修改持久结构体变量类型

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",
"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",

View File

@ -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" }

View File

@ -1,3 +1,3 @@
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::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<chrono::Utc>,
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, sqlx::Error> {
feedback.created_at = DateTime::default().to_utc();
feedback.created_at = Utc::now().naive_utc();
sqlx::query_as!(
Feedback,
r#"insert into feedback

View File

@ -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<u64>,
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<chrono::Utc>,
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<PlayerInfo, sqlx::Error> {
player_info.created_at = DateTime::default().to_utc();
player_info.created_at = Utc::now().naive_utc();
sqlx::query_as!(
PlayerInfo,
r#"

View File

@ -4,11 +4,11 @@ use serde::Serialize;
#[derive(Debug, Serialize)]
pub struct Pageable<T> where T: Debug + Serialize {
pub data: Vec<T>,
pub total: u64,
pub total: i64,
}
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 {
data,
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();
if count.is_none() {
tracing::error!("反馈信息为空");
return 0;
}
count.unwrap().count
count.unwrap().count.unwrap()
}
/// 添加反馈信息