-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathoperation.rs
More file actions
46 lines (40 loc) · 1.13 KB
/
Copy pathoperation.rs
File metadata and controls
46 lines (40 loc) · 1.13 KB
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
use chrono::{DateTime, Utc};
use derive_more::Display;
use serde::{Deserialize, Serialize};
use crate::database::content_folder;
use crate::database::torrent;
use crate::extractors::user::User;
/// Type of operation applied to the database.
#[derive(Clone, Debug, Display, Serialize, Deserialize)]
pub enum OperationType {
Create,
Update,
Delete,
}
#[derive(Clone, Debug, Display, Serialize, Deserialize)]
pub enum Table {
ContentFolder,
Torrent,
}
/// Operation applied to the database.
///
/// Will be saved as an [OperationLog].
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Operation {
ContentFolder(content_folder::ContentFolderOperation),
Torrent(torrent::TorrentOperation),
}
impl std::fmt::Display for Operation {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", serde_json::to_string(self).unwrap())
}
}
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct OperationLog {
pub user: Option<User>,
pub date: DateTime<Utc>,
pub operation: Operation,
pub operation_type: OperationType,
pub table: Table,
}