Skip to content

Commit

Permalink
chore: regulate English words
Browse files Browse the repository at this point in the history
  • Loading branch information
ElaBosak233 committed Nov 3, 2024
1 parent ca5f3f4 commit 4f956d4
Show file tree
Hide file tree
Showing 16 changed files with 100 additions and 100 deletions.
20 changes: 10 additions & 10 deletions src/model/challenge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ pub struct Model {
pub struct Ports(pub Vec<i64>);

impl Model {
pub fn simplify(&mut self) {
pub fn desensitize(&mut self) {
self.envs.clear();
self.ports.clear();
self.flags.clear();
Expand Down Expand Up @@ -107,38 +107,38 @@ pub async fn find(
id: Option<i64>, title: Option<String>, category: Option<Category>,
is_practicable: Option<bool>, is_dynamic: Option<bool>, page: Option<u64>, size: Option<u64>,
) -> Result<(Vec<crate::model::challenge::Model>, u64), DbErr> {
let mut query = crate::model::challenge::Entity::find();
let mut sql = crate::model::challenge::Entity::find();

if let Some(id) = id {
query = query.filter(crate::model::challenge::Column::Id.eq(id));
sql = sql.filter(crate::model::challenge::Column::Id.eq(id));
}

if let Some(title) = title {
query = query.filter(crate::model::challenge::Column::Title.contains(title));
sql = sql.filter(crate::model::challenge::Column::Title.contains(title));
}

if let Some(category) = category {
query = query.filter(crate::model::challenge::Column::Category.eq(category));
sql = sql.filter(crate::model::challenge::Column::Category.eq(category));
}

if let Some(is_practicable) = is_practicable {
query = query.filter(crate::model::challenge::Column::IsPracticable.eq(is_practicable));
sql = sql.filter(crate::model::challenge::Column::IsPracticable.eq(is_practicable));
}

if let Some(is_dynamic) = is_dynamic {
query = query.filter(crate::model::challenge::Column::IsDynamic.eq(is_dynamic));
sql = sql.filter(crate::model::challenge::Column::IsDynamic.eq(is_dynamic));
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

if let Some(page) = page {
if let Some(size) = size {
let offset = (page - 1) * size;
query = query.offset(offset).limit(size);
sql = sql.offset(offset).limit(size);
}
}

let challenges = query.all(&get_db()).await?;
let challenges = sql.all(&get_db()).await?;

return Ok((challenges, total));
}
Expand Down
16 changes: 8 additions & 8 deletions src/model/game/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub struct Model {
#[sea_orm(primary_key)]
pub id: i64,
pub title: String,
pub bio: Option<String>,
pub sketch: Option<String>,
pub description: Option<String>,
pub is_enabled: bool,
pub is_public: bool,
Expand Down Expand Up @@ -87,30 +87,30 @@ pub async fn find(
id: Option<i64>, title: Option<String>, is_enabled: Option<bool>, page: Option<u64>,
size: Option<u64>,
) -> Result<(Vec<crate::model::game::Model>, u64), DbErr> {
let mut query = crate::model::game::Entity::find();
let mut sql = crate::model::game::Entity::find();

if let Some(id) = id {
query = query.filter(crate::model::game::Column::Id.eq(id));
sql = sql.filter(crate::model::game::Column::Id.eq(id));
}

if let Some(title) = title {
query = query.filter(crate::model::game::Column::Title.contains(title));
sql = sql.filter(crate::model::game::Column::Title.contains(title));
}

if let Some(is_enabled) = is_enabled {
query = query.filter(crate::model::game::Column::IsEnabled.eq(is_enabled));
sql = sql.filter(crate::model::game::Column::IsEnabled.eq(is_enabled));
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

if let Some(page) = page {
if let Some(size) = size {
let offset = (page - 1) * size;
query = query.offset(offset).limit(size);
sql = sql.offset(offset).limit(size);
}
}

let games = query.all(&get_db()).await?;
let games = sql.all(&get_db()).await?;

return Ok((games, total));
}
12 changes: 6 additions & 6 deletions src/model/game_challenge/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,23 +89,23 @@ async fn preload(
pub async fn find(
game_id: Option<i64>, challenge_id: Option<i64>, is_enabled: Option<bool>,
) -> Result<(Vec<crate::model::game_challenge::Model>, u64), DbErr> {
let mut query = crate::model::game_challenge::Entity::find();
let mut sql = crate::model::game_challenge::Entity::find();

if let Some(game_id) = game_id {
query = query.filter(crate::model::game_challenge::Column::GameId.eq(game_id));
sql = sql.filter(crate::model::game_challenge::Column::GameId.eq(game_id));
}

if let Some(challenge_id) = challenge_id {
query = query.filter(crate::model::game_challenge::Column::ChallengeId.eq(challenge_id));
sql = sql.filter(crate::model::game_challenge::Column::ChallengeId.eq(challenge_id));
}

if let Some(is_enabled) = is_enabled {
query = query.filter(crate::model::game_challenge::Column::IsEnabled.eq(is_enabled));
sql = sql.filter(crate::model::game_challenge::Column::IsEnabled.eq(is_enabled));
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

let mut game_challenges = query.all(&get_db()).await?;
let mut game_challenges = sql.all(&get_db()).await?;

game_challenges = preload(game_challenges).await?;

Expand Down
10 changes: 5 additions & 5 deletions src/model/game_team/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,19 +85,19 @@ async fn preload(
pub async fn find(
game_id: Option<i64>, team_id: Option<i64>,
) -> Result<(Vec<crate::model::game_team::Model>, u64), DbErr> {
let mut query = crate::model::game_team::Entity::find();
let mut sql = crate::model::game_team::Entity::find();

if let Some(game_id) = game_id {
query = query.filter(crate::model::game_team::Column::GameId.eq(game_id));
sql = sql.filter(crate::model::game_team::Column::GameId.eq(game_id));
}

if let Some(team_id) = team_id {
query = query.filter(crate::model::game_team::Column::TeamId.eq(team_id));
sql = sql.filter(crate::model::game_team::Column::TeamId.eq(team_id));
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

let mut game_teams = query.all(&get_db()).await?;
let mut game_teams = sql.all(&get_db()).await?;

game_teams = preload(game_teams).await?;

Expand Down
26 changes: 13 additions & 13 deletions src/model/pod/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ pub struct Model {
}

impl Model {
pub fn simplify(&mut self) {
pub fn desensitize(&mut self) {
self.flag = None;
for nat in self.nats.iter_mut() {
nat.simplify();
nat.desensitize();
}
}
}
Expand Down Expand Up @@ -128,49 +128,49 @@ pub async fn find(
id: Option<i64>, name: Option<String>, user_id: Option<i64>, team_id: Option<i64>,
game_id: Option<i64>, challenge_id: Option<i64>, is_available: Option<bool>,
) -> Result<(Vec<crate::model::pod::Model>, u64), DbErr> {
let mut query = crate::model::pod::Entity::find();
let mut sql = crate::model::pod::Entity::find();
if let Some(id) = id {
query = query.filter(crate::model::pod::Column::Id.eq(id));
sql = sql.filter(crate::model::pod::Column::Id.eq(id));
}

if let Some(name) = name {
query = query.filter(crate::model::pod::Column::Name.eq(name));
sql = sql.filter(crate::model::pod::Column::Name.eq(name));
}

if let Some(user_id) = user_id {
query = query.filter(crate::model::pod::Column::UserId.eq(user_id));
sql = sql.filter(crate::model::pod::Column::UserId.eq(user_id));
}

if let Some(team_id) = team_id {
query = query.filter(crate::model::pod::Column::TeamId.eq(team_id));
sql = sql.filter(crate::model::pod::Column::TeamId.eq(team_id));
}

if let Some(game_id) = game_id {
query = query.filter(crate::model::pod::Column::GameId.eq(game_id));
sql = sql.filter(crate::model::pod::Column::GameId.eq(game_id));
}

if let Some(challenge_id) = challenge_id {
query = query.filter(crate::model::pod::Column::ChallengeId.eq(challenge_id));
sql = sql.filter(crate::model::pod::Column::ChallengeId.eq(challenge_id));
}

if let Some(is_available) = is_available {
match is_available {
true => {
query = query.filter(
sql = sql.filter(
crate::model::pod::Column::RemovedAt.gte(chrono::Utc::now().timestamp()),
)
}
false => {
query = query.filter(
sql = sql.filter(
crate::model::pod::Column::RemovedAt.lte(chrono::Utc::now().timestamp()),
)
}
}
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

let mut pods = query.all(&get_db()).await?;
let mut pods = sql.all(&get_db()).await?;

pods = preload(pods).await?;

Expand Down
2 changes: 1 addition & 1 deletion src/model/pod/nat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Nat {
}

impl Nat {
pub fn simplify(&mut self) {
pub fn desensitize(&mut self) {
if self.proxy {
self.dst = None;
self.entry = None;
Expand Down
28 changes: 14 additions & 14 deletions src/model/submission/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ pub struct Model {
}

impl Model {
pub fn simplify(&mut self) {
pub fn desensitize(&mut self) {
self.flag.clear();
}
}
Expand Down Expand Up @@ -141,15 +141,15 @@ async fn preload(
for (i, submission) in submissions.iter_mut().enumerate() {
submission.user = users[i].clone();
if let Some(user) = submission.user.as_mut() {
user.simplify();
user.desensitize();
}
submission.challenge = challenges[i].clone();
if let Some(challenge) = submission.challenge.as_mut() {
challenge.simplify();
challenge.desensitize();
}
submission.team = teams[i].clone();
if let Some(team) = submission.team.as_mut() {
team.simplify();
team.desensitize();
}
submission.game = games[i].clone();
}
Expand All @@ -160,42 +160,42 @@ pub async fn find(
id: Option<i64>, user_id: Option<i64>, team_id: Option<i64>, game_id: Option<i64>,
challenge_id: Option<i64>, status: Option<Status>, page: Option<u64>, size: Option<u64>,
) -> Result<(Vec<crate::model::submission::Model>, u64), DbErr> {
let mut query = crate::model::submission::Entity::find();
let mut sql = crate::model::submission::Entity::find();

if let Some(id) = id {
query = query.filter(crate::model::submission::Column::Id.eq(id));
sql = sql.filter(crate::model::submission::Column::Id.eq(id));
}

if let Some(user_id) = user_id {
query = query.filter(crate::model::submission::Column::UserId.eq(user_id));
sql = sql.filter(crate::model::submission::Column::UserId.eq(user_id));
}

if let Some(team_id) = team_id {
query = query.filter(crate::model::submission::Column::TeamId.eq(team_id));
sql = sql.filter(crate::model::submission::Column::TeamId.eq(team_id));
}

if let Some(game_id) = game_id {
query = query.filter(crate::model::submission::Column::GameId.eq(game_id));
sql = sql.filter(crate::model::submission::Column::GameId.eq(game_id));
}

if let Some(challenge_id) = challenge_id {
query = query.filter(crate::model::submission::Column::ChallengeId.eq(challenge_id));
sql = sql.filter(crate::model::submission::Column::ChallengeId.eq(challenge_id));
}

if let Some(status) = status {
query = query.filter(crate::model::submission::Column::Status.eq(status));
sql = sql.filter(crate::model::submission::Column::Status.eq(status));
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

if let Some(page) = page {
if let Some(size) = size {
let offset = (page - 1) * size;
query = query.offset(offset).limit(size);
sql = sql.offset(offset).limit(size);
}
}

let mut submissions = query.all(&get_db()).await?;
let mut submissions = sql.all(&get_db()).await?;

submissions = preload(submissions).await?;

Expand Down
24 changes: 12 additions & 12 deletions src/model/team/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pub struct Model {
pub name: String,
pub email: Option<String>,
pub captain_id: i64,
pub description: Option<String>,
pub slogan: Option<String>,
pub invite_token: Option<String>,
pub created_at: i64,
pub updated_at: i64,
Expand All @@ -25,13 +25,13 @@ pub struct Model {
}

impl Model {
pub fn simplify(&mut self) {
pub fn desensitize(&mut self) {
self.invite_token = None;
if let Some(captain) = self.captain.as_mut() {
captain.simplify();
captain.desensitize();
}
for user in self.users.iter_mut() {
user.simplify();
user.desensitize();
}
}
}
Expand Down Expand Up @@ -103,7 +103,7 @@ async fn preload(
for (i, team) in teams.iter_mut().enumerate() {
team.users = users[i].clone();
for user in team.users.iter_mut() {
user.simplify();
user.desensitize();
if user.id == team.captain_id {
team.captain = Some(user.clone());
}
Expand All @@ -117,30 +117,30 @@ pub async fn find(
id: Option<i64>, name: Option<String>, email: Option<String>, page: Option<u64>,
size: Option<u64>,
) -> Result<(Vec<crate::model::team::Model>, u64), DbErr> {
let mut query = crate::model::team::Entity::find();
let mut sql = crate::model::team::Entity::find();

if let Some(id) = id {
query = query.filter(crate::model::team::Column::Id.eq(id));
sql = sql.filter(crate::model::team::Column::Id.eq(id));
}

if let Some(name) = name {
query = query.filter(crate::model::team::Column::Name.contains(name));
sql = sql.filter(crate::model::team::Column::Name.contains(name));
}

if let Some(email) = email {
query = query.filter(crate::model::team::Column::Email.eq(email));
sql = sql.filter(crate::model::team::Column::Email.eq(email));
}

let total = query.clone().count(&get_db()).await?;
let total = sql.clone().count(&get_db()).await?;

if let Some(page) = page {
if let Some(size) = size {
let offset = (page - 1) * size;
query = query.offset(offset).limit(size);
sql = sql.offset(offset).limit(size);
}
}

let mut teams = query.all(&get_db()).await?;
let mut teams = sql.all(&get_db()).await?;

teams = preload(teams).await?;

Expand Down
Loading

0 comments on commit 4f956d4

Please sign in to comment.