Skip to content

Commit

Permalink
Add creation_timestamp to challenge categories
Browse files Browse the repository at this point in the history
  • Loading branch information
Defelo committed Oct 14, 2023
1 parent f1dcf4e commit 940ed06
Show file tree
Hide file tree
Showing 25 changed files with 67 additions and 22 deletions.
4 changes: 3 additions & 1 deletion challenges/src/endpoints/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Challenges {
_auth: VerifiedUserAuth,
) -> ListCategories::Response<VerifiedUserAuth> {
let mut query = challenges_challenge_categories::Entity::find()
.order_by_asc(challenges_challenge_categories::Column::Title);
.order_by_asc(challenges_challenge_categories::Column::CreationTimestamp);
if let Some(title) = title.0 {
query = query.filter(challenges_challenge_categories::Column::Title.contains(title));
}
Expand Down Expand Up @@ -125,6 +125,7 @@ impl Challenges {
id: Set(Uuid::new_v4()),
title: Set(data.0.title),
description: Set(data.0.description),
creation_timestamp: Set(Utc::now().naive_utc()),
}
.insert(&***db)
.await?
Expand All @@ -147,6 +148,7 @@ impl Challenges {
id: Unchanged(category.id),
title: data.0.title.update(category.title),
description: data.0.description.update(category.description),
creation_timestamp: Unchanged(category.creation_timestamp),
}
.update(&***db)
.await?
Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_ban.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
3 changes: 2 additions & 1 deletion entity/src/challenges_challenge_categories.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand All @@ -11,6 +11,7 @@ pub struct Model {
pub title: String,
#[sea_orm(column_type = "Text")]
pub description: String,
pub creation_timestamp: DateTime,
}

#[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)]
Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_challenges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_coding_challenge_result.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_coding_challenge_submissions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_coding_challenges.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_course_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_matching_attempts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_matchings.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_multiple_choice_attempts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_multiple_choice_quizes.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_question_attempts.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_questions.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_subtask_reports.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_subtasks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_tasks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/challenges_user_subtasks.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
pub mod prelude;

Expand Down
2 changes: 1 addition & 1 deletion entity/src/prelude.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
pub use super::{
challenges_ban::Entity as ChallengesBan,
Expand Down
2 changes: 1 addition & 1 deletion entity/src/sea_orm_active_enums.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.11.3
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.2
use sea_orm::entity::prelude::*;

Expand Down
2 changes: 2 additions & 0 deletions migration/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ mod m20230719_174846_user_subtasks_last_attempt;
mod m20230815_162457_remove_subtask_fee;
mod m20230815_203544_remove_subtask_unlocked;
mod m20230816_173651_retire_subtasks;
mod m20231014_142202_category_creation_timestamp;

#[async_trait::async_trait]
impl MigratorTrait for Migrator {
Expand Down Expand Up @@ -68,6 +69,7 @@ impl MigratorTrait for Migrator {
Box::new(m20230815_162457_remove_subtask_fee::Migration),
Box::new(m20230815_203544_remove_subtask_unlocked::Migration),
Box::new(m20230816_173651_retire_subtasks::Migration),
Box::new(m20231014_142202_category_creation_timestamp::Migration),
]
}
}
3 changes: 2 additions & 1 deletion migration/src/m20230322_163425_challenges_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,12 +238,13 @@ impl MigrationTrait for Migration {
}

#[derive(Iden)]
enum ChallengeCategory {
pub enum ChallengeCategory {
#[iden = "challenges_challenge_categories"]
Table,
Id,
Title,
Description,
CreationTimestamp,
}

#[derive(Iden)]
Expand Down
36 changes: 36 additions & 0 deletions migration/src/m20231014_142202_category_creation_timestamp.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
use sea_orm_migration::prelude::*;

use crate::m20230322_163425_challenges_init::ChallengeCategory;

#[derive(DeriveMigrationName)]
pub struct Migration;

#[async_trait::async_trait]
impl MigrationTrait for Migration {
async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(ChallengeCategory::Table)
.add_column(
ColumnDef::new(ChallengeCategory::CreationTimestamp)
.timestamp()
.not_null()
.default(Expr::current_timestamp()),
)
.to_owned(),
)
.await
}

async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> {
manager
.alter_table(
Table::alter()
.table(ChallengeCategory::Table)
.drop_column(ChallengeCategory::CreationTimestamp)
.to_owned(),
)
.await
}
}
3 changes: 3 additions & 0 deletions schemas/src/challenges/challenges.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ pub struct Category {
pub title: String,
/// The description of the category
pub description: String,
/// The creation timestamp of the category
pub creation_timestamp: DateTime<Utc>,
}

#[derive(Debug, Clone, Deserialize)]
Expand Down Expand Up @@ -132,6 +134,7 @@ impl From<challenges_challenge_categories::Model> for Category {
id: value.id,
title: value.title,
description: value.description,
creation_timestamp: value.creation_timestamp.and_utc(),
}
}
}
Expand Down

0 comments on commit 940ed06

Please sign in to comment.