fistinc-auth 0.1.0

Paging types for Fist Inc bank
Documentation
use actix_web::web;
use email_address::EmailAddress;
use fistinc_errors::ApiResult;
use serde::{Deserialize, Serialize};

use crate::domain::entity::User;
use crate::domain::services::UserAuthService;

#[derive(Debug, Deserialize)]
pub struct LoginRequest {
    email: EmailAddress,
    password: String,
}

#[derive(Debug, Serialize)]
pub struct LoginResponse {
    token: String,
    user: User,
}

pub async fn login(
    auth_service: web::Data<dyn UserAuthService>,
    data: web::Json<LoginRequest>,
) -> ApiResult<web::Json<LoginResponse>> {
    let (user, token) =
        auth_service.login(
            &data.email,
            &data.password,
        ).await?;
    let resp = LoginResponse { user, token };
    Ok(web::Json(resp))
}