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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//! The database models.
use std::fmt::{Display, Formatter, Result as FmtResult};
use chrono::NaiveDate;
use priority::Priority;
use schema::{tasks, users};
/// A task.
#[derive(Clone, Debug, Queryable)]
pub struct Task {
/// The task's database ID.
pub id: i32,
/// The name of the task.
pub name: String,
/// The creation date of the task.
pub create_date: NaiveDate,
/// The due date of the task.
pub due_date: Option<NaiveDate>,
/// The priority of the task.
pub priority: Priority,
/// The ID of the user the task is assigned to.
pub user_id: i32,
/// Whether the task is completed or not.
pub done: bool,
}
/// A user.
#[derive(Clone, Debug, Queryable)]
pub struct User {
/// The user's database ID.
pub id: i32,
/// The user's ID on Slack, for example `U7RD06U1G`.
pub slack_id: String,
/// The user's name. This is essentially a comment field, and may be
/// ignored.
pub name: Option<String>,
}
impl Display for User {
fn fmt(&self, fmt: &mut Formatter) -> FmtResult {
if let Some(name) = self.name.as_ref() {
write!(fmt, "{} ({})", name, self.slack_id)
} else {
write!(fmt, "{}", self.slack_id)
}
}
}
/// A task to be added to the database.
#[derive(Debug, Insertable)]
#[table_name = "tasks"]
pub(crate) struct NewTask<'a> {
/// The name of the task.
pub name: &'a str,
/// The due date of the task.
pub due_date: Option<NaiveDate>,
/// The priority of the task.
pub priority: Priority,
/// The ID of the user the task is assigned to.
pub user_id: i32,
}
/// A user to be added to the database.
#[derive(Debug, Insertable)]
#[table_name = "users"]
pub(crate) struct NewUser<'a> {
/// The user's ID on Slack, for example `U7RD06U1G`.
pub slack_id: &'a str,
/// The user's name. This is essentially a comment field, and may be
/// ignored.
pub name: Option<&'a str>,
}