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
use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};

use moonramp_core::{chrono, serde, Hash};
use moonramp_entity::program;

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(crate = "moonramp_core::serde", rename_all = "camelCase")]
pub struct ProgramCreateRequest {
    pub name: String,
    pub version: String,
    pub url: Option<String>,
    pub description: Option<String>,
    pub data: Vec<u8>,
    pub private: bool,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(crate = "moonramp_core::serde", rename_all = "camelCase")]
pub struct ProgramUpdateRequest {
    pub name: String,
    pub version: String,
    pub url: Option<String>,
    pub description: Option<String>,
    pub data: Vec<u8>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(crate = "moonramp_core::serde", rename_all = "camelCase", untagged)]
pub enum ProgramLookupRequest {
    Hash { hash: Hash },
    Name { name: String },
}

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(crate = "moonramp_core::serde", rename_all = "camelCase")]
pub struct ProgramResponse {
    pub hash: Hash,
    pub name: String,
    pub version: String,
    pub url: Option<String>,
    pub description: Option<String>,
    pub private: bool,
    pub revision: i64,
    pub created_at: DateTime<Utc>,
}

impl From<program::Model> for ProgramResponse {
    fn from(model: program::Model) -> ProgramResponse {
        ProgramResponse {
            hash: model.hash,
            name: model.name,
            version: model.version,
            url: model.url,
            description: model.description,
            private: model.private,
            revision: model.revision,
            created_at: model.created_at,
        }
    }
}