Skip to main content

koprogo_api/application/dto/
account_dto.rs

1// DTOs for Account API
2//
3// CREDITS: Structure inspired by Noalyss API patterns (GPL-2.0+)
4// https://gitlab.com/noalyss/noalyss
5
6use serde::{Deserialize, Serialize};
7use validator::Validate;
8
9/// Request DTO for creating a new account
10///
11/// `deny_unknown_fields` n'est pas décoratif : sans lui, un champ mal nommé
12/// est accepté puis JETÉ en silence — la requête rend 201 et la donnée
13/// n'existe pas. Sur un compte du plan comptable, ce serait une écriture
14/// qu'on croit passée.
15#[derive(Debug, Serialize, Deserialize, Validate, Clone)]
16#[serde(deny_unknown_fields)]
17pub struct CreateAccountDto {
18    #[validate(length(min = 1, max = 40, message = "Account code must be 1-40 characters"))]
19    pub code: String,
20
21    #[validate(length(min = 1, max = 255, message = "Account label must be 1-255 characters"))]
22    pub label: String,
23
24    pub parent_code: Option<String>,
25
26    pub account_type: String, // "ASSET", "LIABILITY", "EXPENSE", "REVENUE", "OFF_BALANCE"
27
28    pub direct_use: bool,
29
30    pub organization_id: String,
31}
32
33/// Request DTO for updating an existing account
34#[derive(Debug, Serialize, Deserialize, Validate, Clone)]
35pub struct UpdateAccountDto {
36    #[validate(length(min = 1, max = 255))]
37    pub label: Option<String>,
38
39    pub parent_code: Option<Option<String>>,
40
41    pub account_type: Option<String>, // "ASSET", "LIABILITY", "EXPENSE", "REVENUE", "OFF_BALANCE"
42
43    pub direct_use: Option<bool>,
44}
45
46/// Response DTO for account data
47#[derive(Debug, Serialize, Deserialize, Clone)]
48pub struct AccountResponseDto {
49    pub id: String,
50    pub code: String,
51    pub label: String,
52    pub parent_code: Option<String>,
53    pub account_type: String, // "ASSET", "LIABILITY", "EXPENSE", "REVENUE", "OFF_BALANCE"
54    pub direct_use: bool,
55    pub organization_id: String,
56    pub created_at: String,
57    pub updated_at: String,
58}
59
60/// Request DTO for seeding Belgian PCMN
61#[derive(Debug, Serialize, Deserialize, Validate, Clone)]
62pub struct SeedBelgianPcmnDto {
63    pub organization_id: String,
64}
65
66/// Response DTO for seed operation
67#[derive(Debug, Serialize, Deserialize, Clone)]
68pub struct SeedPcmnResponseDto {
69    pub accounts_created: i64,
70    pub message: String,
71}
72
73/// Query parameters for searching accounts
74#[derive(Debug, Deserialize, Clone)]
75pub struct AccountSearchQuery {
76    pub code_pattern: Option<String>,
77    pub account_type: Option<String>,
78    pub direct_use_only: Option<bool>,
79    pub parent_code: Option<String>,
80}