forked from Txio-labs/txio
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest.rs
More file actions
57 lines (48 loc) · 1.41 KB
/
Copy pathrequest.rs
File metadata and controls
57 lines (48 loc) · 1.41 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
47
48
49
50
51
52
53
54
55
56
57
use serde::{Deserialize, Serialize};
use mongodb::bson::oid::ObjectId;
use chrono::{DateTime, Utc};
use validator::Validate;
#[derive(Debug, Serialize, Deserialize, Validate, Clone)]
pub struct SavedRequest {
#[serde(rename = "_id", skip_serializing_if = "Option::is_none")]
pub id: Option<ObjectId>,
pub collection_id: ObjectId,
pub user_id: ObjectId,
#[validate(length(min = 1, message = "Name cannot be empty"))]
pub name: String,
#[validate(length(min = 1, message = "Method cannot be empty"))]
pub method: String,
pub params: serde_json::Value,
pub network: Option<String>,
pub rpc_url: Option<String>,
pub last_response: Option<serde_json::Value>,
pub last_executed_at: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}
impl SavedRequest {
pub fn new(
collection_id: ObjectId,
user_id: ObjectId,
name: String,
method: String,
params: serde_json::Value,
network: Option<String>,
rpc_url: Option<String>,
) -> Self {
Self {
id: None,
collection_id,
user_id,
name,
method,
params,
network,
rpc_url,
last_response: None,
last_executed_at: None,
created_at: Utc::now(),
updated_at: Utc::now(),
}
}
}