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
59
60
61
62
63
64
65
66
67
68
69
70
use crate::database::conn::ConnectionParams;
use serde::{Deserialize, Serialize};
#[derive(Debug, Deserialize, Serialize)]
pub struct ProjectSummary {
pub name: String,
#[serde(rename = "connectionParams")]
pub connection_params: ConnectionParams
}
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ProjectDescription {
pub key: String,
pub name: String,
pub server: String,
pub port: Option<i32>,
pub database: String,
pub user: String,
pub tls: bool
}
#[derive(derive_more::Constructor, Debug, Serialize)]
pub struct Project {
key: String,
name: String,
connection_params: ConnectionParams
}
impl Project {
pub fn to_summary(&self) -> ProjectSummary {
ProjectSummary {
name: self.name.clone(),
connection_params: self.connection_params.clone()
}
}
pub fn to_description(&self) -> ProjectDescription {
ProjectDescription {
key: self.key.clone(),
name: self.name.clone(),
server: self.connection_params.server().clone(),
port: *self.connection_params.port(),
database: self.connection_params.database().clone(),
user: self.connection_params.user().clone(),
tls: self.connection_params.tls()
}
}
pub fn key(&self) -> &String {
&self.key
}
pub fn name(&self) -> &String {
&self.name
}
pub fn conn(&self) -> &ConnectionParams {
&self.connection_params
}
}
impl From<(String, ProjectSummary)> for Project {
fn from(item: (String, ProjectSummary)) -> Self {
Project::new(item.0, item.1.name, item.1.connection_params)
}
}