修改持久结构体变量类型

This commit is contained in:
liyunjia 2024-05-22 06:21:24 +08:00
parent 96d0bf1bec
commit 5afea94458
7 changed files with 15 additions and 10 deletions

2
Cargo.lock generated
View File

@ -292,6 +292,7 @@ dependencies = [
"iana-time-zone", "iana-time-zone",
"js-sys", "js-sys",
"num-traits", "num-traits",
"serde",
"wasm-bindgen", "wasm-bindgen",
"windows-targets 0.52.4", "windows-targets 0.52.4",
] ]
@ -474,6 +475,7 @@ dependencies = [
name = "domain" name = "domain"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"chrono",
"library", "library",
"serde", "serde",
"sqlx", "sqlx",

View File

@ -9,5 +9,6 @@ edition = "2021"
serde = { workspace = true, features = ["derive"] } serde = { workspace = true, features = ["derive"] }
sqlx = { workspace = true, features = ["postgres", "uuid", "macros", "sqlx-macros", "chrono"] } sqlx = { workspace = true, features = ["postgres", "uuid", "macros", "sqlx-macros", "chrono"] }
validator = { workspace = true, features = ["derive"] } validator = { workspace = true, features = ["derive"] }
chrono = { workspace = true, features = ["serde"]}
library = { path = "../library" } library = { path = "../library" }

View File

@ -1,3 +1,3 @@
pub struct CountResult { pub struct CountResult {
pub count: u64 pub count: Option<i64>
} }

View File

@ -1,3 +1,4 @@
use chrono::{NaiveDateTime, Utc};
use sqlx::{FromRow, PgPool}; use sqlx::{FromRow, PgPool};
use sqlx::types::chrono::{self, DateTime}; use sqlx::types::chrono::{self, DateTime};
use crate::db_result::CountResult; use crate::db_result::CountResult;
@ -7,7 +8,7 @@ pub struct Feedback {
pub id: u64, pub id: u64,
pub user_id: u64, pub user_id: u64,
pub content: String, pub content: String,
pub created_at: DateTime<chrono::Utc>, pub created_at: NaiveDateTime,
} }
impl Feedback { impl Feedback {
@ -27,7 +28,7 @@ impl Feedback {
} }
pub async fn add_feedback(feedback: &mut Feedback, db_pool: &PgPool) -> Result<Feedback, sqlx::Error> { pub async fn add_feedback(feedback: &mut Feedback, db_pool: &PgPool) -> Result<Feedback, sqlx::Error> {
feedback.created_at = DateTime::default().to_utc(); feedback.created_at = Utc::now().naive_utc();
sqlx::query_as!( sqlx::query_as!(
Feedback, Feedback,
r#"insert into feedback r#"insert into feedback

View File

@ -1,16 +1,17 @@
use chrono::{NaiveDateTime, Utc};
use sqlx::{FromRow, PgPool, QueryBuilder}; use sqlx::{FromRow, PgPool, QueryBuilder};
use sqlx::types::chrono::{self, DateTime}; use sqlx::types::chrono::{self, DateTime};
use library::db; use library::db;
#[derive(Debug, Clone, FromRow, serde::Serialize)] #[derive(Debug, Clone, FromRow, serde::Serialize)]
pub struct PlayerInfo { pub struct PlayerInfo {
pub id: Option<u64>, pub id: u64,
pub username: String, pub username: String,
pub email: String, pub email: String,
pub platform_id: String, pub platform_id: String,
pub user_type: String, pub user_type: String,
pub country_code: String, pub country_code: String,
pub created_at: DateTime<chrono::Utc>, pub created_at: NaiveDateTime,
} }
impl PlayerInfo { impl PlayerInfo {
@ -25,7 +26,7 @@ impl PlayerInfo {
} }
pub async fn add_player_info(player_info: &mut PlayerInfo, db_pool: &PgPool) -> Result<PlayerInfo, sqlx::Error> { pub async fn add_player_info(player_info: &mut PlayerInfo, db_pool: &PgPool) -> Result<PlayerInfo, sqlx::Error> {
player_info.created_at = DateTime::default().to_utc(); player_info.created_at = Utc::now().naive_utc();
sqlx::query_as!( sqlx::query_as!(
PlayerInfo, PlayerInfo,
r#" r#"

View File

@ -4,11 +4,11 @@ use serde::Serialize;
#[derive(Debug, Serialize)] #[derive(Debug, Serialize)]
pub struct Pageable<T> where T: Debug + Serialize { pub struct Pageable<T> where T: Debug + Serialize {
pub data: Vec<T>, pub data: Vec<T>,
pub total: u64, pub total: i64,
} }
impl <T> Pageable<T> where T: Debug + Serialize { impl <T> Pageable<T> where T: Debug + Serialize {
pub fn new(data: Vec<T>, total: u64) -> Self { pub fn new(data: Vec<T>, total: i64) -> Self {
Self { Self {
data, data,
total, total,

View File

@ -19,13 +19,13 @@ pub async fn get_feedback_list_by_page(page: u64, page_size: u64) -> ResResult<R
} }
/// 获取反馈信息总数 /// 获取反馈信息总数
async fn get_feedback_count() -> u64 { async fn get_feedback_count() -> i64 {
let count = Feedback::count_feedback(db!()).await.ok(); let count = Feedback::count_feedback(db!()).await.ok();
if count.is_none() { if count.is_none() {
tracing::error!("反馈信息为空"); tracing::error!("反馈信息为空");
return 0; return 0;
} }
count.unwrap().count count.unwrap().count.unwrap()
} }
/// 添加反馈信息 /// 添加反馈信息