feat: category web stubs
This commit is contained in:
parent
8899ef7ac1
commit
77e86aea82
2 changed files with 119 additions and 3 deletions
|
@ -13,4 +13,102 @@ use super::errors::*;
|
|||
use super::types;
|
||||
//use crate::utils::uuid::WebGetUUIDInterfaceObj;
|
||||
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {}
|
||||
pub fn services(cfg: &mut web::ServiceConfig) {
|
||||
cfg.service(add_category_ui_handler);
|
||||
cfg.service(add_category_form_submission_handler);
|
||||
cfg.service(update_category_ui_handler);
|
||||
cfg.service(update_category_form_submission_handler);
|
||||
}
|
||||
|
||||
// add_category handlers
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[get("/inventory/category/add")]
|
||||
#[tracing::instrument(name = "add_category UI handler", skip())]
|
||||
async fn add_category_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
||||
use web_ui::inventory::add_category::*;
|
||||
|
||||
let page = AddCategoryPage::page();
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.insert_header(ContentType::html())
|
||||
.body(page))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||
struct AddCategoryPayload {
|
||||
password: String,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[post("/inventory/category/add")]
|
||||
#[tracing::instrument(
|
||||
name = "Add c ategory form submission handler"
|
||||
skip(id, req, payload, inventory_cqrs_exec)
|
||||
)]
|
||||
async fn add_category_form_submission_handler(
|
||||
inventory_cqrs_exec: types::WebInventoryCqrsExec,
|
||||
req: HttpRequest,
|
||||
id: Identity,
|
||||
payload: web::Form<AddCategoryPayload>,
|
||||
) -> WebJsonRepsonse<impl Responder> {
|
||||
let store = "";
|
||||
|
||||
Ok(HttpResponse::Ok().json(store))
|
||||
}
|
||||
|
||||
// update_category handlers
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[get("/inventory/{category_uuid}/update")]
|
||||
#[tracing::instrument(name = "update_category UI handler", skip())]
|
||||
async fn update_category_ui_handler() -> WebJsonRepsonse<impl Responder> {
|
||||
use web_ui::inventory::update_category::*;
|
||||
|
||||
let page = UpdateCategoryPage::page();
|
||||
|
||||
Ok(HttpResponse::Ok()
|
||||
.insert_header(ContentType::html())
|
||||
.body(page))
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize)]
|
||||
struct UpdateCategoryPayload {
|
||||
password: String,
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
#[post("/inventory/{category_uuid}/update")]
|
||||
#[tracing::instrument(
|
||||
name = "update_category form submission handler"
|
||||
skip(id, req, payload, inventory_cqrs_exec)
|
||||
)]
|
||||
async fn update_category_form_submission_handler(
|
||||
inventory_cqrs_exec: types::WebInventoryCqrsExec,
|
||||
req: HttpRequest,
|
||||
id: Identity,
|
||||
payload: web::Form<UpdateCategoryPayload>,
|
||||
) -> WebJsonRepsonse<impl Responder> {
|
||||
let store = "";
|
||||
|
||||
Ok(HttpResponse::Ok().json(store))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::uuid::tests::UUID;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn inventory_web_add_category_ui_works() {
|
||||
let routes = crate::inventory::adapters::input::web::RoutesRepository::default();
|
||||
crate::tests::actix_web_test_utils::page_test_runner(&routes.add_category).await;
|
||||
}
|
||||
|
||||
#[actix_rt::test]
|
||||
async fn inventory_web_update_category_ui_works() {
|
||||
let routes = crate::inventory::adapters::input::web::RoutesRepository::default();
|
||||
crate::tests::actix_web_test_utils::page_test_runner(&routes.update_category(UUID)).await;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -7,7 +7,7 @@ use uuid::Uuid;
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord)]
|
||||
pub struct RoutesRepository {
|
||||
add_category: String,
|
||||
pub add_category: String,
|
||||
add_product: String,
|
||||
add_customization: String,
|
||||
update_product: String,
|
||||
|
@ -31,4 +31,22 @@ impl Default for RoutesRepository {
|
|||
}
|
||||
}
|
||||
|
||||
impl RoutesRepository {}
|
||||
impl RoutesRepository {
|
||||
pub fn update_category(&self, category_uuid: Uuid) -> String {
|
||||
self.update_category
|
||||
.replace("{category_uuid}", &category_uuid.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::utils::uuid::tests::UUID;
|
||||
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn inventory_update_category_route() {
|
||||
let r = RoutesRepository::default();
|
||||
assert_eq!(r.update_category(UUID), format!("/inventory/{UUID}/update"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue