Skip to main content

max / makenotwork

2.6 KB · 86 lines History Blame Raw
1 //! Tip, project member, and revenue split models.
2
3 use chrono::{DateTime, Utc};
4 use serde::Serialize;
5 use sqlx::FromRow;
6
7 use super::super::id_types::{
8 ProjectId, ProjectMemberId, RevenueSplitId, TipId, TransactionId, UserId,
9 };
10 use super::super::validated_types::{Cents, StripeAccountId};
11
12 /// A one-time tip from a fan to a creator.
13 #[derive(Debug, Clone, FromRow, Serialize)]
14 pub struct DbTip {
15 pub id: TipId,
16 pub tipper_id: UserId,
17 pub recipient_id: UserId,
18 pub project_id: Option<ProjectId>,
19 pub amount_cents: Cents,
20 pub message: Option<String>,
21 pub status: super::super::TransactionStatus,
22 pub stripe_payment_intent_id: Option<String>,
23 pub stripe_checkout_session_id: Option<String>,
24 pub stripe_transfer_group: Option<String>,
25 pub created_at: DateTime<Utc>,
26 pub completed_at: Option<DateTime<Utc>>,
27 }
28
29 /// A member of a multi-author project with a revenue split.
30 #[derive(Debug, Clone, FromRow, Serialize)]
31 pub struct DbProjectMember {
32 pub id: ProjectMemberId,
33 pub project_id: ProjectId,
34 pub user_id: UserId,
35 pub role: super::super::ProjectRole,
36 pub split_percent: i16,
37 pub added_at: DateTime<Utc>,
38 pub added_by: UserId,
39 }
40
41 /// A revenue split record for a completed payment.
42 #[derive(Debug, Clone, FromRow, Serialize)]
43 pub struct DbRevenueSplit {
44 pub id: RevenueSplitId,
45 pub tip_id: Option<TipId>,
46 pub transaction_id: Option<TransactionId>,
47 pub recipient_id: UserId,
48 pub amount_cents: Cents,
49 pub split_percent: i16,
50 pub stripe_transfer_id: Option<String>,
51 pub status: super::super::TransactionStatus,
52 pub created_at: DateTime<Utc>,
53 pub completed_at: Option<DateTime<Utc>>,
54 }
55
56 /// Tip with tipper username for display in dashboard/history.
57 #[derive(Debug, Clone, FromRow)]
58 pub struct DbTipWithUser {
59 pub id: TipId,
60 pub tipper_id: UserId,
61 pub recipient_id: UserId,
62 pub project_id: Option<ProjectId>,
63 pub amount_cents: Cents,
64 pub message: Option<String>,
65 pub status: super::super::TransactionStatus,
66 pub created_at: DateTime<Utc>,
67 pub completed_at: Option<DateTime<Utc>>,
68 pub tipper_username: String,
69 pub tipper_display_name: Option<String>,
70 }
71
72 /// Project member with user info for display.
73 #[derive(Debug, Clone, FromRow)]
74 pub struct DbProjectMemberWithUser {
75 pub id: ProjectMemberId,
76 pub project_id: ProjectId,
77 pub user_id: UserId,
78 pub role: super::super::ProjectRole,
79 pub split_percent: i16,
80 pub added_at: DateTime<Utc>,
81 pub username: String,
82 pub display_name: Option<String>,
83 pub stripe_account_id: Option<StripeAccountId>,
84 pub stripe_charges_enabled: bool,
85 }
86