Skip to main content

qm_entity/
model.rs

1use async_graphql::{InputObject, SimpleObject};
2use chrono::{DateTime, Utc};
3use qm_mongodb::bson::Uuid;
4use serde::{Deserialize, Serialize};
5
6#[derive(Default, Debug, Clone, SimpleObject, Serialize, Deserialize)]
7#[serde(rename_all = "camelCase")]
8/// Modification tracking for entities.
9pub struct Modification {
10    /// User ID who made the modification.
11    #[graphql(skip)]
12    pub user_id: Option<Uuid>,
13    /// Timestamp of modification.
14    pub at: DateTime<Utc>,
15}
16
17impl Modification {
18    /// Creates a new Modification with the given user ID.
19    pub fn new(user_id: Uuid) -> Self {
20        Self {
21            user_id: Some(user_id),
22            at: Utc::now(),
23        }
24    }
25}
26
27/// Filter for list queries.
28#[derive(
29    Default, Debug, Clone, InputObject, Serialize, Deserialize, Eq, PartialEq, Hash, PartialOrd, Ord,
30)]
31pub struct ListFilter {
32    /// Page number.
33    pub page: Option<usize>,
34    /// Items per page limit.
35    pub limit: Option<usize>,
36}
37
38/// Result of a list query.
39pub struct ListResult<T> {
40    /// Items returned.
41    pub items: Vec<T>,
42    /// Limit used.
43    pub limit: Option<i64>,
44    /// Total count.
45    pub total: Option<i64>,
46    /// Page number.
47    pub page: Option<i64>,
48}