use actix_web::{HttpResponse, web};
use service::{AppService, auth::login::LoginParams};
use session::Session;

use crate::error::ApiError;

fn ok() -> Result<HttpResponse, ApiError> {
    Ok(HttpResponse::Ok().finish())
}

#[utoipa::path(
    post,
    path = "/api/v1/auth/login",
    request_body = LoginParams,
    responses((status = 200)),
    tag = "auth"
)]
pub async fn login(
    session: Session,
    params: web::Json<LoginParams>,
    service: web::Data<AppService>,
) -> Result<HttpResponse, ApiError> {
    service.auth_login(params.into_inner(), session).await?;
    ok()
}
