#![allow(dead_code)]
use chrono::{DateTime, NaiveDate, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
#[sqlx(type_name = "user_role", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum UserRole {
Admin,
Manager,
Employee,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct User {
pub id: Uuid,
pub email: String,
pub display_name: String,
pub role: UserRole,
pub active: bool,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Agent {
pub id: Uuid,
pub user_id: Uuid,
pub name: String,
pub revoked_at: Option<DateTime<Utc>>,
pub last_seen_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Workday {
pub id: Uuid,
pub user_id: Uuid,
pub date: NaiveDate,
pub started_at: DateTime<Utc>,
pub ended_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Pause {
pub id: Uuid,
pub workday_id: Uuid,
pub started_at: DateTime<Utc>,
pub ended_at: Option<DateTime<Utc>>,
pub duration_seconds: Option<i32>,
pub manual: bool,
pub reason: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Task {
pub id: Uuid,
pub user_id: Uuid,
pub agent_task_id: i32,
pub agent_group_id: i32,
pub date: NaiveDate,
pub recorded_at: DateTime<Utc>,
pub name: String,
pub comment: Option<String>,
pub completeness: i16,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Tag {
pub id: Uuid,
pub user_id: Uuid,
pub name: String,
pub color: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, sqlx::Type)]
#[sqlx(type_name = "report_kind", rename_all = "lowercase")]
#[serde(rename_all = "lowercase")]
pub enum ReportKind {
Daily,
Monthly,
}
#[derive(Debug, Clone, Serialize, Deserialize, sqlx::FromRow)]
pub struct Report {
pub id: Uuid,
pub user_id: Uuid,
pub kind: ReportKind,
pub period_start: NaiveDate,
pub submitted_at: DateTime<Utc>,
pub worked_seconds: i32,
pub productivity: Option<f32>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn roles_and_report_kinds_serialize_in_lowercase() {
assert_eq!(serde_json::to_string(&UserRole::Admin).unwrap(), r#""admin""#);
assert_eq!(serde_json::to_string(&UserRole::Manager).unwrap(), r#""manager""#);
assert_eq!(serde_json::to_string(&UserRole::Employee).unwrap(), r#""employee""#);
assert_eq!(serde_json::to_string(&ReportKind::Daily).unwrap(), r#""daily""#);
assert_eq!(serde_json::to_string(&ReportKind::Monthly).unwrap(), r#""monthly""#);
}
#[test]
fn roles_round_trip_through_json() {
for role in [UserRole::Admin, UserRole::Manager, UserRole::Employee] {
let json = serde_json::to_string(&role).unwrap();
assert_eq!(serde_json::from_str::<UserRole>(&json).unwrap(), role);
}
}
}