qm_customer/model/
customer.rs

1use async_graphql::{InputObject, SimpleObject};
2use qm_entity::ids::{CustomerId, InfraId};
3use serde::{Deserialize, Serialize};
4use sqlx::types::uuid::Uuid;
5use sqlx::FromRow;
6
7use std::sync::Arc;
8
9use time::PrimitiveDateTime;
10
11#[derive(Debug, InputObject)]
12pub struct QmCreateCustomerInput {
13    pub id: Option<i64>,
14    pub name: String,
15    pub ty: Option<String>,
16}
17
18#[derive(Debug, InputObject)]
19pub struct QmUpdateCustomerInput {
20    pub name: String,
21}
22
23pub struct CustomerData(pub String, pub Option<String>, pub Option<i64>);
24
25#[derive(Debug, Clone, SimpleObject, FromRow, Serialize, Deserialize)]
26#[graphql(complex)]
27pub struct QmCustomer {
28    #[graphql(skip)]
29    pub id: InfraId,
30    pub name: Arc<str>,
31    pub ty: Arc<str>,
32    pub created_by: Uuid,
33    pub created_at: PrimitiveDateTime,
34    pub updated_by: Option<Uuid>,
35    pub updated_at: Option<PrimitiveDateTime>,
36}
37
38#[derive(Debug, Clone, Serialize, Deserialize)]
39pub struct CustomerUpdate {
40    pub id: InfraId,
41    pub name: Arc<str>,
42    pub ty: Arc<str>,
43    pub created_by: Uuid,
44    pub created_at: String,
45    pub updated_by: Option<Uuid>,
46    pub updated_at: Option<String>,
47}
48
49pub struct RemoveCustomerPayload {
50    pub id: InfraId,
51    pub name: Arc<str>,
52}
53
54impl From<CustomerUpdate> for RemoveCustomerPayload {
55    fn from(value: CustomerUpdate) -> Self {
56        Self {
57            id: value.id,
58            name: value.name,
59        }
60    }
61}
62
63impl<'a> From<&'a QmCustomer> for RemoveCustomerPayload {
64    fn from(value: &'a QmCustomer) -> Self {
65        Self {
66            id: value.id,
67            name: value.name.clone(),
68        }
69    }
70}
71
72#[derive(Debug, Clone, SimpleObject)]
73pub struct QmCustomerList {
74    pub items: Arc<[Arc<QmCustomer>]>,
75    pub limit: Option<i64>,
76    pub total: Option<i64>,
77    pub page: Option<i64>,
78}
79
80impl<'a> From<&'a QmCustomer> for CustomerId {
81    fn from(val: &'a QmCustomer) -> Self {
82        (*val.id.as_ref()).into()
83    }
84}