init project, impl authorization

This commit is contained in:
2022-06-06 14:17:58 +05:00
commit ec73d6584f
26 changed files with 2680 additions and 0 deletions

View 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)
}
}