pub struct ResourceBooking {Show 13 fields
pub id: Uuid,
pub building_id: Uuid,
pub resource_type: ResourceType,
pub resource_name: String,
pub booked_by: Uuid,
pub start_time: DateTime<Utc>,
pub end_time: DateTime<Utc>,
pub status: BookingStatus,
pub notes: Option<String>,
pub recurring_pattern: RecurringPattern,
pub recurrence_end_date: Option<DateTime<Utc>>,
pub created_at: DateTime<Utc>,
pub updated_at: DateTime<Utc>,
}Expand description
Resource booking entity for community space reservations
Represents a booking for shared building resources (meeting rooms, laundry, gym, etc.) with conflict detection, duration limits, and recurring booking support.
§Belgian Legal Context
- Common spaces in Belgian copropriétés are shared property (Article 3 Loi Copropriété)
- Syndic can regulate usage to ensure fair access for all co-owners
- Booking system provides transparent allocation and prevents conflicts
§Business Rules
- start_time must be < end_time
- start_time must be in the future (no past bookings)
- Duration must not exceed max_duration_hours (configurable per resource)
- No overlapping bookings for the same resource
- Advance booking limit (e.g., max 30 days ahead)
- Only booking owner can cancel their own bookings
Fields§
§id: Uuid§building_id: Uuid§resource_type: ResourceType§resource_name: String§booked_by: Uuid§start_time: DateTime<Utc>§end_time: DateTime<Utc>§status: BookingStatus§notes: Option<String>§recurring_pattern: RecurringPattern§recurrence_end_date: Option<DateTime<Utc>>§created_at: DateTime<Utc>§updated_at: DateTime<Utc>Implementations§
Source§impl ResourceBooking
impl ResourceBooking
Sourcepub const DEFAULT_MAX_DURATION_HOURS: i64 = 4i64
pub const DEFAULT_MAX_DURATION_HOURS: i64 = 4i64
Maximum duration in hours per booking (default: 4 hours)
Sourcepub const DEFAULT_MAX_ADVANCE_DAYS: i64 = 30i64
pub const DEFAULT_MAX_ADVANCE_DAYS: i64 = 30i64
Maximum advance booking in days (default: 30 days)
Sourcepub const MIN_DURATION_MINUTES: i64 = 30i64
pub const MIN_DURATION_MINUTES: i64 = 30i64
Minimum booking duration in minutes (default: 30 minutes)
Sourcepub fn new(
building_id: Uuid,
resource_type: ResourceType,
resource_name: String,
booked_by: Uuid,
start_time: DateTime<Utc>,
end_time: DateTime<Utc>,
notes: Option<String>,
recurring_pattern: RecurringPattern,
recurrence_end_date: Option<DateTime<Utc>>,
max_duration_hours: Option<i64>,
max_advance_days: Option<i64>,
) -> Result<Self, String>
pub fn new( building_id: Uuid, resource_type: ResourceType, resource_name: String, booked_by: Uuid, start_time: DateTime<Utc>, end_time: DateTime<Utc>, notes: Option<String>, recurring_pattern: RecurringPattern, recurrence_end_date: Option<DateTime<Utc>>, max_duration_hours: Option<i64>, max_advance_days: Option<i64>, ) -> Result<Self, String>
Create a new resource booking
§Validation
- resource_name must be 3-100 characters
- start_time must be < end_time
- start_time must be in the future
- Duration must be >= MIN_DURATION_MINUTES
- Duration must be <= max_duration_hours
- start_time must be <= max_advance_days in the future
- For recurring bookings, recurrence_end_date must be provided
§Arguments
building_id- Building where resource is locatedresource_type- Type of resource being bookedresource_name- Specific resource name (e.g., “Meeting Room A”)booked_by- Owner ID making the bookingstart_time- Booking start timeend_time- Booking end timenotes- Optional notes for the bookingrecurring_pattern- Recurring pattern (None, Daily, Weekly, Monthly)recurrence_end_date- End date for recurring bookingsmax_duration_hours- Max duration allowed (defaults to 4 hours)max_advance_days- Max advance booking allowed (defaults to 30 days)
Sourcepub fn complete(&mut self) -> Result<(), String>
pub fn complete(&mut self) -> Result<(), String>
Mark booking as completed
Typically called automatically after end_time passes. Only Confirmed bookings can be marked as completed.
Sourcepub fn mark_no_show(&mut self) -> Result<(), String>
pub fn mark_no_show(&mut self) -> Result<(), String>
Mark booking as no-show
Called when user doesn’t show up for their booking. Only Confirmed bookings can be marked as no-show.
Sourcepub fn confirm(&mut self) -> Result<(), String>
pub fn confirm(&mut self) -> Result<(), String>
Confirm a pending booking
Only Pending bookings can be confirmed.
Sourcepub fn update_details(
&mut self,
resource_name: Option<String>,
notes: Option<String>,
) -> Result<(), String>
pub fn update_details( &mut self, resource_name: Option<String>, notes: Option<String>, ) -> Result<(), String>
Update booking details (resource_name, notes)
Only allowed for Pending or Confirmed bookings. Time changes require cancellation and rebooking to ensure conflict detection.
Sourcepub fn is_active(&self) -> bool
pub fn is_active(&self) -> bool
Check if booking is currently active (now is between start_time and end_time)
Sourcepub fn is_future(&self) -> bool
pub fn is_future(&self) -> bool
Check if booking is in the future (start_time hasn’t arrived yet)
Sourcepub fn duration_hours(&self) -> f64
pub fn duration_hours(&self) -> f64
Calculate booking duration in hours
Sourcepub fn conflicts_with(&self, other: &ResourceBooking) -> bool
pub fn conflicts_with(&self, other: &ResourceBooking) -> bool
Check if this booking conflicts with another booking
Conflict occurs if:
- Same building_id, resource_type, resource_name
- Time ranges overlap
- Other booking is Pending or Confirmed (not Cancelled/Completed/NoShow)
Time overlap logic:
- Bookings overlap if: start1 < end2 AND start2 < end1
Sourcepub fn is_modifiable(&self) -> bool
pub fn is_modifiable(&self) -> bool
Check if booking is modifiable (Pending or Confirmed)
Sourcepub fn is_recurring(&self) -> bool
pub fn is_recurring(&self) -> bool
Check if booking is recurring
Trait Implementations§
Source§impl Clone for ResourceBooking
impl Clone for ResourceBooking
Source§fn clone(&self) -> ResourceBooking
fn clone(&self) -> ResourceBooking
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for ResourceBooking
impl Debug for ResourceBooking
Source§impl<'de> Deserialize<'de> for ResourceBooking
impl<'de> Deserialize<'de> for ResourceBooking
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for ResourceBooking
impl RefUnwindSafe for ResourceBooking
impl Send for ResourceBooking
impl Sync for ResourceBooking
impl Unpin for ResourceBooking
impl UnwindSafe for ResourceBooking
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Chain<T> for T
impl<T> Chain<T> for T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Fake for T
impl<T> Fake for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more