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
use serde::Deserialize;
use serde::Serialize;
use uuid::Uuid;

use crate::account::*;
use crate::events::*;
use crate::gift_card::*;
use crate::order::*;

#[derive(chekov::Command, Serialize, Deserialize)]
#[command(event = "account::AccountOpened", aggregate = "Account")]
pub struct OpenAccount {
    #[command(identifier)]
    pub account_id: Uuid,
    pub name: String,
}

#[derive(chekov::Command, Serialize, Deserialize)]
#[command(event = "gift_card::GiftCardCreated", aggregate = "GiftCard")]
pub struct CreateGiftCard {
    #[command(identifier)]
    pub gift_card_id: Uuid,
    pub name: String,
    pub price: i64,
    pub count: usize,
}

#[derive(Clone, chekov::Command, Deserialize, Serialize)]
#[command(event = "order::OrderCreated", aggregate = "Order")]
pub struct CreateOrder {
    #[command(identifier)]
    pub order_id: Uuid,
    pub account_id: Uuid,
}

#[derive(Clone, chekov::Command, Deserialize, Serialize)]
#[command(event = "order::GiftCardAdded", aggregate = "Order")]
pub struct AddGiftCardToOrder {
    #[command(identifier)]
    pub order_id: Uuid,
    pub gift_card_id: Uuid,
    pub amount: usize,
    pub price: i64,
}

#[derive(Clone, chekov::Command, Deserialize, Serialize)]
#[command(event = "order::OrderValidated", aggregate = "Order")]
pub struct ValidateOrder {
    #[command(identifier)]
    pub order_id: Uuid,
}

#[derive(Clone, chekov::Command, Deserialize, Serialize)]
#[command(event = "order::OrderCanceled", aggregate = "Order")]
pub struct CancelOrder {
    #[command(identifier)]
    pub order_id: Uuid,
}