From 5afea9445856119146fc05b771e9298b14f83e2f Mon Sep 17 00:00:00 2001 From: liyunjia Date: Wed, 22 May 2024 06:21:24 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E6=8C=81=E4=B9=85=E7=BB=93?= =?UTF-8?q?=E6=9E=84=E4=BD=93=E5=8F=98=E9=87=8F=E7=B1=BB=E5=9E=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 ++ domain/Cargo.toml | 1 + domain/src/db_result.rs | 2 +- domain/src/entities/feedback.rs | 5 +++-- domain/src/entities/player_info.rs | 7 ++++--- library/src/resp/pageable.rs | 4 ++-- service/src/feedback.rs | 4 ++-- 7 files changed, 15 insertions(+), 10 deletions(-) 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() } /// 添加反馈信息