diff --git a/Cargo.lock b/Cargo.lock index afa8c00..e28e807 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -292,6 +292,7 @@ dependencies = [ "iana-time-zone", "js-sys", "num-traits", + "serde", "wasm-bindgen", "windows-targets 0.52.4", ] @@ -474,6 +475,7 @@ dependencies = [ name = "domain" version = "0.1.0" dependencies = [ + "chrono", "library", "serde", "sqlx", diff --git a/domain/Cargo.toml b/domain/Cargo.toml index 2472994..c241f98 100644 --- a/domain/Cargo.toml +++ b/domain/Cargo.toml @@ -9,5 +9,6 @@ edition = "2021" serde = { workspace = true, features = ["derive"] } sqlx = { workspace = true, features = ["postgres", "uuid", "macros", "sqlx-macros", "chrono"] } validator = { workspace = true, features = ["derive"] } +chrono = { workspace = true, features = ["serde"]} library = { path = "../library" } \ No newline at end of file diff --git a/domain/src/db_result.rs b/domain/src/db_result.rs index 6cc35fc..f622676 100644 --- a/domain/src/db_result.rs +++ b/domain/src/db_result.rs @@ -1,3 +1,3 @@ pub struct CountResult { - pub count: u64 + pub count: Option } \ No newline at end of file diff --git a/domain/src/entities/feedback.rs b/domain/src/entities/feedback.rs index b189ba8..d3d4269 100644 --- a/domain/src/entities/feedback.rs +++ b/domain/src/entities/feedback.rs @@ -1,3 +1,4 @@ +use chrono::{NaiveDateTime, Utc}; use sqlx::{FromRow, PgPool}; use sqlx::types::chrono::{self, DateTime}; use crate::db_result::CountResult; @@ -7,7 +8,7 @@ pub struct Feedback { pub id: u64, pub user_id: u64, pub content: String, - pub created_at: DateTime, + pub created_at: NaiveDateTime, } impl Feedback { @@ -27,7 +28,7 @@ impl Feedback { } pub async fn add_feedback(feedback: &mut Feedback, db_pool: &PgPool) -> Result { - feedback.created_at = DateTime::default().to_utc(); + feedback.created_at = Utc::now().naive_utc(); sqlx::query_as!( Feedback, r#"insert into feedback diff --git a/domain/src/entities/player_info.rs b/domain/src/entities/player_info.rs index 5f0bdcb..bff39f7 100644 --- a/domain/src/entities/player_info.rs +++ b/domain/src/entities/player_info.rs @@ -1,16 +1,17 @@ +use chrono::{NaiveDateTime, Utc}; use sqlx::{FromRow, PgPool, QueryBuilder}; use sqlx::types::chrono::{self, DateTime}; use library::db; #[derive(Debug, Clone, FromRow, serde::Serialize)] pub struct PlayerInfo { - pub id: Option, + pub id: u64, pub username: String, pub email: String, pub platform_id: String, pub user_type: String, pub country_code: String, - pub created_at: DateTime, + pub created_at: NaiveDateTime, } impl PlayerInfo { @@ -25,7 +26,7 @@ impl PlayerInfo { } pub async fn add_player_info(player_info: &mut PlayerInfo, db_pool: &PgPool) -> Result { - player_info.created_at = DateTime::default().to_utc(); + player_info.created_at = Utc::now().naive_utc(); sqlx::query_as!( PlayerInfo, r#" diff --git a/library/src/resp/pageable.rs b/library/src/resp/pageable.rs index 46ede8e..23c3b06 100644 --- a/library/src/resp/pageable.rs +++ b/library/src/resp/pageable.rs @@ -4,11 +4,11 @@ use serde::Serialize; #[derive(Debug, Serialize)] pub struct Pageable where T: Debug + Serialize { pub data: Vec, - pub total: u64, + pub total: i64, } impl Pageable where T: Debug + Serialize { - pub fn new(data: Vec, total: u64) -> Self { + pub fn new(data: Vec, total: i64) -> Self { Self { data, total, diff --git a/service/src/feedback.rs b/service/src/feedback.rs index 2b755a0..6bef325 100644 --- a/service/src/feedback.rs +++ b/service/src/feedback.rs @@ -19,13 +19,13 @@ pub async fn get_feedback_list_by_page(page: u64, page_size: u64) -> ResResult u64 { +async fn get_feedback_count() -> i64 { let count = Feedback::count_feedback(db!()).await.ok(); if count.is_none() { tracing::error!("反馈信息为空"); return 0; } - count.unwrap().count + count.unwrap().count.unwrap() } /// 添加反馈信息