2022-05-10 16:20:37 +02:00
|
|
|
use chrono::NaiveDateTime;
|
2022-05-09 16:17:27 +02:00
|
|
|
use derive_more::Deref;
|
|
|
|
#[cfg(feature = "dummy")]
|
|
|
|
use fake::Fake;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2022-05-06 11:47:18 +02:00
|
|
|
|
2022-05-10 16:20:37 +02:00
|
|
|
use crate::*;
|
2022-05-08 14:59:59 +02:00
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2022-05-06 11:47:18 +02:00
|
|
|
#[serde(transparent)]
|
|
|
|
pub struct AccountOrders(pub Vec<AccountOrder>);
|
|
|
|
|
|
|
|
impl From<(Vec<crate::AccountOrder>, Vec<crate::OrderItem>)> for AccountOrders {
|
|
|
|
fn from((orders, mut items): (Vec<crate::AccountOrder>, Vec<crate::OrderItem>)) -> Self {
|
|
|
|
Self(
|
|
|
|
orders
|
|
|
|
.into_iter()
|
|
|
|
.map(
|
|
|
|
|crate::AccountOrder {
|
|
|
|
id,
|
|
|
|
buyer_id,
|
|
|
|
status,
|
|
|
|
order_id,
|
|
|
|
order_ext_id: _,
|
|
|
|
service_order_id: _,
|
|
|
|
}| {
|
|
|
|
AccountOrder {
|
|
|
|
id,
|
|
|
|
buyer_id,
|
|
|
|
status,
|
|
|
|
order_id,
|
|
|
|
items: items.drain_filter(|item| item.order_id == id).collect(),
|
|
|
|
}
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.collect(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(crate::AccountOrder, Vec<crate::OrderItem>)> for AccountOrder {
|
|
|
|
fn from(
|
|
|
|
(
|
|
|
|
crate::AccountOrder {
|
|
|
|
id,
|
|
|
|
buyer_id,
|
|
|
|
status,
|
|
|
|
order_id,
|
|
|
|
order_ext_id: _,
|
|
|
|
service_order_id: _,
|
|
|
|
},
|
|
|
|
mut items,
|
|
|
|
): (crate::AccountOrder, Vec<crate::OrderItem>),
|
|
|
|
) -> Self {
|
|
|
|
AccountOrder {
|
|
|
|
id,
|
|
|
|
buyer_id,
|
|
|
|
status,
|
|
|
|
order_id,
|
|
|
|
items: items.drain_filter(|item| item.order_id == id).collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2022-05-06 11:47:18 +02:00
|
|
|
pub struct AccountOrder {
|
|
|
|
pub id: crate::AccountOrderId,
|
|
|
|
pub buyer_id: crate::AccountId,
|
|
|
|
pub status: crate::OrderStatus,
|
|
|
|
pub order_id: Option<crate::OrderId>,
|
|
|
|
pub items: Vec<crate::OrderItem>,
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2022-05-06 11:47:18 +02:00
|
|
|
pub struct ShoppingCartItem {
|
2022-05-10 16:20:37 +02:00
|
|
|
pub id: ShoppingCartId,
|
|
|
|
pub product_id: ProductId,
|
|
|
|
pub shopping_cart_id: ShoppingCartId,
|
|
|
|
pub quantity: Quantity,
|
|
|
|
pub quantity_unit: QuantityUnit,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<crate::ShoppingCartItem> for ShoppingCartItem {
|
|
|
|
fn from(
|
|
|
|
crate::ShoppingCartItem {
|
|
|
|
id,
|
|
|
|
product_id,
|
|
|
|
shopping_cart_id,
|
|
|
|
quantity,
|
|
|
|
quantity_unit,
|
|
|
|
}: crate::ShoppingCartItem,
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
id,
|
|
|
|
product_id,
|
|
|
|
shopping_cart_id,
|
|
|
|
quantity,
|
|
|
|
quantity_unit,
|
|
|
|
}
|
|
|
|
}
|
2022-05-06 11:47:18 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
2022-05-06 11:47:18 +02:00
|
|
|
pub struct ShoppingCart {
|
2022-05-10 16:20:37 +02:00
|
|
|
pub id: ShoppingCartId,
|
|
|
|
pub buyer_id: AccountId,
|
|
|
|
pub payment_method: PaymentMethod,
|
|
|
|
pub state: ShoppingCartState,
|
2022-05-06 11:47:18 +02:00
|
|
|
pub items: Vec<ShoppingCartItem>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<(crate::ShoppingCart, Vec<crate::ShoppingCartItem>)> for ShoppingCart {
|
|
|
|
fn from(
|
|
|
|
(
|
|
|
|
crate::ShoppingCart {
|
|
|
|
id,
|
|
|
|
buyer_id,
|
|
|
|
payment_method,
|
|
|
|
state,
|
|
|
|
},
|
|
|
|
items,
|
|
|
|
): (crate::ShoppingCart, Vec<crate::ShoppingCartItem>),
|
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
id,
|
|
|
|
buyer_id,
|
|
|
|
payment_method,
|
|
|
|
state,
|
|
|
|
items: items
|
|
|
|
.into_iter()
|
|
|
|
.map(
|
|
|
|
|crate::ShoppingCartItem {
|
|
|
|
id,
|
|
|
|
product_id,
|
|
|
|
shopping_cart_id,
|
|
|
|
quantity,
|
|
|
|
quantity_unit,
|
|
|
|
}| ShoppingCartItem {
|
|
|
|
id,
|
|
|
|
product_id,
|
|
|
|
shopping_cart_id,
|
|
|
|
quantity,
|
|
|
|
quantity_unit,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
.collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-05-08 14:59:59 +02:00
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
2022-05-10 22:32:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Hash)]
|
2022-05-08 14:59:59 +02:00
|
|
|
pub struct Photo {
|
|
|
|
pub id: crate::PhotoId,
|
|
|
|
pub file_name: crate::FileName,
|
2022-05-09 16:17:27 +02:00
|
|
|
pub url: String,
|
|
|
|
pub unique_name: crate::UniqueName,
|
2022-05-08 14:59:59 +02:00
|
|
|
}
|
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
2022-05-10 22:32:22 +02:00
|
|
|
#[derive(Serialize, Deserialize, Debug, Hash)]
|
2022-05-08 14:59:59 +02:00
|
|
|
pub struct Product {
|
|
|
|
pub id: crate::ProductId,
|
|
|
|
pub name: crate::ProductName,
|
|
|
|
pub short_description: crate::ProductShortDesc,
|
|
|
|
pub long_description: crate::ProductLongDesc,
|
|
|
|
pub category: Option<crate::ProductCategory>,
|
|
|
|
pub price: crate::Price,
|
|
|
|
pub deliver_days_flag: crate::Days,
|
|
|
|
pub photos: Vec<Photo>,
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
impl<'path> From<(crate::Product, &mut Vec<ProductLinkedPhoto>, &'path str)> for Product {
|
2022-05-08 14:59:59 +02:00
|
|
|
fn from(
|
|
|
|
(
|
|
|
|
crate::Product {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
short_description,
|
|
|
|
long_description,
|
|
|
|
category,
|
|
|
|
price,
|
|
|
|
deliver_days_flag,
|
|
|
|
},
|
|
|
|
photos,
|
2022-05-09 16:17:27 +02:00
|
|
|
public_path,
|
|
|
|
): (crate::Product, &mut Vec<ProductLinkedPhoto>, &'path str),
|
2022-05-08 14:59:59 +02:00
|
|
|
) -> Self {
|
|
|
|
Self {
|
|
|
|
id,
|
|
|
|
name,
|
|
|
|
short_description,
|
|
|
|
long_description,
|
|
|
|
category,
|
|
|
|
price,
|
|
|
|
deliver_days_flag,
|
|
|
|
photos: photos
|
|
|
|
.drain_filter(|photo| photo.product_id == id)
|
|
|
|
.map(
|
|
|
|
|ProductLinkedPhoto {
|
|
|
|
id,
|
|
|
|
local_path: _,
|
|
|
|
file_name,
|
|
|
|
product_id: _,
|
2022-05-09 16:17:27 +02:00
|
|
|
unique_name,
|
|
|
|
}| Photo {
|
|
|
|
id,
|
|
|
|
url: format!("{}/{}", public_path, unique_name.as_str()),
|
|
|
|
unique_name,
|
|
|
|
file_name,
|
|
|
|
},
|
2022-05-08 14:59:59 +02:00
|
|
|
)
|
|
|
|
.collect(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
#[cfg_attr(feature = "dummy", derive(fake::Dummy))]
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Deref)]
|
2022-05-08 14:59:59 +02:00
|
|
|
#[serde(transparent)]
|
2022-05-09 16:17:27 +02:00
|
|
|
pub struct Products(pub Vec<Product>);
|
2022-05-08 14:59:59 +02:00
|
|
|
|
2022-05-09 16:17:27 +02:00
|
|
|
impl From<(Vec<crate::Product>, Vec<ProductLinkedPhoto>, String)> for Products {
|
|
|
|
fn from(
|
|
|
|
(products, mut photos, public_path): (Vec<crate::Product>, Vec<ProductLinkedPhoto>, String),
|
|
|
|
) -> Self {
|
2022-05-08 14:59:59 +02:00
|
|
|
Self(
|
|
|
|
products
|
|
|
|
.into_iter()
|
2022-05-09 16:17:27 +02:00
|
|
|
.map(|p| (p, &mut photos, public_path.as_str()).into())
|
2022-05-08 14:59:59 +02:00
|
|
|
.collect(),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
}
|
2022-05-10 16:20:37 +02:00
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct SignInInput {
|
|
|
|
pub login: Login,
|
|
|
|
pub password: Password,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct SignInOutput {
|
|
|
|
pub access_token: AccessTokenString,
|
|
|
|
pub refresh_token: RefreshTokenString,
|
|
|
|
pub exp: NaiveDateTime,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct CreateAccountInput {
|
|
|
|
pub email: Email,
|
|
|
|
pub login: Login,
|
|
|
|
pub password: Password,
|
|
|
|
pub password_confirmation: PasswordConfirmation,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct CreateOrderInput {
|
|
|
|
/// Required customer e-mail
|
|
|
|
pub email: String,
|
|
|
|
/// Required customer phone number
|
|
|
|
pub phone: String,
|
|
|
|
/// Required customer first name
|
|
|
|
pub first_name: String,
|
|
|
|
/// Required customer last name
|
|
|
|
pub last_name: String,
|
|
|
|
/// Required customer language
|
|
|
|
pub language: String,
|
|
|
|
/// False if customer is allowed to be charged on site.
|
|
|
|
/// Otherwise it should be true to use payment service for charging
|
|
|
|
pub charge_client: bool,
|
|
|
|
/// User currency
|
|
|
|
pub currency: String,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct DeleteItemInput {
|
|
|
|
pub shopping_cart_item_id: ShoppingCartItemId,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct DeleteItemOutput {
|
|
|
|
pub success: bool,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct CreateItemInput {
|
|
|
|
pub product_id: ProductId,
|
|
|
|
pub quantity: Quantity,
|
|
|
|
pub quantity_unit: QuantityUnit,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct CreateItemOutput {
|
|
|
|
pub success: bool,
|
|
|
|
pub shopping_cart_item: ShoppingCartItem,
|
|
|
|
}
|
|
|
|
|
|
|
|
pub mod admin {
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
|
|
|
|
|
|
use crate::*;
|
|
|
|
|
|
|
|
#[derive(Deserialize, Serialize, Debug)]
|
|
|
|
pub struct RegisterInput {
|
|
|
|
pub login: Login,
|
|
|
|
pub email: Email,
|
|
|
|
pub password: Password,
|
|
|
|
pub password_confirmation: PasswordConfirmation,
|
|
|
|
pub role: Role,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug, Default)]
|
|
|
|
pub struct RegisterResponse {
|
|
|
|
pub success: bool,
|
|
|
|
pub errors: Vec<RegisterError>,
|
|
|
|
pub account: Option<Account>,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub enum RegisterError {
|
|
|
|
PasswordDiffer,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct SignInInput {
|
|
|
|
pub login: Option<Login>,
|
|
|
|
pub email: Option<Email>,
|
|
|
|
pub password: Password,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Serialize, Deserialize, Debug)]
|
|
|
|
pub struct LogoutResponse {}
|
|
|
|
}
|