修GameAccount->PlayerInfo
This commit is contained in:
parent
a98dbe65bc
commit
269c739ce9
@ -1 +1 @@
|
||||
pub mod game_account;
|
||||
pub mod player_info;
|
@ -1,17 +1,17 @@
|
||||
use axum::Json;
|
||||
use axum_extra::extract::WithRejection;
|
||||
use domain::dto::game_account::GameAccountCreate;
|
||||
use domain::dto::player_info::PlayerInfoRegister;
|
||||
use library::resp::{rejection::IRejection, response::{ResErr, ResOK, ResResult}};
|
||||
use validator::Validate;
|
||||
|
||||
pub async fn create(
|
||||
WithRejection(Json(req), _): IRejection<Json<GameAccountCreate>>
|
||||
WithRejection(Json(req), _): IRejection<Json<PlayerInfoRegister>>
|
||||
) -> ResResult<ResOK<()>> {
|
||||
if let Err(err) = req.validate() {
|
||||
return Err(ResErr::ErrParams(Some(err.to_string())));
|
||||
}
|
||||
|
||||
service::game_account::create(req).await?;
|
||||
service::player_info::register(req).await?;
|
||||
|
||||
Ok(ResOK(None))
|
||||
}
|
@ -8,7 +8,7 @@ use tower_http::trace::TraceLayer;
|
||||
pub(crate) fn init() -> Router {
|
||||
let open = Router::new().route("/", get(|| async { "hello" }));
|
||||
|
||||
let auth = Router::new().route("/game_accounts", post(controller::game_account::create));
|
||||
let auth = Router::new().route("/game_accounts", post(controller::player_info::create));
|
||||
|
||||
Router::new()
|
||||
.nest("/", open)
|
||||
|
@ -1 +1 @@
|
||||
pub mod game_account;
|
||||
pub mod player_info;
|
@ -2,7 +2,7 @@ use serde::{Deserialize, Serialize};
|
||||
use validator::Validate;
|
||||
|
||||
#[derive(Debug, Validate, Deserialize, Serialize)]
|
||||
pub struct GameAccountCreate {
|
||||
pub struct PlayerInfoRegister {
|
||||
#[validate(required(message = "用户名称不能为空"), length(min = 1, message = "用户名称不能为空"))]
|
||||
pub username: Option<String>,
|
||||
#[validate(required, length(min = 1, message = "电子邮箱不能为空"))]
|
@ -2,4 +2,4 @@
|
||||
|
||||
pub mod prelude;
|
||||
pub mod account;
|
||||
pub mod game_account;
|
||||
pub mod player_info;
|
||||
|
@ -3,7 +3,7 @@
|
||||
use sea_orm::entity::prelude::*;
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, DeriveEntityModel, Eq)]
|
||||
#[sea_orm(table_name = "game_account")]
|
||||
#[sea_orm(table_name = "player_info")]
|
||||
pub struct Model {
|
||||
#[sea_orm(primary_key)]
|
||||
pub id: u64,
|
@ -1,4 +1,4 @@
|
||||
//! `SeaORM` Entity. Generated by sea-orm-codegen 0.12.14
|
||||
|
||||
pub use super::account::Entity as Account;
|
||||
pub use super::game_account::Entity as GameAccount;
|
||||
pub use super::player_info::Entity as PlayerInfo;
|
||||
|
@ -1 +1 @@
|
||||
pub mod game_account;
|
||||
pub mod player_info;
|
@ -1,14 +1,14 @@
|
||||
use domain::entities::game_account;
|
||||
use domain::entities::prelude::GameAccount;
|
||||
use domain::dto::game_account::GameAccountCreate;
|
||||
use domain::entities::player_info;
|
||||
use domain::entities::prelude::PlayerInfo;
|
||||
use domain::dto::player_info::PlayerInfoRegister;
|
||||
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().unwrap()))
|
||||
pub async fn register(req: PlayerInfoRegister) -> ResResult<ResOK<()>> {
|
||||
match PlayerInfo::find()
|
||||
.filter(player_info::Column::PlatformId.eq(req.platform_id.clone().unwrap()))
|
||||
.count(db!())
|
||||
.await
|
||||
{
|
||||
@ -25,7 +25,7 @@ pub async fn create(req: GameAccountCreate) -> ResResult<ResOK<()>> {
|
||||
|
||||
let now = chrono::Local::now().naive_local();
|
||||
|
||||
let model = game_account::ActiveModel {
|
||||
let model = player_info::ActiveModel {
|
||||
username: Set(req.username.unwrap()),
|
||||
email: Set(Option::from(req.email)),
|
||||
platform_id: Set(req.platform_id.unwrap()),
|
||||
@ -35,7 +35,7 @@ pub async fn create(req: GameAccountCreate) -> ResResult<ResOK<()>> {
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
if let Err(err) = GameAccount::insert(model).exec(db!()).await {
|
||||
if let Err(err) = PlayerInfo::insert(model).exec(db!()).await {
|
||||
tracing::error!(error = ?err, "err insert game account");
|
||||
return Err(ErrSystem(None));
|
||||
}
|
Loading…
Reference in New Issue
Block a user