Skip to content
Clone

feat(project): add links types

zhenyi committed
parent c32f7bd commit bbf1d5a Browse files

1 file changed

+60 −0

Added lib/project/features/links/types.rs View lib/project/features/links/types.rs
@@ -0,0 +1,60 @@
1use db::project::project_links::ProjectLinkKind as DbKind;
2use serde::{Deserialize, Serialize};
3use time::OffsetDateTime;
4use utoipa::ToSchema;
5use uuid::Uuid;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, ToSchema)]
8#[serde(rename_all = "snake_case")]
9pub enum LinkKind {
10 Related,
11 Duplicate,
12 Blocks,
13 BlockedBy,
14}
15
16impl From<DbKind> for LinkKind {
17 fn from(k: DbKind) -> Self {
18 match k {
19 DbKind::Related => Self::Related,
20 DbKind::Duplicate => Self::Duplicate,
21 DbKind::Blocks => Self::Blocks,
22 DbKind::BlockedBy => Self::BlockedBy,
23 }
24 }
25}
26
27impl TryFrom<LinkKind> for DbKind {
28 type Error = crate::error::ProjectError;
29
30 fn try_from(k: LinkKind) -> Result<Self, Self::Error> {
31 match k {
32 LinkKind::Related => Ok(DbKind::Related),
33 LinkKind::Duplicate => Ok(DbKind::Duplicate),
34 LinkKind::Blocks => Ok(DbKind::Blocks),
35 LinkKind::BlockedBy => Ok(DbKind::BlockedBy),
36 }
37 }
38}
39
40#[derive(Debug, Clone, Deserialize, ToSchema)]
41pub struct AddLinkCmd {
42 pub related_project_id: Uuid,
43 pub kind: LinkKind,
44}
45
46#[derive(Debug, Clone, Serialize, ToSchema)]
47pub struct LinkView {
48 pub id: Uuid,
49 pub project_id: Uuid,
50 pub related_project_id: Uuid,
51 pub kind: LinkKind,
52 pub created_by: Uuid,
53 pub created_at: OffsetDateTime,
54}
55
56#[derive(Debug, Clone, Serialize, ToSchema)]
57pub struct LinkPage {
58 pub total: u64,
59 pub items: Vec<LinkView>,
60}
No newline at end of file