diff --git a/domain/src/dto/game_account.rs b/domain/src/dto/game_account.rs index 4f9018a..e8a012c 100644 --- a/domain/src/dto/game_account.rs +++ b/domain/src/dto/game_account.rs @@ -3,14 +3,14 @@ use validator::Validate; #[derive(Debug, Validate, Deserialize, Serialize)] pub struct GameAccountCreate { - #[validate(length(min = 1, message = "用户名称不能为空"))] - pub username: String, - #[validate(length(min = 1, message = "电子邮箱不能为空"))] - pub email: String, - #[validate(length(min = 1, message = "平台ID不能为空"))] - pub platform_id: String, - #[validate(length(min = 1, message = "用户类型不能为空"))] - pub user_type: String, - #[validate(length(min = 1, message = "用户所属区域不能为空"))] - pub country_code: String, + #[validate(required(message = "用户名称不能为空"), length(min = 1, message = "用户名称不能为空"))] + pub username: Option, + #[validate(required, length(min = 1, message = "电子邮箱不能为空"))] + pub email: Option, + #[validate(required, length(min = 1, message = "平台ID不能为空"))] + pub platform_id: Option, + #[validate(required, length(min = 1, message = "用户类型不能为空"))] + pub user_type: Option, + #[validate(required, length(min = 1, message = "用户所属区域不能为空"))] + pub country_code: Option, } diff --git a/service/src/game_account.rs b/service/src/game_account.rs index c049f15..af097eb 100644 --- a/service/src/game_account.rs +++ b/service/src/game_account.rs @@ -8,7 +8,7 @@ use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, Set}; pub async fn create(req: GameAccountCreate) -> ResResult> { match GameAccount::find() - .filter(game_account::Column::PlatformId.eq(req.platform_id.clone())) + .filter(game_account::Column::PlatformId.eq(req.platform_id.clone().unwrap())) .count(db!()) .await { @@ -26,11 +26,11 @@ pub async fn create(req: GameAccountCreate) -> ResResult> { let now = chrono::Local::now().naive_local(); let model = game_account::ActiveModel { - username: Set(req.username), + username: Set(req.username.unwrap()), email: Set(Option::from(req.email)), - platform_id: Set(req.platform_id), - user_type: Set(req.user_type), - country_code: Set(req.country_code), + platform_id: Set(req.platform_id.unwrap()), + user_type: Set(req.user_type.unwrap()), + country_code: Set(req.country_code.unwrap()), created_at: Set(now), ..Default::default() };