Skip to main content

max / makenotwork

3.2 KB · 109 lines History Blame Raw
1 //! Report, collection, and session models for admin features.
2
3 use chrono::{DateTime, Utc};
4 use sqlx::FromRow;
5 use uuid::Uuid;
6
7 use super::super::id_types::*;
8 use super::super::validated_types::*;
9
10 // ── Report models ──
11
12 /// A user-submitted report against a project or item.
13 #[derive(Debug, Clone, FromRow)]
14 pub struct DbReport {
15 pub id: ReportId,
16 pub reporter_user_id: UserId,
17 pub target_type: super::super::ReportTargetType,
18 pub target_id: Uuid,
19 pub report_type: super::super::ReportType,
20 pub reason: String,
21 pub status: super::super::ReportStatus,
22 pub admin_notes: Option<String>,
23 pub resolved_by: Option<UserId>,
24 pub created_at: DateTime<Utc>,
25 pub resolved_at: Option<DateTime<Utc>>,
26 }
27
28 /// A report row joined with reporter, target, and owner info for admin display.
29 #[derive(Debug, Clone, FromRow)]
30 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
31 pub struct DbAdminReportRow {
32 pub id: ReportId,
33 pub reporter_username: String,
34 pub target_type: super::super::ReportTargetType,
35 pub target_title: String,
36 pub target_slug_or_id: String,
37 pub target_owner: String,
38 pub report_type: super::super::ReportType,
39 pub reason: String,
40 pub status: super::super::ReportStatus,
41 pub admin_notes: Option<String>,
42 pub created_at: DateTime<Utc>,
43 pub resolved_at: Option<DateTime<Utc>>,
44 }
45
46 /// Aggregate counts of reports by status.
47 #[derive(Debug, Clone, FromRow)]
48 pub struct DbReportStats {
49 pub open: i64,
50 pub resolved: i64,
51 pub dismissed: i64,
52 }
53
54 // ── Collection models ──
55
56 /// A user-curated collection of items (playlist, reading list, bundle).
57 #[derive(Debug, Clone, FromRow)]
58 pub struct DbCollection {
59 pub id: CollectionId,
60 pub user_id: UserId,
61 pub slug: Slug,
62 pub title: String,
63 pub description: Option<String>,
64 pub is_public: bool,
65 pub created_at: DateTime<Utc>,
66 pub updated_at: DateTime<Utc>,
67 }
68
69 /// A collection with its item count, for listing views.
70 #[derive(Debug, Clone, FromRow)]
71 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
72 pub struct DbCollectionWithCount {
73 pub id: CollectionId,
74 pub user_id: UserId,
75 pub slug: Slug,
76 pub title: String,
77 pub description: Option<String>,
78 pub is_public: bool,
79 pub created_at: DateTime<Utc>,
80 pub updated_at: DateTime<Utc>,
81 pub item_count: i64,
82 }
83
84 /// An item in a collection, joined with item/project/user data for display.
85 #[derive(Debug, Clone, FromRow)]
86 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
87 pub struct DbCollectionItemRow {
88 pub item_id: ItemId,
89 pub title: String,
90 pub description: Option<String>,
91 pub price_cents: i32,
92 pub item_type: super::super::ItemType,
93 pub username: Username,
94 pub project_title: String,
95 pub position: i32,
96 pub added_at: DateTime<Utc>,
97 }
98
99 /// A tracked login session for remote revocation.
100 #[derive(Debug, Clone, FromRow)]
101 pub struct DbUserSession {
102 pub id: UserSessionId,
103 pub user_id: UserId,
104 pub created_at: DateTime<Utc>,
105 pub last_active_at: DateTime<Utc>,
106 pub user_agent: Option<String>,
107 pub ip_address: Option<String>,
108 }
109