Skip to content
Clone

feat(export): add repo collab export

zhenyi committed
parent 0055aaf commit 7dcb4eb Browse files

1 file changed

+70 −0

Added lib/export/repo/collab.rs View lib/export/repo/collab.rs
@@ -0,0 +1,70 @@
1use db::repo::repo_collaborations as collab_entity;
2use db::repo::repo_collaborations::CollaborationMode;
3use serde::{Deserialize, Serialize};
4use time::OffsetDateTime;
5use time::format_description::well_known::Rfc3339;
6use utoipa::{IntoParams, ToSchema};
7use uuid::Uuid;
8
9fn fmt_ts(ts: OffsetDateTime) -> String {
10 ts.format(&Rfc3339).unwrap_or_default()
11}
12
13#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
14pub struct CollaboratorView {
15 pub id: Uuid,
16 pub repo_id: Uuid,
17 pub user_id: Uuid,
18 pub mode: String,
19 pub created_at: String,
20 pub updated_at: String,
21}
22
23impl From<collab_entity::Model> for CollaboratorView {
24 fn from(m: collab_entity::Model) -> Self {
25 Self {
26 id: m.id,
27 repo_id: m.repo_id,
28 user_id: m.user_id,
29 mode: match m.mode {
30 CollaborationMode::Read => "read".to_string(),
31 CollaborationMode::Write => "write".to_string(),
32 CollaborationMode::Admin => "admin".to_string(),
33 },
34 created_at: fmt_ts(m.created_at),
35 updated_at: fmt_ts(m.updated_at),
36 }
37 }
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
41pub struct CollaboratorPage {
42 pub items: Vec<CollaboratorView>,
43 pub total: i64,
44}
45
46#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
47pub struct AddCollaboratorOption {
48 pub permission: String,
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
52pub struct RepoCollaboratorPermission {
53 pub permission: String,
54 pub role: String,
55 pub user: UserSummary,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
59pub struct UserSummary {
60 pub id: Uuid,
61 pub name: String,
62 pub login: String,
63 pub email: Option<String>,
64}
65
66#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
67pub struct ListCollaboratorQuery {
68 pub page: Option<u64>,
69 pub limit: Option<u64>,
70}