45 lines
1.4 KiB
Rust
45 lines
1.4 KiB
Rust
use domain::entities::game_account;
|
|
use domain::entities::prelude::GameAccount;
|
|
use domain::models::game_account::GameAccountCreate;
|
|
use library::db;
|
|
use library::resp::response::ResErr::{ErrPerm, ErrSystem};
|
|
use library::resp::response::{ResOK, ResResult};
|
|
use sea_orm::{ColumnTrait, EntityTrait, PaginatorTrait, QueryFilter, Set};
|
|
|
|
pub async fn create(req: GameAccountCreate) -> ResResult<ResOK<()>> {
|
|
match GameAccount::find()
|
|
.filter(game_account::Column::PlatformId.eq(req.platform_id.clone()))
|
|
.count(db!())
|
|
.await
|
|
{
|
|
Err(err) => {
|
|
tracing::error!(error = ?err, "err find game account");
|
|
return Err(ErrSystem(None));
|
|
}
|
|
Ok(v) => {
|
|
if v > 0 {
|
|
return Err(ErrPerm(Some("用户已存在".to_string())));
|
|
}
|
|
}
|
|
}
|
|
|
|
let now = chrono::Local::now().naive_local();
|
|
|
|
let model = game_account::ActiveModel {
|
|
username: Set(req.username),
|
|
email: Set(Option::from(req.email)),
|
|
platform_id: Set(req.platform_id),
|
|
user_type: Set(req.user_type),
|
|
country_code: Set(req.country_code),
|
|
created_at: Set(now),
|
|
..Default::default()
|
|
};
|
|
|
|
if let Err(err) = GameAccount::insert(model).exec(db!()).await {
|
|
tracing::error!(error = ?err, "err insert game account");
|
|
return Err(ErrSystem(None));
|
|
}
|
|
|
|
Ok(ResOK(None))
|
|
}
|