forked from Txio-labs/txio-backend
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollection.rs
More file actions
42 lines (35 loc) · 1.01 KB
/
Copy pathcollection.rs
File metadata and controls
42 lines (35 loc) · 1.01 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
use chrono::{DateTime, Utc};
use mongodb::bson::oid::ObjectId;
use serde::{Deserialize, Serialize};
use validator::Validate;
#[derive(Debug, Serialize, Deserialize, Validate, Clone)]
pub struct Collection {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
pub id: Option<ObjectId>,
pub user_id: ObjectId,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub workspace_id: Option<ObjectId>,
#[validate(length(min = 1, message = "Name cannot be empty"))]
pub name: String,
pub description: Option<String>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl Collection {
pub fn new(
user_id: ObjectId,
workspace_id: Option<ObjectId>,
name: String,
description: Option<String>,
) -> Self {
Self {
id: None,
user_id,
workspace_id,
name,
description,
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}