init project, impl authorization
This commit is contained in:
57
backend/src/dto/account/mod.rs
Normal file
57
backend/src/dto/account/mod.rs
Normal file
@ -0,0 +1,57 @@
|
||||
use crate::service::account::entity::Account as AccountEntity;
|
||||
use derive_more::Constructor;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct CreateAccount {
|
||||
pub name: String,
|
||||
pub email: Option<String>,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
pub struct Login {
|
||||
pub name: String,
|
||||
pub password: String,
|
||||
}
|
||||
|
||||
#[derive(Constructor, Serialize)]
|
||||
pub struct Account {
|
||||
pub email: Option<String>,
|
||||
pub name: String,
|
||||
pub id: Uuid,
|
||||
}
|
||||
|
||||
#[derive(Constructor, Serialize)]
|
||||
pub struct Tokens {
|
||||
pub refresh: String,
|
||||
pub access: String,
|
||||
}
|
||||
|
||||
#[derive(Constructor, Serialize)]
|
||||
pub struct AccountCreated {
|
||||
pub account: Account,
|
||||
pub tokens: Tokens,
|
||||
}
|
||||
|
||||
#[derive(Constructor, Serialize, Deserialize)]
|
||||
pub struct AccessTokenClaims {
|
||||
pub exp: i64,
|
||||
pub sub: String,
|
||||
pub iat: i64,
|
||||
}
|
||||
|
||||
#[derive(Constructor, Serialize, Deserialize)]
|
||||
pub struct RefreshTokenClaims {
|
||||
pub exp: i64,
|
||||
pub sub: String,
|
||||
pub iat: i64,
|
||||
pub refresh_token_id: Uuid,
|
||||
}
|
||||
|
||||
impl From<AccountEntity> for Account {
|
||||
fn from(entity: AccountEntity) -> Self {
|
||||
Account::new(entity.email, entity.username, entity.id)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user