Skip to main content

max / makenotwork

3.6 KB · 112 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 }
41
42 /// A flattened project row returned by the discover projects query.
43 #[derive(Debug, Clone, FromRow)]
44 #[allow(dead_code)] // Fields populated by sqlx query, read during type conversion
45 pub struct DbDiscoverProjectRow {
46 /// Project URL slug.
47 pub slug: Slug,
48 /// Project title.
49 pub title: String,
50 /// Project description.
51 pub description: Option<String>,
52 /// Project category.
53 pub project_type: super::super::ProjectType,
54 /// When the project was created.
55 pub created_at: DateTime<Utc>,
56 /// Creator's username (joined from users).
57 pub username: Username,
58 /// Number of public items in this project.
59 pub item_count: i64,
60 /// Trigram similarity score (set when searching, `None` otherwise).
61 pub match_score: Option<f32>,
62 /// Category name (joined from project_categories), or NULL if uncategorized.
63 pub category_name: Option<String>,
64 /// Category slug (joined from project_categories), or NULL if uncategorized.
65 pub category_slug: Option<String>,
66 }
67
68 /// An item_type value paired with the number of matching items.
69 #[derive(Debug, Clone, FromRow)]
70 pub struct DbItemTypeCount {
71 /// The item_type category value.
72 pub category: String,
73 /// Number of matching items of this type.
74 pub count: i64,
75 }
76
77 /// Bucketed item counts by price range for the discover page sidebar.
78 #[derive(Debug, Clone, Default)]
79 pub struct DbPriceRangeCounts {
80 /// Items priced at $0.
81 pub free: i64,
82 /// Items priced $0.01 -- $24.99.
83 pub under_25: i64,
84 /// Items priced $25.00 -- $49.99.
85 pub range_25_50: i64,
86 /// Items priced $50.00 -- $99.99.
87 pub range_50_100: i64,
88 /// Items priced $100.00 and above.
89 pub over_100: i64,
90 }
91
92 /// A user-defined external link shown on their profile.
93 #[derive(Debug, Clone, FromRow, Serialize)]
94 pub struct DbCustomLink {
95 /// Database primary key.
96 pub id: CustomLinkId,
97 /// Owning user's ID.
98 pub user_id: UserId,
99 /// Full URL.
100 pub url: String,
101 /// Display title for the link.
102 pub title: String,
103 /// Optional description shown below the title.
104 pub description: Option<String>,
105 /// Position in the user's link list.
106 pub sort_order: i32,
107 /// When the link was created.
108 pub created_at: DateTime<Utc>,
109 /// When the link was last modified.
110 pub updated_at: DateTime<Utc>,
111 }
112