diff --git a/src/domain/appointment.rs b/src/domain/appointment.rs index 287743a..4367584 100644 --- a/src/domain/appointment.rs +++ b/src/domain/appointment.rs @@ -47,7 +47,7 @@ impl AppointmentId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/appointment_slot.rs b/src/domain/appointment_slot.rs index c05c758..1cc0d41 100644 --- a/src/domain/appointment_slot.rs +++ b/src/domain/appointment_slot.rs @@ -44,7 +44,7 @@ impl AppointmentSlotId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/bank_question.rs b/src/domain/bank_question.rs index 8d7c7f9..f39044d 100644 --- a/src/domain/bank_question.rs +++ b/src/domain/bank_question.rs @@ -77,7 +77,7 @@ impl BankQuestionId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/board.rs b/src/domain/board.rs index 7b39965..b30ea6e 100644 --- a/src/domain/board.rs +++ b/src/domain/board.rs @@ -32,7 +32,7 @@ impl BoardId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/board_stroke.rs b/src/domain/board_stroke.rs index 1ea4b77..bde473c 100644 --- a/src/domain/board_stroke.rs +++ b/src/domain/board_stroke.rs @@ -69,7 +69,7 @@ impl BoardStrokeId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/chatbot_message.rs b/src/domain/chatbot_message.rs index afc6c4d..768cde1 100644 --- a/src/domain/chatbot_message.rs +++ b/src/domain/chatbot_message.rs @@ -41,7 +41,7 @@ impl ChatbotMessageId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/chatbot_thread.rs b/src/domain/chatbot_thread.rs index 7bfabac..f47bd47 100644 --- a/src/domain/chatbot_thread.rs +++ b/src/domain/chatbot_thread.rs @@ -26,7 +26,7 @@ impl ChatbotThreadId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/class_group.rs b/src/domain/class_group.rs index 12cc779..2341f05 100644 --- a/src/domain/class_group.rs +++ b/src/domain/class_group.rs @@ -32,7 +32,7 @@ impl ClassGroupId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/course.rs b/src/domain/course.rs index 71a2e08..f81d578 100644 --- a/src/domain/course.rs +++ b/src/domain/course.rs @@ -20,7 +20,7 @@ impl CourseId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/course_note.rs b/src/domain/course_note.rs index 4058db2..189f852 100644 --- a/src/domain/course_note.rs +++ b/src/domain/course_note.rs @@ -20,7 +20,7 @@ impl CourseNoteId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/course_note_file.rs b/src/domain/course_note_file.rs index 5a1d954..3d962be 100644 --- a/src/domain/course_note_file.rs +++ b/src/domain/course_note_file.rs @@ -28,7 +28,7 @@ impl CourseNoteFileId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/course_session.rs b/src/domain/course_session.rs index 56df9ff..d18b606 100644 --- a/src/domain/course_session.rs +++ b/src/domain/course_session.rs @@ -21,7 +21,7 @@ impl CourseSessionId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/event.rs b/src/domain/event.rs index 07868bb..61101b9 100644 --- a/src/domain/event.rs +++ b/src/domain/event.rs @@ -23,7 +23,7 @@ impl EventId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } @@ -132,6 +132,32 @@ impl EventAudienceKind { match self { EventAudienceKind::School => "school", EventAudienceKind::Role => "role", + +/// The five audience columns as one value — the write-side bundle. The row +/// keeps them flat; every write spells them as a unit, so a kind and its +/// payload always land together and only the payload matching `kind` is +/// ever non-NULL. +#[derive(Debug, Clone, PartialEq, Eq)] +pub struct EventAudience { + pub kind: EventAudienceKind, + pub role: Option, + pub course: Option, + pub class: Option, + pub capacity: Option, +} + +impl EventAudience { + /// The audience of a row read back from the store. + pub fn of_row(event: &Event) -> Self { + Self { + kind: event.get_audience_kind(), + role: event.get_audience_role(), + course: event.get_audience_course().copied(), + class: event.get_audience_class().copied(), + capacity: event.get_audience_capacity(), + } + } +} EventAudienceKind::Course => "course", EventAudienceKind::Class => "class", EventAudienceKind::Registration => "registration", diff --git a/src/domain/exam.rs b/src/domain/exam.rs index c8a256a..35b8615 100644 --- a/src/domain/exam.rs +++ b/src/domain/exam.rs @@ -37,7 +37,7 @@ impl ExamId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/exam_question.rs b/src/domain/exam_question.rs index 9ba0d10..c571d57 100644 --- a/src/domain/exam_question.rs +++ b/src/domain/exam_question.rs @@ -27,7 +27,7 @@ impl ExamQuestionId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/fee_plan.rs b/src/domain/fee_plan.rs index 8c2cb41..8cde41b 100644 --- a/src/domain/fee_plan.rs +++ b/src/domain/fee_plan.rs @@ -34,7 +34,7 @@ impl FeePlanId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/homework.rs b/src/domain/homework.rs index 7557118..0e31b83 100644 --- a/src/domain/homework.rs +++ b/src/domain/homework.rs @@ -36,7 +36,7 @@ impl HomeworkId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/homework_file.rs b/src/domain/homework_file.rs index 6a83a36..f22fe0a 100644 --- a/src/domain/homework_file.rs +++ b/src/domain/homework_file.rs @@ -29,7 +29,7 @@ impl HomeworkFileId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/homework_result.rs b/src/domain/homework_result.rs index 56ee74a..8d27666 100644 --- a/src/domain/homework_result.rs +++ b/src/domain/homework_result.rs @@ -34,7 +34,7 @@ impl HomeworkResultId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/homework_submission.rs b/src/domain/homework_submission.rs index 143cca9..8207ad8 100644 --- a/src/domain/homework_submission.rs +++ b/src/domain/homework_submission.rs @@ -34,7 +34,7 @@ impl HomeworkSubmissionId { /// The inner uuid, for runtime-checked binds (Param/QueryBuilder) that /// cannot take the newtype. Static `query!` binds take `self` directly. - pub fn uuid(&self) -> Uuid { + pub fn uuid(&self) -> uuid::Uuid { self.0 } diff --git a/src/domain/work_entry.rs b/src/domain/work_entry.rs index d3385b6..f5121a9 100644 --- a/src/domain/work_entry.rs +++ b/src/domain/work_entry.rs @@ -3,6 +3,7 @@ use uuid::Uuid; use crate::domain::monotonic_id::next_uuid; use crate::domain::timestamp::Timestamp; use crate::domain::user::UserId; +use crate::error::{AppError, ValidationError}; /// Typed work-entry row id. A UUIDv7 minted by the process-wide monotonic /// generator, so `id` order is mint order. @@ -77,3 +78,13 @@ impl WorkEntry { self.check_out.is_none() } } + +/// The one ordering refusal both the web handler's pre-flight and the db +/// layer's write-time guard owe for a corrected stint: the correction must +/// still order as *stored* — check-out at or after check-in. +pub(crate) fn out_before_in_error() -> AppError { + AppError::Validation(ValidationError::Invalid { + field: "check_out", + reason: "must be at or after check_in", + }) +}