1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
use actix_web::{HttpResponse, ResponseError}; use derive_more::Display; use serde::{Deserialize, Serialize}; use validator::Validate; #[derive(Serialize, Deserialize, Debug, Clone, Validate)] pub struct GetListPromoCodesBody { pub menu: String, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct GetListPromoCodesResult { pub list: Vec<PromoCodeAggregation>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeAggregation { pub id: Option<String>, pub code: Option<String>, pub kind: Option<String>, pub values: Option<PromoCodeValuesAggregation>, pub limits: Option<PromoCodeLimitsAggregation>, pub requirements: Option<PromoCodeRequirementsAggregation>, pub targets: Option<PromoCodeTargetsAggregation>, pub filters: Option<PromoCodeFiltersAggregation>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeValuesAggregation { pub percentage: Option<i32>, pub price: Option<PromoCodePriceAggregation>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodePriceAggregation { pub value: Option<f64>, pub currency: Option<PromoCodeCurrencyAggregation>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeCurrencyAggregation { pub id: Option<String>, pub code: Option<String>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeLimitsAggregation { pub start_date: Option<String>, pub end_date: Option<String>, pub maximum_uses: Option<i32>, pub is_used_once: Option<bool>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeRequirementsAggregation { pub kind: Option<String>, pub minimum_cart_total_price: Option<f64>, pub minimum_cart_total_quantity: Option<f64>, pub minimum_past_orders_total_price: Option<f64>, pub minimum_past_orders_total_quantity: Option<f64>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeTargetsAggregation { pub kind: Option<String>, pub customers: Option<Vec<PromoCodeCustomerIdAggregation>>, pub groups: Option<Vec<PromoCodeGroupIdAggregation>>, pub subscribers: Option<Vec<PromoCodeSubscriberIdAggregation>>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeCustomerIdAggregation { pub customer: Option<String>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeGroupIdAggregation { pub group: Option<String>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeSubscriberIdAggregation { pub subscriber: Option<String>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeFiltersAggregation { pub kind: Option<String>, pub collections: Option<Vec<PromoCodeCollectionIdAggregation>>, pub categories: Option<Vec<PromoCodeCategoryIdAggregation>>, pub products: Option<Vec<PromoCodeProductIdAggregation>>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeCollectionIdAggregation { pub collection: Option<String>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeCategoryIdAggregation { pub category: Option<String>, } #[derive(Serialize, Deserialize, Debug, Clone)] pub struct PromoCodeProductIdAggregation { pub product: Option<String>, } #[derive(Debug, Display)] pub enum GetListPromoCodesError { #[display(fmt = "invalid_object_id")] InvalidObjectId, Default(String), } impl ResponseError for GetListPromoCodesError { fn error_response(&self) -> HttpResponse { match self { GetListPromoCodesError::InvalidObjectId => { HttpResponse::NotAcceptable().body("invalid_object_id") } GetListPromoCodesError::Default(error) => HttpResponse::BadRequest().body(error), } } }