-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sma): Add import from SMA Sales
- Loading branch information
Showing
8 changed files
with
390 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod product; | ||
pub mod sma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
use crate::{error::AppError, models::utils::sma::SmaChange}; | ||
|
||
use super::product::{EditedProductResponse, ProductResponse}; | ||
|
||
#[derive(Debug, Clone, PartialEq, serde::Serialize)] | ||
pub struct SmaResponse { | ||
pub unchanged: Vec<uuid::Uuid>, | ||
pub changed: Vec<EditedProductResponse>, | ||
pub created: Vec<ProductResponse>, | ||
} | ||
|
||
impl TryFrom<Vec<SmaChange>> for SmaResponse { | ||
type Error = AppError; | ||
|
||
fn try_from(value: Vec<SmaChange>) -> Result<Self, Self::Error> { | ||
let iter = value.into_iter(); | ||
Ok(Self { | ||
unchanged: iter | ||
.clone() | ||
.filter_map(|x| match x { | ||
SmaChange::Unchanged(x) => Some(x), | ||
_ => None, | ||
}) | ||
.map(|x| x.id) | ||
.collect(), | ||
changed: vec![], // TODO: Changed | ||
created: iter | ||
.filter_map(|x| match x { | ||
SmaChange::Created(x) => Some(x), | ||
_ => None, | ||
}) | ||
.map(TryInto::<ProductResponse>::try_into) | ||
.collect::<Result<_, AppError>>()?, | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
pub mod pagination; | ||
pub mod sma; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
use entity::product::Model as Product; | ||
use serde::Deserialize; | ||
use serde_json::Value; | ||
|
||
use crate::models::response::product::EditedProductResponse; | ||
|
||
#[derive(Debug, Clone, PartialEq)] | ||
pub enum SmaChange { | ||
Unchanged(Product), | ||
Edited(EditedProductResponse), | ||
Created(Product), | ||
} | ||
|
||
#[derive(Debug, Clone, Copy, PartialEq, serde::Deserialize)] | ||
#[serde(rename_all = "lowercase")] | ||
pub struct SmaChangeTypeMatrix { | ||
#[serde(default)] | ||
pub name: bool, | ||
#[serde(default)] | ||
pub price: bool, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)] | ||
pub struct SmaProducts { | ||
pub data: Vec<SmaProduct>, | ||
pub limit: Value, | ||
pub start: Value, | ||
pub total: u64, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)] | ||
pub struct SmaProduct { | ||
pub category: SmCategory, | ||
pub code: String, | ||
pub id: String, | ||
pub image_url: Option<String>, | ||
pub name: String, | ||
pub net_price: String, | ||
pub price: String, | ||
pub slug: String, | ||
pub tax_method: String, | ||
pub tax_rate: SmaTaxRate, | ||
#[serde(rename = "type")] | ||
pub type_field: String, | ||
pub unit: SmaUnit, | ||
pub unit_price: String, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)] | ||
pub struct SmCategory { | ||
pub id: String, | ||
pub code: String, | ||
pub name: String, | ||
pub image: Option<String>, | ||
pub parent_id: String, | ||
pub slug: String, | ||
pub description: String, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)] | ||
pub struct SmaTaxRate { | ||
pub id: String, | ||
pub name: String, | ||
pub code: String, | ||
pub rate: String, | ||
#[serde(rename = "type")] | ||
pub type_field: String, | ||
} | ||
|
||
#[derive(Default, Debug, Clone, PartialEq, Deserialize)] | ||
pub struct SmaUnit { | ||
pub id: String, | ||
pub code: String, | ||
pub name: String, | ||
pub base_unit: Option<String>, | ||
pub operator: Option<String>, | ||
pub unit_value: Option<String>, | ||
pub operation_value: Option<String>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,5 +8,6 @@ pub mod download; | |
pub mod login; | ||
pub mod logout; | ||
pub mod openapi; | ||
pub mod sma; | ||
pub mod status; | ||
pub mod upload; |
Oops, something went wrong.