1#![allow(dead_code)]
16
17use chrono::{DateTime, NaiveDate, Utc};
18use serde::{Deserialize, Serialize};
19use uuid::Uuid;
20
21#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
23#[sqlx(type_name = "user_role", rename_all = "lowercase")]
24#[serde(rename_all = "lowercase")]
25pub enum UserRole {
26 Admin,
28 Manager,
30 Employee,
32}
33
34#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
40pub struct User {
41 pub id: Uuid,
42 pub email: String,
43 pub display_name: String,
44 pub role: UserRole,
45 pub active: bool,
47 pub created_at: DateTime<Utc>,
48 pub updated_at: DateTime<Utc>,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
55pub struct Agent {
56 pub id: Uuid,
57 pub user_id: Uuid,
58 pub name: String,
59 pub revoked_at: Option<DateTime<Utc>>,
61 pub last_seen_at: Option<DateTime<Utc>>,
63 pub created_at: DateTime<Utc>,
64 pub updated_at: DateTime<Utc>,
65}
66
67#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
69pub struct Workday {
70 pub id: Uuid,
71 pub user_id: Uuid,
72 pub date: NaiveDate,
75 pub started_at: DateTime<Utc>,
76 pub ended_at: Option<DateTime<Utc>>,
78 pub created_at: DateTime<Utc>,
79 pub updated_at: DateTime<Utc>,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
84pub struct Pause {
85 pub id: Uuid,
86 pub workday_id: Uuid,
87 pub started_at: DateTime<Utc>,
88 pub ended_at: Option<DateTime<Utc>>,
90 pub duration_seconds: Option<i32>,
93 pub manual: bool,
96 pub reason: Option<String>,
97 pub created_at: DateTime<Utc>,
98 pub updated_at: DateTime<Utc>,
99}
100
101#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
103pub struct Task {
104 pub id: Uuid,
105 pub user_id: Uuid,
106 pub agent_task_id: i32,
108 pub agent_group_id: i32,
110 pub date: NaiveDate,
112 pub recorded_at: DateTime<Utc>,
113 pub name: String,
114 pub comment: Option<String>,
115 pub completeness: i16,
117 pub created_at: DateTime<Utc>,
118 pub updated_at: DateTime<Utc>,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
123pub struct Tag {
124 pub id: Uuid,
125 pub user_id: Uuid,
126 pub name: String,
127 pub color: Option<String>,
128 pub created_at: DateTime<Utc>,
129 pub updated_at: DateTime<Utc>,
130}
131
132#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
134#[sqlx(type_name = "report_kind", rename_all = "lowercase")]
135#[serde(rename_all = "lowercase")]
136pub enum ReportKind {
137 Daily,
138 Monthly,
139}
140
141#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
147pub struct Report {
148 pub id: Uuid,
149 pub user_id: Uuid,
150 pub kind: ReportKind,
151 pub period_start: NaiveDate,
153 pub submitted_at: DateTime<Utc>,
154 pub worked_seconds: i32,
155 pub productivity: Option<f32>,
157 pub created_at: DateTime<Utc>,
158 pub updated_at: DateTime<Utc>,
159}
160
161#[cfg(test)]
162mod tests {
163 use super::*;
164
165 #[test]
169 fn roles_and_report_kinds_serialize_in_lowercase() {
170 assert_eq!(serde_json::to_string(&UserRole::Admin).unwrap(), r#""admin""#);
171 assert_eq!(serde_json::to_string(&UserRole::Manager).unwrap(), r#""manager""#);
172 assert_eq!(serde_json::to_string(&UserRole::Employee).unwrap(), r#""employee""#);
173 assert_eq!(serde_json::to_string(&ReportKind::Daily).unwrap(), r#""daily""#);
174 assert_eq!(serde_json::to_string(&ReportKind::Monthly).unwrap(), r#""monthly""#);
175 }
176
177 #[test]
178 fn roles_round_trip_through_json() {
179 for role in [UserRole::Admin, UserRole::Manager, UserRole::Employee] {
180 let json = serde_json::to_string(&role).unwrap();
181 assert_eq!(serde_json::from_str::<UserRole>(&json).unwrap(), role);
182 }
183 }
184}