| 1 |
|
| 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 |
|
| 11 |
|
| 12 |
#[derive(Debug, Clone)] |
| 13 |
pub struct ApprovedEntryInfo { |
| 14 |
|
| 15 |
pub selection_method: super::super::SelectionMethod, |
| 16 |
|
| 17 |
pub wave_id: CreatorWaveId, |
| 18 |
|
| 19 |
pub reviewed_at: DateTime<Utc>, |
| 20 |
} |
| 21 |
|
| 22 |
|
| 23 |
#[derive(Debug, Clone, FromRow, Serialize)] |
| 24 |
pub struct DbInviteCode { |
| 25 |
pub id: InviteCodeId, |
| 26 |
pub code: String, |
| 27 |
pub creator_id: UserId, |
| 28 |
pub redeemed_by_id: Option<UserId>, |
| 29 |
pub redeemed_at: Option<DateTime<Utc>>, |
| 30 |
pub created_at: DateTime<Utc>, |
| 31 |
} |
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
#[derive(Debug, Clone, FromRow, Serialize)] |
| 40 |
pub struct DbWaitlistEntry { |
| 41 |
|
| 42 |
pub id: WaitlistEntryId, |
| 43 |
|
| 44 |
pub user_id: UserId, |
| 45 |
|
| 46 |
pub pitch: Option<String>, |
| 47 |
|
| 48 |
pub status: super::super::WaitlistStatus, |
| 49 |
|
| 50 |
pub selection_method: Option<super::super::SelectionMethod>, |
| 51 |
|
| 52 |
pub wave_id: Option<CreatorWaveId>, |
| 53 |
|
| 54 |
pub admin_note: Option<String>, |
| 55 |
|
| 56 |
pub created_at: DateTime<Utc>, |
| 57 |
|
| 58 |
pub reviewed_at: Option<DateTime<Utc>>, |
| 59 |
|
| 60 |
pub invited_by_user_id: Option<UserId>, |
| 61 |
} |
| 62 |
|
| 63 |
impl DbWaitlistEntry { |
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
pub fn approved_info(&self) -> Option<ApprovedEntryInfo> { |
| 68 |
Some(ApprovedEntryInfo { |
| 69 |
selection_method: self.selection_method?, |
| 70 |
wave_id: self.wave_id?, |
| 71 |
reviewed_at: self.reviewed_at?, |
| 72 |
}) |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
#[derive(Debug, Clone, FromRow, Serialize)] |
| 78 |
pub struct DbCreatorWave { |
| 79 |
|
| 80 |
pub id: CreatorWaveId, |
| 81 |
|
| 82 |
pub wave_number: i32, |
| 83 |
|
| 84 |
pub hand_picked_count: i32, |
| 85 |
|
| 86 |
pub lottery_count: i32, |
| 87 |
|
| 88 |
pub total_eligible: i32, |
| 89 |
|
| 90 |
pub note: Option<String>, |
| 91 |
|
| 92 |
pub created_at: DateTime<Utc>, |
| 93 |
} |
| 94 |
|
| 95 |
|
| 96 |
#[derive(Debug, Clone, FromRow)] |
| 97 |
#[allow(dead_code)] |
| 98 |
pub struct DbAdminWaitlistRow { |
| 99 |
|
| 100 |
pub id: WaitlistEntryId, |
| 101 |
|
| 102 |
pub user_id: UserId, |
| 103 |
|
| 104 |
pub pitch: Option<String>, |
| 105 |
|
| 106 |
pub status: super::super::WaitlistStatus, |
| 107 |
|
| 108 |
pub selection_method: Option<super::super::SelectionMethod>, |
| 109 |
|
| 110 |
pub admin_note: Option<String>, |
| 111 |
|
| 112 |
pub created_at: DateTime<Utc>, |
| 113 |
|
| 114 |
pub reviewed_at: Option<DateTime<Utc>>, |
| 115 |
|
| 116 |
|
| 117 |
pub username: Username, |
| 118 |
|
| 119 |
pub email: Email, |
| 120 |
|
| 121 |
pub email_verified: bool, |
| 122 |
|
| 123 |
pub invited_by_user_id: Option<UserId>, |
| 124 |
|
| 125 |
pub invited_by_username: Option<String>, |
| 126 |
} |
| 127 |
|
| 128 |
|
| 129 |
#[derive(Debug, Clone, FromRow)] |
| 130 |
pub struct DbWaitlistStats { |
| 131 |
|
| 132 |
pub pending: i64, |
| 133 |
|
| 134 |
pub approved: i64, |
| 135 |
|
| 136 |
pub spam: i64, |
| 137 |
} |
| 138 |
|
| 139 |
#[cfg(test)] |
| 140 |
mod tests { |
| 141 |
use super::*; |
| 142 |
|
| 143 |
fn make_waitlist_entry( |
| 144 |
status: super::super::super::WaitlistStatus, |
| 145 |
method: Option<super::super::super::SelectionMethod>, |
| 146 |
wave: Option<CreatorWaveId>, |
| 147 |
reviewed: Option<DateTime<Utc>>, |
| 148 |
) -> DbWaitlistEntry { |
| 149 |
DbWaitlistEntry { |
| 150 |
id: WaitlistEntryId::nil(), |
| 151 |
user_id: UserId::nil(), |
| 152 |
pitch: Some("test".to_string()), |
| 153 |
status, |
| 154 |
selection_method: method, |
| 155 |
wave_id: wave, |
| 156 |
admin_note: None, |
| 157 |
created_at: Utc::now(), |
| 158 |
reviewed_at: reviewed, |
| 159 |
invited_by_user_id: None, |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
#[test] |
| 164 |
fn approved_info_for_approved_entry() { |
| 165 |
let wave = CreatorWaveId::new(); |
| 166 |
let now = Utc::now(); |
| 167 |
let e = make_waitlist_entry( |
| 168 |
super::super::super::WaitlistStatus::Approved, |
| 169 |
Some(super::super::super::SelectionMethod::HandPicked), |
| 170 |
Some(wave), |
| 171 |
Some(now), |
| 172 |
); |
| 173 |
let info = e.approved_info().unwrap(); |
| 174 |
assert_eq!(info.selection_method, super::super::super::SelectionMethod::HandPicked); |
| 175 |
assert_eq!(info.wave_id, wave); |
| 176 |
assert_eq!(info.reviewed_at, now); |
| 177 |
} |
| 178 |
|
| 179 |
#[test] |
| 180 |
fn approved_info_none_for_pending() { |
| 181 |
let e = make_waitlist_entry( |
| 182 |
super::super::super::WaitlistStatus::Pending, |
| 183 |
None, |
| 184 |
None, |
| 185 |
None, |
| 186 |
); |
| 187 |
assert!(e.approved_info().is_none()); |
| 188 |
} |
| 189 |
|
| 190 |
#[test] |
| 191 |
fn approved_info_none_for_spam() { |
| 192 |
|
| 193 |
let e = make_waitlist_entry( |
| 194 |
super::super::super::WaitlistStatus::Spam, |
| 195 |
None, |
| 196 |
None, |
| 197 |
Some(Utc::now()), |
| 198 |
); |
| 199 |
assert!(e.approved_info().is_none()); |
| 200 |
} |
| 201 |
} |
| 202 |
|