feat(export): add space roles export
zhenyi committed
Added lib/export/space/roles.rs lib/export/space/roles.rs +85 −0 View lib/export/space/roles.rs
@@ -0,0 +1,85 @@
1use db::space::space_roles as role_entity;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use time::format_description::well_known::Rfc3339;
5use utoipa::ToSchema;
6use uuid::Uuid;
7
8fn fmt_ts(ts: OffsetDateTime) -> String {
9 ts.format(&Rfc3339).unwrap_or_default()
10}
11
12fn fmt_ts_opt(ts: Option<OffsetDateTime>) -> Option<String> {
13 ts.map(fmt_ts)
14}
15
16#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
17pub struct RoleView {
18 pub id: Uuid,
19 pub space_id: Uuid,
20 pub name: String,
21 pub position: i64,
22 pub color: String,
23 pub unicode_emoji: Option<String>,
24 pub icon_hash: Option<String>,
25 pub version: i32,
26 pub created_at: String,
27 pub updated_at: Option<String>,
28 pub created_by: Uuid,
29 pub permissions: Vec<String>,
30}
31
32impl From<role_entity::Model> for RoleView {
33 fn from(r: role_entity::Model) -> Self {
34 Self {
35 id: r.id,
36 space_id: r.space_id,
37 name: r.name,
38 position: r.position,
39 color: r.color,
40 unicode_emoji: r.unicode_emoji,
41 icon_hash: r.icon_hash,
42 version: r.version,
43 created_at: fmt_ts(r.created_at),
44 updated_at: fmt_ts_opt(r.updated_at),
45 created_by: r.created_by,
46 permissions: Vec::new(),
47 }
48 }
49}
50
51#[derive(Debug, Clone, Deserialize, ToSchema)]
52pub struct CreateRoleCmd {
53 pub name: String,
54 pub color: Option<String>,
55 pub unicode_emoji: Option<String>,
56 pub icon_hash: Option<String>,
57 pub position: Option<i64>,
58 pub permissions: Vec<String>,
59}
60
61#[derive(Debug, Clone, Deserialize, ToSchema)]
62pub struct UpdateRoleCmd {
63 pub name: Option<String>,
64 pub color: Option<String>,
65 pub unicode_emoji: Option<Option<String>>,
66 pub icon_hash: Option<Option<String>>,
67 pub position: Option<i64>,
68 pub permissions: Option<Vec<String>>,
69}
70
71#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
72pub struct RolePage {
73 pub items: Vec<RoleView>,
74 pub total: i64,
75}
76
77#[derive(Debug, Clone, Deserialize, ToSchema)]
78pub struct AssignRoleCmd {
79 pub role_id: Uuid,
80}
81
82#[derive(Debug, Clone, Deserialize, ToSchema)]
83pub struct UnassignRoleCmd {
84 pub role_id: Uuid,
85}
No newline at end of file