From 6fec5a5cb1ec360410de3c2d70a836eb1eaf019b Mon Sep 17 00:00:00 2001 From: Chloe <25387744+qimiko@users.noreply.github.com> Date: Wed, 4 Sep 2024 14:35:18 -0700 Subject: [PATCH] return version dates in api --- src/types/models/mod_entity.rs | 5 +++++ src/types/models/mod_version.rs | 30 +++++++++++++++++++++--------- 2 files changed, 26 insertions(+), 9 deletions(-) diff --git a/src/types/models/mod_entity.rs b/src/types/models/mod_entity.rs index b06889c..4e65079 100644 --- a/src/types/models/mod_entity.rs +++ b/src/types/models/mod_entity.rs @@ -89,6 +89,8 @@ struct ModRecordGetOne { changelog: Option, created_at: DateTime, updated_at: DateTime, + mod_version_created_at: Option>, + mod_version_updated_at: Option>, info: Option, } @@ -579,6 +581,7 @@ impl Mod { r#"SELECT m.id, m.repository, m.about, m.changelog, m.featured, m.download_count as mod_download_count, m.created_at, m.updated_at, mv.id as version_id, mv.name, mv.description, mv.version, mv.download_link, mv.download_count as mod_version_download_count, + mv.created_at as mod_version_created_at, mv.updated_at as mod_version_updated_at, mv.hash, mv.geode, mv.early_load, mv.api, mv.mod_id, mvs.status as "status: _", mvs.info FROM mods m INNER JOIN mod_versions mv ON m.id = mv.mod_id @@ -623,6 +626,8 @@ impl Mod { tags: None, dependencies: None, incompatibilities: None, + created_at: x.mod_version_created_at.map(|x| x.to_rfc3339_opts(SecondsFormat::Secs, true)), + updated_at: x.mod_version_updated_at.map(|x| x.to_rfc3339_opts(SecondsFormat::Secs, true)), direct_download_link: Some(x.download_link.clone()), info: x.info.clone(), }) diff --git a/src/types/models/mod_version.rs b/src/types/models/mod_version.rs index 8a7a7b4..45b97a9 100644 --- a/src/types/models/mod_version.rs +++ b/src/types/models/mod_version.rs @@ -1,9 +1,12 @@ use std::collections::HashMap; -use chrono::Utc; +use chrono::SecondsFormat; use semver::Version; use serde::Serialize; -use sqlx::{PgConnection, Postgres, QueryBuilder, Row}; +use sqlx::{ + types::chrono::{DateTime, Utc}, + PgConnection, Postgres, QueryBuilder, Row +}; use crate::types::{ api::{create_download_link, ApiError, PaginatedData}, @@ -41,6 +44,9 @@ pub struct ModVersion { pub developers: Option>, pub tags: Option>, + pub created_at: Option, + pub updated_at: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] /// Admin/developer only - Reason given to status pub info: Option, @@ -63,6 +69,8 @@ struct ModVersionGetOne { api: bool, mod_id: String, status: ModVersionStatusEnum, + created_at: Option>, + updated_at: Option>, #[sqlx(default)] info: Option, } @@ -108,6 +116,8 @@ impl ModVersionGetOne { incompatibilities: None, info: self.info, direct_download_link: None, + created_at: self.created_at.map(|x| x.to_rfc3339_opts(SecondsFormat::Secs, true)), + updated_at: self.updated_at.map(|x| x.to_rfc3339_opts(SecondsFormat::Secs, true)), } } } @@ -298,10 +308,10 @@ impl ModVersion { let mut builder: QueryBuilder = QueryBuilder::new( r#"SELECT q.name, q.id, q.description, q.version, q.download_link, q.hash, q.geode, q.download_count, - q.early_load, q.api, q.mod_id, q.status FROM ( + q.early_load, q.api, q.mod_id, q.status, q.created_at, q.updated_at FROM ( SELECT mv.name, mv.id, mv.description, mv.version, mv.download_link, mv.hash, mv.geode, mv.download_count, mvs.status, - mv.early_load, mv.api, mv.mod_id, row_number() over (partition by m.id order by mv.id desc) rn FROM mods m + mv.early_load, mv.api, mv.mod_id, mv.created_at, mv.updated_at, row_number() over (partition by m.id order by mv.id desc) rn FROM mods m INNER JOIN mod_versions mv ON m.id = mv.mod_id INNER JOIN mod_version_statuses mvs ON mvs.mod_version_id = mv.id INNER JOIN mod_gd_versions mgv ON mgv.mod_id = mv.id @@ -398,7 +408,7 @@ impl ModVersion { let mut query_builder: QueryBuilder = QueryBuilder::new( r#"SELECT DISTINCT mv.name, mv.id, mv.description, mv.version, mv.download_link, mv.hash, mv.geode, mv.download_count, - mv.early_load, mv.api, mv.mod_id, mvs.status FROM mod_versions mv + mv.early_load, mv.api, mv.mod_id, mv.created_at, mv.updated_at, mvs.status FROM mod_versions mv INNER JOIN mod_version_statuses mvs ON mvs.mod_version_id = mv.id WHERE mvs.status = 'pending' AND mv.mod_id IN ("#, ); @@ -441,11 +451,12 @@ impl ModVersion { let mut query_builder: QueryBuilder = QueryBuilder::new( r#"SELECT q.name, q.id, q.description, q.version, q.download_link, q.hash, q.geode, q.download_count, - q.early_load, q.api, q.mod_id, q.status + q.early_load, q.api, q.mod_id, q.status, + q.created_at, q.updated_at FROM ( SELECT mv.name, mv.id, mv.description, mv.version, mv.download_link, mv.hash, mv.geode, mv.download_count, mvs.status, - mv.early_load, mv.api, mv.mod_id, + mv.early_load, mv.api, mv.mod_id, mv.created_at, mv.updated_at, row_number() over (partition by m.id order by mv.id desc) rn FROM mods m INNER JOIN mod_versions mv ON m.id = mv.mod_id @@ -489,7 +500,7 @@ impl ModVersion { return Err(ApiError::NotFound("".to_string())); } Err(e) => { - log::info!("{:?}", e); + log::error!("{:?}", e); return Err(ApiError::DbError); } }; @@ -626,7 +637,8 @@ impl ModVersion { ModVersionGetOne, r#"SELECT mv.id, mv.name, mv.description, mv.version, mv.download_link, mv.download_count, - mv.hash, mv.geode, mv.early_load, mv.api, + mv.hash, mv.geode, mv.early_load, mv.api, + mv.created_at, mv.updated_at, mv.mod_id, mvs.status as "status: _", mvs.info FROM mod_versions mv INNER JOIN mods m ON m.id = mv.mod_id