refactor(repo): remove release types (inlined)
zhenyi committed
Deleted lib/repo/features/release/types.rs lib/repo/features/release/types.rs +0 −130
@@ -1,130 +0,0 @@
1use db::repo::repo_release as release_entity;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use time::format_description::well_known::Rfc3339;
5use utoipa::{IntoParams, ToSchema};
6use uuid::Uuid;
7
8fn fmt_ts(ts: OffsetDateTime) -> String {
9 ts.format(&Rfc3339).unwrap_or_default()
10}
11
12#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
13pub struct ReleaseAttachment {
14 pub id: Uuid,
15 pub name: String,
16 pub size: i64,
17 pub download_url: String,
18 pub created_at: String,
19}
20
21#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
22pub struct UserSummary {
23 pub id: Uuid,
24 pub login: String,
25 pub full_name: Option<String>,
26 pub avatar_url: Option<String>,
27}
28
29#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
30pub struct ReleaseView {
31 pub id: Uuid,
32 pub repo_id: Uuid,
33 pub tag_name: String,
34 pub target: String,
35 pub title: String,
36 pub content: Option<String>,
37 pub sha: String,
38 pub num_commits: i32,
39 pub is_draft: bool,
40 pub is_prerelease: bool,
41 pub is_tag: bool,
42 pub url: String,
43 pub html_url: String,
44 pub tarball_url: String,
45 pub zipball_url: String,
46 pub upload_url: String,
47 pub publisher: UserSummary,
48 pub attachments: Vec<ReleaseAttachment>,
49 pub created_at: String,
50 pub updated_at: String,
51}
52
53impl From<release_entity::Model> for ReleaseView {
54 fn from(m: release_entity::Model) -> Self {
55 let repo_id = m.repo_id;
56 let id = m.id;
57 let tag_name = m.tag_name.clone();
58 Self {
59 id,
60 repo_id,
61 tag_name: m.tag_name,
62 target: m.target,
63 title: m.title,
64 content: m.content,
65 sha: m.sha,
66 num_commits: m.num_commits,
67 is_draft: m.is_draft,
68 is_prerelease: m.is_prerelease,
69 is_tag: m.is_tag,
70 url: format!("/repo/{repo_id}/releases/{id}"),
71 html_url: format!("/repo/{repo_id}/releases/{id}"),
72 tarball_url: format!("/repo/{repo_id}/archive/tarball/{tag_name}"),
73 zipball_url: format!("/repo/{repo_id}/archive/zipball/{tag_name}"),
74 upload_url: format!("/repo/{repo_id}/releases/{id}/assets"),
75 publisher: UserSummary {
76 id: m.publisher_id,
77 login: m.publisher_name.clone(),
78 full_name: Some(m.publisher_name),
79 avatar_url: None,
80 },
81 attachments: Vec::new(),
82 created_at: fmt_ts(m.created_at),
83 updated_at: fmt_ts(m.updated_at),
84 }
85 }
86}
87
88#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
89pub struct ReleasePage {
90 pub items: Vec<ReleaseView>,
91 pub total: i64,
92}
93
94#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
95pub struct CreateReleaseOption {
96 pub tag_name: String,
97 pub target: Option<String>,
98 pub title: String,
99 pub content: Option<String>,
100 pub tag_message: Option<String>,
101 pub is_draft: Option<bool>,
102 pub is_prerelease: Option<bool>,
103}
104
105#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
106pub struct EditReleaseOption {
107 pub tag_name: Option<String>,
108 pub target: Option<String>,
109 pub title: Option<String>,
110 pub content: Option<Option<String>>,
111 pub is_draft: Option<bool>,
112 pub is_prerelease: Option<bool>,
113}
114
115#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
116pub struct PublisherSummary {
117 pub id: Uuid,
118 pub name: String,
119 pub login: String,
120 pub email: Option<String>,
121 pub avatar_url: Option<String>,
122}
123
124#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
125pub struct ListReleaseQuery {
126 pub draft: Option<bool>,
127 pub prerelease: Option<bool>,
128 pub page: Option<u64>,
129 pub limit: Option<u64>,
130}