Skip to main content

max / makenotwork

4.2 KB · 120 lines History Blame Raw
1 //! Project and git repository models.
2
3 use chrono::{DateTime, Utc};
4 use serde::Serialize;
5 use sqlx::FromRow;
6
7 use super::super::id_types::*;
8 use super::super::validated_types::*;
9
10 /// A creator's project (collection of items).
11 #[derive(Debug, Clone, FromRow, Serialize)]
12 pub struct DbProject {
13 /// Database primary key.
14 pub id: ProjectId,
15 /// Owning user's ID.
16 pub user_id: UserId,
17 /// URL-safe slug unique per user.
18 pub slug: Slug,
19 /// Display title.
20 pub title: String,
21 /// Optional longer description.
22 pub description: Option<String>,
23 /// Category type (e.g. software, music, blog).
24 pub project_type: super::super::ProjectType,
25 /// URL to the project's cover image.
26 pub cover_image_url: Option<String>,
27 /// Whether this project is publicly visible.
28 pub is_public: bool,
29 /// When the project was created.
30 pub created_at: DateTime<Utc>,
31 /// When the project was last modified.
32 pub updated_at: DateTime<Utc>,
33 /// Generation counter for ETag-based HTTP caching. Bumped on any project-visible write.
34 pub cache_generation: i64,
35 /// Linked MT community ID (None if not yet provisioned or MT unavailable).
36 pub mt_community_id: Option<uuid::Uuid>,
37 /// Platform features enabled for this project (e.g. audio, blog, downloads).
38 pub features: Vec<String>,
39 /// Pricing model: free, buy_once, pwyw, or subscription.
40 pub pricing_model: super::super::PricingKind,
41 /// Price in cents (for buy_once); 0 for free projects.
42 pub price_cents: i32,
43 /// Minimum price in cents when PWYW is enabled (floor).
44 pub pwyw_min_cents: Option<i32>,
45 /// Whether this project requires license verification (phone-home) on content access.
46 pub license_verification_enabled: bool,
47 /// AI content tier: handmade, assisted, or generated.
48 pub ai_tier: super::super::AiTier,
49 /// Required disclosure text when ai_tier is assisted.
50 pub ai_disclosure: Option<String>,
51 }
52
53 /// A git repository tracked on disk, optionally linked to a project.
54 #[derive(Debug, Clone, FromRow, Serialize)]
55 pub struct DbGitRepo {
56 /// Database primary key.
57 pub id: GitRepoId,
58 /// Owning user's ID.
59 pub user_id: UserId,
60 /// Bare repository name (no path separators).
61 pub name: String,
62 /// Linked project (many repos can link to one project).
63 pub project_id: Option<ProjectId>,
64 /// When the repo was registered.
65 pub created_at: DateTime<Utc>,
66 /// Visibility: public, unlisted, or private.
67 pub visibility: super::super::Visibility,
68 /// Short description of the repository (editable via settings).
69 pub description: String,
70 }
71
72 /// A project row with an aggregated public item count (avoids N+1 queries).
73 #[derive(Debug, Clone, FromRow)]
74 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
75 pub struct DbProjectWithItemCount {
76 /// Database primary key.
77 pub id: ProjectId,
78 /// Owning user's ID.
79 pub user_id: UserId,
80 /// URL-safe slug unique per user.
81 pub slug: Slug,
82 /// Display title.
83 pub title: String,
84 /// Optional longer description.
85 pub description: Option<String>,
86 /// Category type.
87 pub project_type: super::super::ProjectType,
88 /// URL to the project's cover image.
89 pub cover_image_url: Option<String>,
90 /// Whether this project is publicly visible.
91 pub is_public: bool,
92 /// When the project was created.
93 pub created_at: DateTime<Utc>,
94 /// When the project was last modified.
95 pub updated_at: DateTime<Utc>,
96 /// Number of public items in this project.
97 pub item_count: i64,
98 }
99
100 /// A tabbed content section within a project.
101 #[derive(Debug, Clone, FromRow, Serialize)]
102 pub struct DbProjectSection {
103 /// Database primary key.
104 pub id: ProjectSectionId,
105 /// Parent project ID.
106 pub project_id: ProjectId,
107 /// Section tab title.
108 pub title: String,
109 /// URL-safe slug (unique per project).
110 pub slug: String,
111 /// Markdown body content.
112 pub body: String,
113 /// Display order among sibling sections.
114 pub sort_order: i32,
115 /// When this section was created.
116 pub created_at: DateTime<Utc>,
117 /// When this section was last modified.
118 pub updated_at: DateTime<Utc>,
119 }
120