cscart_rs/service/
product_service.rs

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