cscart_rs/service/
category_service.rs

1use crate::prelude::*;
2use crate::service::config::ServiceConfig;
3use crate::types::Category;
4use crate::{
5    impl_create_method, impl_delete_by_id_method, impl_get_all_entity_method, impl_get_all_method,
6    impl_get_by_id_method, impl_update_by_id_method,
7};
8use serde::Deserialize;
9use serde_json::Value;
10
11pub struct CategoryService {
12    config: ServiceConfig<Authenticated>,
13}
14
15impl CategoryService {
16    pub fn with_config(service: ServiceConfig<Authenticated>) -> CategoryService {
17        Self { config: service }
18    }
19}
20
21#[derive(Deserialize, Debug)]
22pub struct GetAllCategoryResponse {
23    pub categories: Vec<Category>,
24}
25
26#[derive(Deserialize, Debug)]
27pub struct GetAllProductsResponse {
28    pub products: Vec<Product>,
29}
30
31#[derive(Deserialize, Debug)]
32pub struct CreateCategoryResponse {
33    pub category_id: i32,
34}
35
36#[derive(Deserialize, Debug)]
37pub struct UpdateCategoryResponse {
38    pub category_id: String,
39}
40
41impl_create_method!(CategoryService, CreateCategoryResponse);
42impl_get_by_id_method!(CategoryService, Category);
43impl_get_all_method!(CategoryService, GetAllCategoryResponse);
44impl_update_by_id_method!(CategoryService, UpdateCategoryResponse);
45impl_delete_by_id_method!(CategoryService, Value);
46impl_get_all_entity_method!(CategoryService, GetAllProductsResponse);