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
use serde::{Deserialize, Serialize};
use zino_core::{database::Model, datetime::DateTime, request::Validation, Map, Uuid};
use zino_derive::Schema;
#[derive(Debug, Clone, Default, Serialize, Deserialize, Schema)]
#[serde(rename_all = "snake_case")]
#[serde(default)]
pub struct Dataset {
id: Uuid,
#[schema(not_null, index = "text")]
name: String,
#[schema(default = "Dataset::model_namespace", index = "hash")]
namespace: String,
#[schema(default = "internal")]
visibility: String,
#[schema(default = "active", index = "hash")]
status: String,
#[schema(index = "text")]
description: String,
project_id: Uuid, task_id: Option<Uuid>, valid_from: DateTime,
expires_at: DateTime,
#[schema(index = "gin")]
tags: Vec<Uuid>, content: Map,
metrics: Map,
extras: Map,
manager_id: Uuid, maintainer_id: Uuid, #[schema(index = "btree")]
created_at: DateTime,
#[schema(index = "btree")]
updated_at: DateTime,
version: u64,
edition: u32,
}
impl Model for Dataset {
fn new() -> Self {
Self {
id: Uuid::new_v4(),
..Self::default()
}
}
fn read_map(&mut self, data: Map) -> Validation {
let mut validation = Validation::new();
if let Some(result) = Validation::parse_uuid(data.get("id")) {
match result {
Ok(id) => self.id = id,
Err(err) => validation.record_fail("id", err),
}
}
if let Some(name) = Validation::parse_string(data.get("name")) {
self.name = name;
}
if self.name.is_empty() {
validation.record_fail("name", "should be nonempty");
}
validation
}
}