Skip to content

Commit

Permalink
replace mpdefault module with mptypes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahmadbky committed Aug 11, 2024
1 parent fb89df9 commit dc57596
Show file tree
Hide file tree
Showing 6 changed files with 199 additions and 132 deletions.
14 changes: 7 additions & 7 deletions game_api/src/graphql/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,10 @@ impl QueryRoot {
"select * from article
where hide is null or hide = 0
order by article_date desc
limit 1"
limit 1",
)
.fetch_optional(db)
.await?;
.fetch_optional(db)
.await?;
Ok(article.map(From::<models::Article>::from))
}

Expand All @@ -128,11 +128,11 @@ impl QueryRoot {
let db = ctx.data_unchecked::<MySqlPool>();
let article = sqlx::query_as(
"select * from article
where (hide is null or hide = 0) and slug = ?"
where (hide is null or hide = 0) and slug = ?",
)
.bind(slug)
.fetch_optional(db)
.await?;
.bind(slug)
.fetch_optional(db)
.await?;
Ok(article.map(From::<models::Article>::from))
}

Expand Down
54 changes: 22 additions & 32 deletions game_api/src/http/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use itertools::Itertools;
use records_lib::{
error::RecordsError,
event::{self, EventMap, OptEvent},
models, opt_ser, Database, MpDefaultI32,
models, Database, NullableInteger, NullableText,
};
use serde::Serialize;
use sqlx::{FromRow, MySqlConnection};
Expand Down Expand Up @@ -86,21 +86,15 @@ struct EventHandleResponse {

#[derive(Serialize)]
struct Map {
#[serde(serialize_with = "opt_ser")]
mx_id: Option<MpDefaultI32<0>>,
mx_id: NullableInteger<0>,
main_author: PlayerInfoNetBody,
name: String,
map_uid: String,
#[serde(serialize_with = "opt_ser")]
bronze_time: Option<MpDefaultI32>,
#[serde(serialize_with = "opt_ser")]
silver_time: Option<MpDefaultI32>,
#[serde(serialize_with = "opt_ser")]
gold_time: Option<MpDefaultI32>,
#[serde(serialize_with = "opt_ser")]
champion_time: Option<MpDefaultI32>,
#[serde(serialize_with = "opt_ser")]
personal_best: Option<MpDefaultI32>,
bronze_time: NullableInteger,
silver_time: NullableInteger,
gold_time: NullableInteger,
champion_time: NullableInteger,
personal_best: NullableInteger,
next_opponent: NextOpponent,
}

Expand Down Expand Up @@ -140,15 +134,13 @@ struct EventHandleEditionResponse {
/// The UTC timestamp of the edition end date.
///
/// It is `None` if the edition never ends.
#[serde(serialize_with = "opt_ser")]
end_date: Option<MpDefaultI32>,
end_date: NullableInteger,
/// The URL to the banner image of the edition, used in the Titlepack menu.
banner_img_url: String,
/// The URL to the small banner image of the edition, used in game in the Campaign mode.
banner2_img_url: String,
/// The MX ID of the related mappack.
#[serde(serialize_with = "opt_ser")]
mx_id: Option<MpDefaultI32>,
mx_id: NullableInteger,
/// Whether the edition has expired or not.
expired: bool,
original_map_uids: Vec<String>,
Expand Down Expand Up @@ -209,19 +201,16 @@ async fn event_editions(

#[derive(FromRow, Serialize, Default)]
struct NextOpponent {
#[serde(serialize_with = "opt_ser")]
login: Option<String>,
#[serde(serialize_with = "opt_ser")]
name: Option<String>,
#[serde(serialize_with = "opt_ser")]
time: Option<MpDefaultI32>,
login: NullableText,
name: NullableText,
time: NullableInteger,
}

struct AuthorWithPlayerTime {
/// The author of the map
main_author: PlayerInfoNetBody,
/// The time of the player (not the same player as the author)
personal_best: Option<MpDefaultI32>,
personal_best: NullableInteger,
/// The next opponent of the player
next_opponent: Option<NextOpponent>,
}
Expand Down Expand Up @@ -339,7 +328,7 @@ async fn edition(
.await
.with_api_err()
.fit(req_id)?,
personal_best: None,
personal_best: None.into(),
next_opponent: None,
}
};
Expand All @@ -351,14 +340,14 @@ async fn edition(
.fit(req_id)?;

maps.push(Map {
mx_id: mx_id.map(|id| MpDefaultI32(id as _)),
mx_id: mx_id.map(|id| id as _).into(),
main_author,
name: map.name,
map_uid: map.game_id,
bronze_time: medal_times.map(|m| m.bronze_time.into()),
silver_time: medal_times.map(|m| m.silver_time.into()),
gold_time: medal_times.map(|m| m.gold_time.into()),
champion_time: medal_times.map(|m| m.champion_time.into()),
bronze_time: medal_times.map(|m| m.bronze_time).into(),
silver_time: medal_times.map(|m| m.silver_time).into(),
gold_time: medal_times.map(|m| m.gold_time).into(),
champion_time: medal_times.map(|m| m.champion_time).into(),
personal_best,
next_opponent: next_opponent.unwrap_or_default(),
});
Expand Down Expand Up @@ -398,7 +387,8 @@ async fn edition(
expired: edition.has_expired(),
end_date: edition
.expire_date()
.map(|d| d.and_utc().timestamp().into()),
.map(|d| d.and_utc().timestamp() as _)
.into(),
id: edition.id,
name: edition.name,
subtitle: edition.subtitle.unwrap_or_default(),
Expand All @@ -411,7 +401,7 @@ async fn edition(
start_date: edition.start_date.and_utc().timestamp() as _,
banner_img_url: edition.banner_img_url.unwrap_or_default(),
banner2_img_url: edition.banner2_img_url.unwrap_or_default(),
mx_id: edition.mx_id.map(|id| MpDefaultI32(id as _)),
mx_id: edition.mx_id.map(|id| id as _).into(),
original_map_uids,
categories,
})
Expand Down
9 changes: 4 additions & 5 deletions game_api/src/http/player_finished.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ use deadpool_redis::redis::AsyncCommands;
use futures::TryStreamExt;
use records_lib::{
event::OptEvent,
models, opt_ser,
models,
redis_key::map_key,
update_ranks::{get_rank, get_rank_opt, update_leaderboard},
DatabaseConnection, MpDefaultI32,
DatabaseConnection, NullableInteger,
};
use serde::{Deserialize, Serialize};
use sqlx::Connection;
Expand Down Expand Up @@ -54,8 +54,7 @@ pub struct HasFinishedResponse {
old: i32,
new: i32,
current_rank: i32,
#[serde(serialize_with = "opt_ser")]
old_rank: Option<MpDefaultI32>,
old_rank: NullableInteger,
}

async fn send_query(
Expand Down Expand Up @@ -245,7 +244,7 @@ pub async fn finished(
old,
new,
current_rank,
old_rank: old_rank.map(From::from),
old_rank: old_rank.map(From::from).into(),
},
})
}
4 changes: 2 additions & 2 deletions records_lib/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use once_cell::sync::OnceCell;
use sqlx::{pool::PoolConnection, MySql, Pool};
use std::time::Duration;

mod mpdefault;
mod mptypes;

pub mod error;
pub mod mappack;
Expand All @@ -33,7 +33,7 @@ pub type RedisPool = deadpool_redis::Pool;
/// The type of a Redis connection.
pub type RedisConnection = deadpool_redis::Connection;

pub use mpdefault::*;
pub use mptypes::*;

use self::error::RecordsResult;

Expand Down
86 changes: 0 additions & 86 deletions records_lib/src/mpdefault.rs

This file was deleted.

Loading

0 comments on commit dc57596

Please sign in to comment.