cala_server/graphql/
journal.rs

1use async_graphql::*;
2
3use super::{convert::ToGlobalId, primitives::*};
4
5#[derive(InputObject)]
6pub struct JournalCreateInput {
7    pub(super) journal_id: UUID,
8    pub(super) name: String,
9    #[graphql(default)]
10    pub(super) status: Status,
11    pub(super) description: Option<String>,
12}
13
14#[derive(Clone, SimpleObject)]
15pub struct Journal {
16    id: ID,
17    journal_id: UUID,
18    version: u32,
19    name: String,
20    status: Status,
21    description: Option<String>,
22    created_at: Timestamp,
23    modified_at: Timestamp,
24}
25
26#[derive(SimpleObject)]
27pub struct JournalCreatePayload {
28    pub journal: Journal,
29}
30
31impl ToGlobalId for cala_ledger::JournalId {
32    fn to_global_id(&self) -> async_graphql::types::ID {
33        async_graphql::types::ID::from(format!("journal:{self}"))
34    }
35}
36
37impl From<cala_ledger::journal::Journal> for Journal {
38    fn from(entity: cala_ledger::journal::Journal) -> Self {
39        let created_at = entity.created_at();
40        let modified_at = entity.modified_at();
41        let values = entity.into_values();
42        Self {
43            id: values.id.to_global_id(),
44            journal_id: UUID::from(values.id),
45            version: values.version,
46            name: values.name,
47            status: values.status,
48            description: values.description,
49            created_at: Timestamp::from(created_at),
50            modified_at: Timestamp::from(modified_at),
51        }
52    }
53}
54
55impl From<cala_ledger::journal::Journal> for JournalCreatePayload {
56    fn from(value: cala_ledger::journal::Journal) -> Self {
57        JournalCreatePayload {
58            journal: Journal::from(value),
59        }
60    }
61}
62
63#[derive(InputObject)]
64pub struct JournalUpdateInput {
65    pub(super) name: Option<String>,
66    pub(super) status: Option<Status>,
67    pub(super) description: Option<String>,
68}
69
70#[derive(SimpleObject)]
71pub struct JournalUpdatePayload {
72    pub journal: Journal,
73}
74
75impl From<cala_ledger::journal::Journal> for JournalUpdatePayload {
76    fn from(value: cala_ledger::journal::Journal) -> Self {
77        JournalUpdatePayload {
78            journal: Journal::from(value),
79        }
80    }
81}