feat: bootstrap ordering web adapter
This commit is contained in:
parent
a388ad4fde
commit
9c3fd1be5d
6 changed files with 114 additions and 2 deletions
|
@ -1,3 +1,4 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
pub mod web;
|
||||
|
|
61
src/ordering/adapters/input/web/errors.rs
Normal file
61
src/ordering/adapters/input/web/errors.rs
Normal file
|
@ -0,0 +1,61 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use actix_web::http::StatusCode;
|
||||
use actix_web::{HttpResponse, ResponseError};
|
||||
use derive_more::Display;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::inventory::application::services::errors::*;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, Debug, Eq, PartialEq)]
|
||||
struct ErrorResponse {
|
||||
error: String,
|
||||
}
|
||||
|
||||
impl From<WebError> for ErrorResponse {
|
||||
fn from(value: WebError) -> Self {
|
||||
ErrorResponse {
|
||||
error: serde_json::to_string(&value).unwrap_or_else(|_| {
|
||||
log::error!("Unable to serialize error");
|
||||
"Unable to serialize error".into()
|
||||
}),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Display, Clone, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub enum WebError {
|
||||
InternalError,
|
||||
BadRequest,
|
||||
|
||||
}
|
||||
|
||||
impl From<InventoryError> for WebError {
|
||||
fn from(v: InventoryError) -> Self {
|
||||
match v {
|
||||
InventoryError::InternalError => Self::InternalError,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ResponseError for WebError {
|
||||
fn status_code(&self) -> StatusCode {
|
||||
match self {
|
||||
Self::InternalError => StatusCode::INTERNAL_SERVER_ERROR,
|
||||
Self::BadRequest => StatusCode::BAD_REQUEST,
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
fn error_response(&self) -> actix_web::HttpResponse {
|
||||
let e: ErrorResponse = self.clone().into();
|
||||
match self {
|
||||
Self::InternalError => HttpResponse::InternalServerError().json(e),
|
||||
Self::BadRequest => HttpResponse::BadRequest().json(e),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub type WebJsonRepsonse<V> = Result<V, WebError>;
|
30
src/ordering/adapters/input/web/mod.rs
Normal file
30
src/ordering/adapters/input/web/mod.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
use actix_web::web;
|
||||
|
||||
use crate::inventory::adapters::types;
|
||||
|
||||
mod employee;
|
||||
mod errors;
|
||||
mod owner;
|
||||
mod routes;
|
||||
|
||||
pub use errors::WebJsonRepsonse;
|
||||
|
||||
pub use routes::RoutesRepository;
|
||||
|
||||
pub fn load_ctx() -> impl FnOnce(&mut web::ServiceConfig) {
|
||||
let routes = types::WebInventoryRoutesRepository::new(Arc::new(RoutesRepository::default()));
|
||||
|
||||
let f = move |cfg: &mut web::ServiceConfig| {
|
||||
cfg.app_data(routes);
|
||||
cfg.configure(owner::services);
|
||||
cfg.configure(employee::services);
|
||||
};
|
||||
|
||||
Box::new(f)
|
||||
}
|
20
src/ordering/adapters/input/web/routes.rs
Normal file
20
src/ordering/adapters/input/web/routes.rs
Normal file
|
@ -0,0 +1,20 @@
|
|||
// SPDX-FileCopyrightText: 2024 Aravinth Manivannan <realaravinth@batsense.net>
|
||||
//
|
||||
// SPDX-License-Identifier: AGPL-3.0-or-later
|
||||
|
||||
use url::Url;
|
||||
use uuid::Uuid;
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct RoutesRepository {
|
||||
}
|
||||
|
||||
impl Default for RoutesRepository {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl RoutesRepository {
|
||||
}
|
|
@ -68,7 +68,7 @@ pub fn load_adapters(pool: PgPool, settings: Settings) -> impl FnOnce(&mut web::
|
|||
));
|
||||
|
||||
let f = move |cfg: &mut web::ServiceConfig| {
|
||||
//cfg.configure(input::web::load_ctx());
|
||||
cfg.configure(input::web::load_ctx());
|
||||
cfg.app_data(Data::new(category_cqrs_query.clone()));
|
||||
cfg.app_data(Data::new(product_cqrs_query.clone()));
|
||||
cfg.app_data(Data::new(customization_cqrs_query.clone()));
|
||||
|
|
|
@ -15,7 +15,7 @@ use postgres_es::PostgresCqrs;
|
|||
|
||||
use crate::ordering::{
|
||||
adapters::{
|
||||
// input::web::RoutesRepository,
|
||||
input::web::RoutesRepository,
|
||||
output::db::{
|
||||
category_view::CategoryView, customization_view::CustomizationView, kot_view::KotView,
|
||||
line_item_view::LineItemView, order_view::OrderView, product_view::ProductView,
|
||||
|
|
Loading…
Reference in a new issue