Skip to main content

max / makenotwork

3.3 KB · 111 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::{CollectionId, ItemId, ReportId, UserId, UserSessionId};
8 use super::super::validated_types::{Slug, Username};
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 target_custom_html: Option<String>,
39 pub target_custom_css: Option<String>,
40 pub report_type: super::super::ReportType,
41 pub reason: String,
42 pub status: super::super::ReportStatus,
43 pub admin_notes: Option<String>,
44 pub created_at: DateTime<Utc>,
45 pub resolved_at: Option<DateTime<Utc>>,
46 }
47
48 /// Aggregate counts of reports by status.
49 #[derive(Debug, Clone, FromRow)]
50 pub struct DbReportStats {
51 pub open: i64,
52 pub resolved: i64,
53 pub dismissed: i64,
54 }
55
56 // ── Collection models ──
57
58 /// A user-curated collection of items (playlist, reading list, bundle).
59 #[derive(Debug, Clone, FromRow)]
60 pub struct DbCollection {
61 pub id: CollectionId,
62 pub user_id: UserId,
63 pub slug: Slug,
64 pub title: String,
65 pub description: Option<String>,
66 pub is_public: bool,
67 pub created_at: DateTime<Utc>,
68 pub updated_at: DateTime<Utc>,
69 }
70
71 /// A collection with its item count, for listing views.
72 #[derive(Debug, Clone, FromRow)]
73 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
74 pub struct DbCollectionWithCount {
75 pub id: CollectionId,
76 pub user_id: UserId,
77 pub slug: Slug,
78 pub title: String,
79 pub description: Option<String>,
80 pub is_public: bool,
81 pub created_at: DateTime<Utc>,
82 pub updated_at: DateTime<Utc>,
83 pub item_count: i64,
84 }
85
86 /// An item in a collection, joined with item/project/user data for display.
87 #[derive(Debug, Clone, FromRow)]
88 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
89 pub struct DbCollectionItemRow {
90 pub item_id: ItemId,
91 pub title: String,
92 pub description: Option<String>,
93 pub price_cents: i32,
94 pub item_type: super::super::ItemType,
95 pub username: Username,
96 pub project_title: String,
97 pub position: i32,
98 pub added_at: DateTime<Utc>,
99 }
100
101 /// A tracked login session for remote revocation.
102 #[derive(Debug, Clone, FromRow)]
103 pub struct DbUserSession {
104 pub id: UserSessionId,
105 pub user_id: UserId,
106 pub created_at: DateTime<Utc>,
107 pub last_active_at: DateTime<Utc>,
108 pub user_agent: Option<String>,
109 pub ip_address: Option<String>,
110 }
111