smbcloud_model/
project.rs1use std::fmt::Display;
2
3use crate::{app_auth::AuthApp, ar_date_format};
4use chrono::{DateTime, Utc};
5use serde::{Deserialize, Serialize};
6use serde_repr::{Deserialize_repr, Serialize_repr};
7
8#[derive(Deserialize, Debug, Serialize)]
9pub struct Config {
10 pub current_project: Option<Project>,
11 pub current_auth_app: Option<AuthApp>,
12}
13
14#[derive(Deserialize, Debug, Serialize, Clone)]
15pub struct Project {
16 pub id: i32,
17 pub name: String,
18 pub repository: String,
19 pub description: Option<String>,
20 pub created_at: DateTime<Utc>,
21 pub updated_at: DateTime<Utc>,
22}
23
24impl Display for Project {
25 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
26 write!(f, "ID: {}, Name: {}", self.id, self.name,)
27 }
28}
29#[derive(Serialize, Debug)]
30pub struct ProjectCreate {
31 pub name: String,
32 pub repository: String,
33 pub description: String,
34}
35
36#[derive(Deserialize, Serialize, Debug)]
37pub struct Deployment {
38 pub id: i32,
39 pub project_id: i32,
40 pub commit_hash: String,
41 pub status: DeploymentStatus,
42 #[serde(with = "ar_date_format")]
43 pub created_at: DateTime<Utc>,
44 #[serde(with = "ar_date_format")]
45 pub updated_at: DateTime<Utc>,
46}
47
48#[derive(Deserialize, Serialize, Debug)]
49pub struct DeploymentPayload {
50 pub commit_hash: String,
51 pub status: DeploymentStatus,
52}
53
54#[derive(Deserialize_repr, Serialize_repr, Debug)]
55#[repr(u8)]
56pub enum DeploymentStatus {
57 Started = 0,
58 Failed,
59 Done,
60}
61
62#[cfg(test)]
63mod tests {
64 use super::*;
65 use serde_json::json;
66 #[test]
67 fn test_project_create() {
68 let project_create = ProjectCreate {
69 name: "test".to_owned(),
70 repository: "test".to_owned(),
71 description: "test".to_owned(),
72 };
73 let json = json!({
74 "name": "test",
75 "description": "test",
76 });
77 assert_eq!(serde_json::to_value(project_create).unwrap(), json);
78 }
79}