forge
Explore
Log in

Don't you dare go Hollow

hezarfen_backend

Clone
★ 0

0 watching0 forksRust8.3 MiB6d68754Ahmet Kaan Gümüş2 months ago566 commits

registration.rs82 lines, 2.7 KiBHistoryRawDownload
1use crate::domain::event::EventId;
2use crate::domain::user::UserId;
3
4/// The (event, user) pair — the table's natural composite primary key. The
5/// same pair always maps to the same row, so one-row-per-pair holds by
6/// construction (the enrollment trick) even if a write ever slipped past the
7/// register lock. UUID strings carry only `-`, so `_` is an unambiguous
8/// joiner.
9#[derive(Debug, Clone, PartialEq, Eq)]
10pub struct RegistrationId {
11 event: EventId,
12 user: UserId,
13}
14
15impl RegistrationId {
16 pub fn composite(event: &EventId, user: &UserId) -> Self {
17 Self {
18 event: event.clone(),
19 user: *user,
20 }
21 }
22
23 /// Parse the `{event}_{user}` wire form. A key that parses as no pair
24 /// reads as the nil pair, which matches no row — exactly the 404 a
25 /// dangling composite key produced under the old store, without turning a
26 /// typo into a panic.
27 pub fn from_key(key: &str) -> Self {
28 let (event, user) = key.rsplit_once('_').unwrap_or(("", ""));
29 Self {
30 event: EventId::from_key(event),
31 user: UserId::from_key(user),
32 }
33 }
34
35 /// The `{event}_{user}` wire form.
36 pub fn key(&self) -> String {
37 format!("{}_{}", self.event.key(), self.user.key())
38 }
39
40 pub fn event(&self) -> EventId {
41 self.event.clone()
42 }
43
44 pub fn user(&self) -> UserId {
45 self.user
46 }
47}
48
49/// A seat on a registration-audience event's signup list. The list *is* the
50/// event's roster: whoever holds a row is expected (and markable), everyone
51/// else is not. Rows survive audience changes inertly — switching the event
52/// away from the registration kind hides them without deleting them.
53#[derive(Debug, Clone, sqlx::FromRow)]
54pub struct Registration {
55 pub(crate) event: EventId,
56 #[sqlx(rename = "app_user")]
57 pub(crate) user: UserId,
58 pub(crate) registered_by: UserId,
59}
60
61impl Registration {
62 pub fn get_event(&self) -> &EventId {
63 &self.event
64 }
65
66 pub fn get_user(&self) -> &UserId {
67 &self.user
68 }
69
70 pub fn get_registered_by(&self) -> &UserId {
71 &self.registered_by
72 }
73
74 // The demotion sweep — freeing every seat a fall to `parent` would strand,
75 // and leaving a list that has already frozen exactly as it stands — is an
76 // arm of [`crate::service::user::set_role`], so the seat comes back in
77 // the same transaction as the role that invalidated it. The freeze it obeys
78 // is [`crate::domain::event::Event::registration_capacity`]'s `Conflict`
79 // arm, re-spelled for the stored guard in
80 // [`crate::constant::REGISTRATION_FROZEN_GUARD`] and held to it by
81 // `event::tests::the_sql_freeze_guard_matches_the_rust_one`.
82}