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

event.rs92 lines, 2.9 KiBHistoryRawDownload
1//! Event surfacing: the calendar's create/read/update/delete and the
2//! audience's live membership resolution. The queries live in
3//! [`crate::db::event`]; there is no workflow of this domain's own — every
4//! write is a single atomic statement or transaction, and the freeze rule
5//! the signup flow leans on is the pure
6//! [`crate::domain::event::Event::registration_capacity`].
7
8use crate::database::Database;
9use crate::db::event;
10use crate::domain::event::{Event, EventAudience, EventDescription, EventId, EventTitle};
11use crate::domain::timestamp::Timestamp;
12use crate::domain::user::{User, UserId};
13use crate::error::AppError;
14
15pub async fn create(
16 db: &Database,
17 creator: &UserId,
18 title: EventTitle,
19 description: EventDescription,
20 audience: EventAudience,
21 starts_at: Option<Timestamp>,
22 ends_at: Option<Timestamp>,
23) -> Result<Event, AppError> {
24 event::create(
25 db,
26 creator,
27 title,
28 description,
29 audience,
30 starts_at,
31 ends_at,
32 )
33 .await
34}
35
36pub async fn read(db: &Database, id: &EventId) -> Result<Option<Event>, AppError> {
37 event::read(db, id).await
38}
39
40/// The `GET /events` list — visibility-free (every authenticated user sees
41/// every event), the schedule window and the page pushed into SQL. All four
42/// window bounds absent is the unfiltered, newest-first read.
43pub async fn list_windowed(
44 db: &Database,
45 starts_after: Option<i64>,
46 ends_after: Option<i64>,
47 starts_before: Option<i64>,
48 ends_before: Option<i64>,
49 limit: Option<i64>,
50 offset: i64,
51) -> Result<(Vec<Event>, i64), AppError> {
52 event::list_windowed(
53 db,
54 starts_after,
55 ends_after,
56 starts_before,
57 ends_before,
58 limit,
59 offset,
60 )
61 .await
62}
63
64/// Only what the request carried is written: an omitted field (`None`) is
65/// not stored at all. The schedule columns take the set-or-clear spelling.
66pub async fn update(
67 db: &Database,
68 event: Event,
69 title: Option<EventTitle>,
70 description: Option<EventDescription>,
71 audience: Option<EventAudience>,
72 starts_at: Option<Option<Timestamp>>,
73 ends_at: Option<Option<Timestamp>>,
74) -> Result<Event, AppError> {
75 event::update(db, event, title, description, audience, starts_at, ends_at).await
76}
77
78/// Delete the event and cascade its attendance and signup rows.
79pub async fn delete(db: &Database, event: Event) -> Result<Event, AppError> {
80 event::delete(db, event).await
81}
82
83/// Is `user` in the event's audience roster right now — the point check
84/// behind marking.
85pub async fn includes(db: &Database, event: &Event, user: &User) -> Result<bool, AppError> {
86 event::includes(db, event, user).await
87}
88
89/// The event's full expected-attendee roster, resolved live.
90pub async fn members(db: &Database, event: &Event) -> Result<Vec<UserId>, AppError> {
91 event::members(db, event).await
92}