refactor(issues): remove issue_reaction types (inlined)
zhenyi committed
Deleted lib/issues/features/issue_reaction/types.rs lib/issues/features/issue_reaction/types.rs +0 −67
@@ -1,67 +0,0 @@
1use db::issue::issue_reactions as reaction_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, Copy, Serialize, Deserialize, ToSchema, PartialEq, Eq)]
13#[serde(rename_all = "snake_case")]
14pub enum ReactionScope {
15 Issue,
16 Comment,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
20pub struct ReactionView {
21 pub id: Uuid,
22 pub scope: ReactionScope,
23 pub target_id: Uuid,
24 pub user_id: Uuid,
25 pub emoji: String,
26 pub created_at: String,
27}
28
29impl From<reaction_entity::Model> for ReactionView {
30 fn from(m: reaction_entity::Model) -> Self {
31 let scope = if m.comment_id.is_some() {
32 ReactionScope::Comment
33 } else {
34 ReactionScope::Issue
35 };
36 let target_id = m.comment_id.unwrap_or_else(|| {
37 m.issue_id
38 .expect("reaction must belong to either issue or comment")
39 });
40 Self {
41 id: m.id,
42 scope,
43 target_id,
44 user_id: m.user_id,
45 emoji: m.emoji,
46 created_at: fmt_ts(m.created_at),
47 }
48 }
49}
50
51#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
52pub struct ReactionAggView {
53 pub emoji: String,
54 pub count: i64,
55 pub user_ids: Vec<Uuid>,
56}
57
58#[derive(Debug, Clone, Serialize, Deserialize, ToSchema)]
59pub struct CreateReactionOption {
60 pub emoji: String,
61}
62
63#[derive(Debug, Clone, Serialize, Deserialize, ToSchema, IntoParams)]
64pub struct ListReactionQuery {
65 pub limit: Option<u64>,
66 pub offset: Option<u64>,
67}
No newline at end of file