From f302fccef5222bb715567050b55a75ffc30f10d9 Mon Sep 17 00:00:00 2001 From: Xander Bil Date: Thu, 5 Dec 2024 23:47:14 +0100 Subject: [PATCH] Revert "vingo: use time with timezone for seasons start and end" This reverts commit 363c99dbb150ed3cee1a0c5c4141038e752cc0b2. --- vingo/migration/src/lib.rs | 2 - .../src/m20241205_210208_add_timezone.rs | 46 ------------------- vingo/src/entities/card.rs | 2 +- vingo/src/entities/day.rs | 2 +- vingo/src/entities/mod.rs | 2 +- vingo/src/entities/prelude.rs | 2 +- vingo/src/entities/scan.rs | 2 +- vingo/src/entities/season.rs | 6 +-- vingo/src/entities/user.rs | 2 +- vingo/src/routes/seasons.rs | 11 +++-- 10 files changed, 15 insertions(+), 62 deletions(-) delete mode 100644 vingo/migration/src/m20241205_210208_add_timezone.rs diff --git a/vingo/migration/src/lib.rs b/vingo/migration/src/lib.rs index dd97022..39f57c2 100644 --- a/vingo/migration/src/lib.rs +++ b/vingo/migration/src/lib.rs @@ -5,7 +5,6 @@ mod m20240829_234032_create_card; mod m20240903_194156_create_scan; mod m20240909_195645_create_days; mod m20240909_214352_create_seasons; -mod m20241205_210208_add_timezone; pub struct Migrator; @@ -18,7 +17,6 @@ impl MigratorTrait for Migrator { Box::new(m20240903_194156_create_scan::Migration), Box::new(m20240909_195645_create_days::Migration), Box::new(m20240909_214352_create_seasons::Migration), - Box::new(m20241205_210208_add_timezone::Migration), ] } } diff --git a/vingo/migration/src/m20241205_210208_add_timezone.rs b/vingo/migration/src/m20241205_210208_add_timezone.rs deleted file mode 100644 index 0dc43bf..0000000 --- a/vingo/migration/src/m20241205_210208_add_timezone.rs +++ /dev/null @@ -1,46 +0,0 @@ -use sea_orm_migration::prelude::*; - -#[derive(DeriveMigrationName)] -pub struct Migration; - -#[derive(DeriveIden)] -enum Season { - Table, - Start, - End, -} - -#[async_trait::async_trait] -impl MigrationTrait for Migration { - async fn up(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .alter_table( - Table::alter() - .table(Season::Table) - .modify_column( - ColumnDef::new(Season::Start) - .timestamp_with_time_zone() - .default(Expr::current_timestamp()), - ) - .modify_column( - ColumnDef::new(Season::End) - .timestamp_with_time_zone() - .default(Expr::current_timestamp()), - ) - .to_owned(), - ) - .await - } - - async fn down(&self, manager: &SchemaManager) -> Result<(), DbErr> { - manager - .alter_table( - Table::alter() - .table(Season::Table) - .modify_column(ColumnDef::new(Season::Start).date()) - .modify_column(ColumnDef::new(Season::End).date()) - .to_owned(), - ) - .await - } -} diff --git a/vingo/src/entities/card.rs b/vingo/src/entities/card.rs index 9b41112..a0438d7 100644 --- a/vingo/src/entities/card.rs +++ b/vingo/src/entities/card.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; diff --git a/vingo/src/entities/day.rs b/vingo/src/entities/day.rs index 03fabd3..0149d1c 100644 --- a/vingo/src/entities/day.rs +++ b/vingo/src/entities/day.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; diff --git a/vingo/src/entities/mod.rs b/vingo/src/entities/mod.rs index 2a7fd27..9c0b40e 100644 --- a/vingo/src/entities/mod.rs +++ b/vingo/src/entities/mod.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 pub mod prelude; diff --git a/vingo/src/entities/prelude.rs b/vingo/src/entities/prelude.rs index 1255c11..813c510 100644 --- a/vingo/src/entities/prelude.rs +++ b/vingo/src/entities/prelude.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 pub use super::card::Entity as Card; pub use super::day::Entity as Day; diff --git a/vingo/src/entities/scan.rs b/vingo/src/entities/scan.rs index 1b12c7e..121addb 100644 --- a/vingo/src/entities/scan.rs +++ b/vingo/src/entities/scan.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; diff --git a/vingo/src/entities/season.rs b/vingo/src/entities/season.rs index 217afec..0ee1ba1 100644 --- a/vingo/src/entities/season.rs +++ b/vingo/src/entities/season.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; @@ -10,8 +10,8 @@ pub struct Model { pub id: i32, #[sea_orm(column_type = "Text")] pub name: String, - pub start: DateTimeWithTimeZone, - pub end: DateTimeWithTimeZone, + pub start: Date, + pub end: Date, } #[derive(Copy, Clone, Debug, EnumIter, DeriveRelation)] diff --git a/vingo/src/entities/user.rs b/vingo/src/entities/user.rs index a4dead9..8a2bae9 100644 --- a/vingo/src/entities/user.rs +++ b/vingo/src/entities/user.rs @@ -1,4 +1,4 @@ -//! `SeaORM` Entity, @generated by sea-orm-codegen 1.1.0 +//! `SeaORM` Entity, @generated by sea-orm-codegen 1.0.1 use sea_orm::entity::prelude::*; use serde::{Deserialize, Serialize}; diff --git a/vingo/src/routes/seasons.rs b/vingo/src/routes/seasons.rs index e1f5b4f..5aa88fc 100644 --- a/vingo/src/routes/seasons.rs +++ b/vingo/src/routes/seasons.rs @@ -2,9 +2,10 @@ use axum::{ extract::{Path, State}, Json, }; +use chrono::NaiveDate; use reqwest::StatusCode; -use sea_orm::{prelude::DateTimeWithTimeZone, sea_query::Expr, DatabaseConnection}; +use sea_orm::{sea_query::Expr, DatabaseConnection}; use sea_orm::{ ActiveModelTrait, EntityTrait, FromQueryResult, QueryFilter, QuerySelect, QueryTrait, Set, }; @@ -21,8 +22,8 @@ use super::util::errors::{ResponseResult, ResultAndLogError}; pub struct SeasonGet { id: i32, name: String, - start: DateTimeWithTimeZone, - end: DateTimeWithTimeZone, + start: NaiveDate, + end: NaiveDate, is_current: bool, } @@ -55,8 +56,8 @@ pub async fn db_seasons(db: &DatabaseConnection, future: bool) -> ResponseResult #[derive(Debug, Serialize, Deserialize)] pub struct SeasonAddBody { name: String, - start: DateTimeWithTimeZone, - end: DateTimeWithTimeZone, + start: NaiveDate, + end: NaiveDate, } pub async fn add( state: State,