order.rs (2846B)
1 //! Order models and API request/response structures 2 3 use bigdecimal::BigDecimal; 4 use chrono::{DateTime, Utc}; 5 use serde::{Deserialize, Serialize}; 6 use sqlx::FromRow; 7 use uuid::Uuid; 8 9 /// Complete order with all related data (from v_orders_complete view) 10 #[derive(Debug, Serialize, FromRow)] 11 #[allow(dead_code)] // id field needed for FromRow but skipped in JSON 12 pub struct OrderComplete { 13 #[serde(skip)] 14 pub id: i32, 15 16 #[serde(rename = "eid")] 17 pub eid: Uuid, 18 19 pub order_number: String, 20 pub customer_email: String, 21 pub customer_phone: Option<String>, 22 23 pub subtotal: BigDecimal, 24 pub tax_amount: BigDecimal, 25 pub shipping_amount: BigDecimal, 26 pub total: BigDecimal, 27 28 pub status: String, 29 pub payment_status: String, 30 pub is_guest_order: bool, 31 32 pub ordered_at: DateTime<Utc>, 33 pub created_at: DateTime<Utc>, 34 pub updated_at: DateTime<Utc>, 35 36 // Related data as JSON 37 pub shipping_address: Option<serde_json::Value>, 38 pub payment: Option<serde_json::Value>, 39 pub shipment: Option<serde_json::Value>, 40 41 pub item_count: Option<i64>, 42 pub total_quantity: Option<i64>, 43 } 44 45 /// Request to create a new order 46 #[derive(Debug, Clone, Deserialize)] 47 pub struct CreateOrderRequest { 48 pub customer_email: String, 49 pub customer_phone: Option<String>, 50 pub items: Vec<CreateOrderItemRequest>, 51 pub shipping_address: CreateShippingAddressRequest, 52 pub payment: CreatePaymentRequest, 53 } 54 55 /// Order item in create request 56 #[derive(Debug, Clone, Deserialize)] 57 pub struct CreateOrderItemRequest { 58 pub product_uuid: Uuid, 59 pub product_name: String, 60 pub product_sku: Option<String>, 61 pub quantity: i32, 62 pub unit_price: BigDecimal, 63 } 64 65 /// Shipping address in create request 66 #[derive(Debug, Clone, Deserialize)] 67 pub struct CreateShippingAddressRequest { 68 pub first_name: String, 69 pub last_name: String, 70 pub address_line1: String, 71 pub address_line2: Option<String>, 72 pub city: String, 73 pub state: String, 74 pub postal_code: String, 75 pub country: String, 76 pub phone: Option<String>, 77 } 78 79 /// Payment info in create request 80 #[derive(Debug, Clone, Deserialize)] 81 pub struct CreatePaymentRequest { 82 pub payment_method: String, 83 pub card_last4: Option<String>, 84 pub card_brand: Option<String>, 85 } 86 87 /// Query parameters for listing orders 88 #[derive(Debug, Clone, Deserialize)] 89 pub struct OrderQueryParams { 90 pub page: Option<i32>, 91 pub page_size: Option<i32>, 92 pub status: Option<String>, 93 pub payment_status: Option<String>, 94 pub customer_email: Option<String>, 95 pub order_number: Option<String>, 96 } 97 98 /// Paginated orders response 99 #[derive(Debug, Serialize)] 100 pub struct OrdersResponse { 101 pub orders: Vec<OrderComplete>, 102 pub total_count: i64, 103 pub page: i32, 104 pub page_size: i32, 105 pub total_pages: i32, 106 }