feat: login UI port for oauth domain
This commit is contained in:
parent
253c26227c
commit
2cf8145e31
3 changed files with 61 additions and 0 deletions
51
src/forge/auth/application/port/input/ui/errors.rs
Normal file
51
src/forge/auth/application/port/input/ui/errors.rs
Normal file
|
@ -0,0 +1,51 @@
|
||||||
|
use actix_web::{
|
||||||
|
http::{header, StatusCode},
|
||||||
|
HttpResponse, HttpResponseBuilder, ResponseError,
|
||||||
|
};
|
||||||
|
use derive_more::Display;
|
||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
use crate::forge::auth::application::services::{
|
||||||
|
process_authorization_response::errors::ProcessAuthorizationServiceError,
|
||||||
|
request_authorization::errors::RequestAuthorizationServiceError,
|
||||||
|
};
|
||||||
|
|
||||||
|
pub type InUIResult<V> = Result<V, InUIError>;
|
||||||
|
|
||||||
|
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||||
|
pub enum InUIError {
|
||||||
|
InternalServerError,
|
||||||
|
BadRequest,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ProcessAuthorizationServiceError> for InUIError {
|
||||||
|
fn from(v: ProcessAuthorizationServiceError) -> Self {
|
||||||
|
match v {
|
||||||
|
ProcessAuthorizationServiceError::InteralError => Self::InternalServerError,
|
||||||
|
ProcessAuthorizationServiceError::BadRequest => Self::BadRequest,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RequestAuthorizationServiceError> for InUIError {
|
||||||
|
fn from(v: RequestAuthorizationServiceError) -> Self {
|
||||||
|
match v {
|
||||||
|
RequestAuthorizationServiceError::InteralError => Self::InternalServerError,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ResponseError for InUIError {
|
||||||
|
fn error_response(&self) -> HttpResponse {
|
||||||
|
HttpResponseBuilder::new(self.status_code())
|
||||||
|
.append_header((header::CONTENT_TYPE, "application/sjon; charset=UTF-8"))
|
||||||
|
.body(serde_json::to_string(self).unwrap())
|
||||||
|
}
|
||||||
|
|
||||||
|
fn status_code(&self) -> actix_web::http::StatusCode {
|
||||||
|
match self {
|
||||||
|
Self::BadRequest => StatusCode::BAD_REQUEST,
|
||||||
|
Self::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
7
src/forge/auth/application/port/input/ui/login.rs
Normal file
7
src/forge/auth/application/port/input/ui/login.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
use super::errors::*;
|
||||||
|
use actix_web::HttpResponse;
|
||||||
|
|
||||||
|
#[async_trait::async_trait]
|
||||||
|
pub trait RequestAuthorizationInterface: Send + Sync {
|
||||||
|
async fn request_oauth_authorization(&self, forge_name: String) -> InUIResult<HttpResponse>;
|
||||||
|
}
|
3
src/forge/auth/application/port/input/ui/mod.rs
Normal file
3
src/forge/auth/application/port/input/ui/mod.rs
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
pub mod errors;
|
||||||
|
pub mod login;
|
||||||
|
// login
|
Loading…
Add table
Reference in a new issue