Skip to main content

max / makenotwork

3.7 KB · 114 lines History Blame Raw
1 //! Discover page query 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 flattened item row returned by the discover/search query.
11 #[derive(Debug, Clone, FromRow)]
12 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
13 pub struct DbDiscoverItemRow {
14 /// Item primary key.
15 pub id: ItemId,
16 /// Item title.
17 pub title: String,
18 /// Item description.
19 pub description: Option<String>,
20 /// Price in cents.
21 pub price_cents: i32,
22 /// Content type.
23 pub item_type: super::super::ItemType,
24 /// When the item was created.
25 pub created_at: DateTime<Utc>,
26 /// Creator's username (joined from users).
27 pub username: Username,
28 /// Parent project title (joined from projects).
29 pub project_title: String,
30 /// Number of completed purchases.
31 pub sales_count: i64,
32 /// Primary tag name (joined from item_tags/tags), or NULL if no primary tag.
33 pub primary_tag_name: Option<String>,
34 /// Whether PWYW pricing is enabled.
35 pub pwyw_enabled: bool,
36 /// Minimum price in cents when PWYW is enabled.
37 pub pwyw_min_cents: Option<i32>,
38 /// Trigram similarity score (set when searching, `None` otherwise).
39 pub match_score: Option<f32>,
40 /// AI disclosure tier — drives the badge / row label on Discover.
41 pub ai_tier: super::super::AiTier,
42 }
43
44 /// A flattened project row returned by the discover projects query.
45 #[derive(Debug, Clone, FromRow)]
46 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
47 pub struct DbDiscoverProjectRow {
48 /// Project URL slug.
49 pub slug: Slug,
50 /// Project title.
51 pub title: String,
52 /// Project description.
53 pub description: Option<String>,
54 /// Project category.
55 pub project_type: super::super::ProjectType,
56 /// When the project was created.
57 pub created_at: DateTime<Utc>,
58 /// Creator's username (joined from users).
59 pub username: Username,
60 /// Number of public items in this project.
61 pub item_count: i64,
62 /// Trigram similarity score (set when searching, `None` otherwise).
63 pub match_score: Option<f32>,
64 /// Category name (joined from project_categories), or NULL if uncategorized.
65 pub category_name: Option<String>,
66 /// Category slug (joined from project_categories), or NULL if uncategorized.
67 pub category_slug: Option<String>,
68 }
69
70 /// An item_type value paired with the number of matching items.
71 #[derive(Debug, Clone, FromRow)]
72 pub struct DbItemTypeCount {
73 /// The item_type category value.
74 pub category: String,
75 /// Number of matching items of this type.
76 pub count: i64,
77 }
78
79 /// Bucketed item counts by price range for the discover page sidebar.
80 #[derive(Debug, Clone, Default)]
81 pub struct DbPriceRangeCounts {
82 /// Items priced at $0.
83 pub free: i64,
84 /// Items priced $0.01 -- $24.99.
85 pub under_25: i64,
86 /// Items priced $25.00 -- $49.99.
87 pub range_25_50: i64,
88 /// Items priced $50.00 -- $99.99.
89 pub range_50_100: i64,
90 /// Items priced $100.00 and above.
91 pub over_100: i64,
92 }
93
94 /// A user-defined external link shown on their profile.
95 #[derive(Debug, Clone, FromRow, Serialize)]
96 pub struct DbCustomLink {
97 /// Database primary key.
98 pub id: CustomLinkId,
99 /// Owning user's ID.
100 pub user_id: UserId,
101 /// Full URL.
102 pub url: String,
103 /// Display title for the link.
104 pub title: String,
105 /// Optional description shown below the title.
106 pub description: Option<String>,
107 /// Position in the user's link list.
108 pub sort_order: i32,
109 /// When the link was created.
110 pub created_at: DateTime<Utc>,
111 /// When the link was last modified.
112 pub updated_at: DateTime<Utc>,
113 }
114