Facility booking-mode redesign, multi-plan subscriptions, and Classes

Implements the facility-classes-booking-dashboard plan (backend):

- Facility.BookingMode (single Scheduled/AdHoc choice) replaced with
  independent SupportsClasses/SupportsBooking flags, so one facility
  can run a class and accept walk-in bookings; a running class now
  blocks walk-in booking for its window on both create and reschedule.
- CustomerPlan.GrantsGymAccess + CustomerPlanClass join table let a
  customer hold one gym-access plan plus any number of class-only
  plans. Replaced the old single-subscription resolution
  (GetActiveSubscriptionByCustomerId/HasAnyActiveSubscriptionAsync)
  with gym-access-aware and class-aware resolvers across booking
  creation/cancellation, plan assignment, and customer self-service.
  Fixed ChangeMembershipPlan/renewal plan-changes, which resolved "the
  subscription to replace" by most-recent-created and would have
  deactivated a member's class subscription instead of their gym one.
- New FacilityClass model: recurring class definitions (Daily/Weekly/
  Monthly/Custom) with lazy occurrence generation (8-week horizon,
  race-safe via a unique index) and proper unlimited-capacity handling.
  "Mark not held" replaces the old bare-cancel: cascades to cancel and
  refund every confirmed booking on the occurrence through the same
  core CancelBooking uses, and frees the slot for walk-in booking.
  Scheduling conflicts (a walk-in booking now overlapping a class) are
  surfaced for staff to resolve via the existing Reschedule flow.
- Renamed the pre-existing "AdHoc" booking-mode terminology to
  "WalkIn" throughout (routes, methods, DTOs, the stored BookingMode
  value) for a clearer, simpler name.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
2026-10-09 14:26:59 +05:30
parent 1a502767ba
commit 5d711bd13e
38 changed files with 1437 additions and 226 deletions
+7 -7
View File
@@ -4,7 +4,7 @@ using System.ComponentModel.DataAnnotations.Schema;
namespace Fitness_core_BE.Models
{
/// <summary>One reservation against a Facility — either a Scheduled-mode booking against a
/// pre-created FacilitySession (many bookings share one capacity pool), or an AdHoc-mode
/// pre-created FacilitySession (many bookings share one capacity pool), or a WalkIn-mode
/// booking that claims one of the Facility's NumberOfUnits directly for an arbitrary time
/// window, no session needed. Either an existing member using a CustomerPlan session
/// allowance (FKCustomerId set, IsGuest = false) or a non-member who booked online and pays
@@ -16,28 +16,28 @@ namespace Fitness_core_BE.Models
[Key]
public Guid BookingId { get; set; }
/// <summary>Null for an AdHoc booking (no pre-created session).</summary>
/// <summary>Null for a WalkIn booking (no pre-created session).</summary>
public Guid? FKFacilitySessionId { get; set; }
[ForeignKey(nameof(FKFacilitySessionId))]
public FacilitySession? FacilitySession { get; set; }
/// <summary>Always set, for both modes -- copied from FacilitySession.FKFacilityId at
/// creation (Scheduled) or the booked facility directly (AdHoc). Every place that needs
/// creation (Scheduled) or the booked facility directly (WalkIn). Every place that needs
/// "which facility / what time window" reads these (and StartTime/EndTime below)
/// uniformly instead of reaching through FacilitySession, which doesn't exist for AdHoc
/// uniformly instead of reaching through FacilitySession, which doesn't exist for WalkIn
/// bookings.</summary>
public Guid FKFacilityId { get; set; }
[ForeignKey(nameof(FKFacilityId))]
public Facility Facility { get; set; }
/// <summary>Copied from FacilitySession.StartTime (Scheduled) or the requested start
/// (AdHoc) at creation; updated in place by Reschedule.</summary>
/// (WalkIn) at creation; updated in place by Reschedule.</summary>
public DateTime StartTime { get; set; }
/// <summary>Same pattern as StartTime.</summary>
public DateTime EndTime { get; set; }
/// <summary>Informational headcount for an AdHoc booking (e.g. "how many will come") --
/// never enforced as a capacity mechanic; each AdHoc booking claims one whole unit
/// <summary>Informational headcount for a WalkIn booking (e.g. "how many will come") --
/// never enforced as a capacity mechanic; each WalkIn booking claims one whole unit
/// regardless of party size. Null for Scheduled bookings.</summary>
public int? PartySize { get; set; }
+9
View File
@@ -63,5 +63,14 @@ namespace Fitness_core_BE.Models
public bool IsActive { get; set; } = true;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
/// <summary>Meaningful only for a plan linked to one or more classes (via
/// CustomerPlanClass) -- never consulted for an ordinary plan with no class links,
/// which always grants gym access regardless of this flag's stored value. Lets a class
/// plan optionally also grant general gym-floor access ("class + gym" as one product)
/// instead of class-only. Migration default true (so every pre-existing plan, which has
/// no class links, keeps behaving exactly as before); new class plans default this to
/// false in the UI.</summary>
public bool GrantsGymAccess { get; set; } = true;
}
}
+23
View File
@@ -0,0 +1,23 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Fitness_core_BE.Models
{
/// <summary>Many-to-many join: which FacilityClass(es) a CustomerPlan is sold against. A
/// plan with no rows here is an ordinary gym plan, completely unaffected by the Classes
/// feature -- CustomerPlan.GrantsGymAccess is never consulted for it. Structurally identical
/// to CustomerPlanFacility.</summary>
public class CustomerPlanClass
{
[Key]
public Guid CustomerPlanClassId { get; set; }
public Guid FKCustomerPlanId { get; set; }
[ForeignKey(nameof(FKCustomerPlanId))]
public CustomerPlan CustomerPlan { get; set; } = null!;
public Guid FKFacilityClassId { get; set; }
[ForeignKey(nameof(FKFacilityClassId))]
public FacilityClass FacilityClass { get; set; } = null!;
}
}
+16 -11
View File
@@ -21,25 +21,30 @@ namespace Fitness_core_BE.Models
[MaxLength(128)]
public string Name { get; set; } = string.Empty;
/// <summary>"Scheduled" | "AdHoc". Scheduled: staff pre-creates fixed-time
/// FacilitySessions that many bookings share one capacity pool against (classes).
/// AdHoc: a booking claims one of NumberOfUnits identical units directly for an
/// arbitrary time window, no pre-created session needed (courts/pool).</summary>
public string BookingMode { get; set; } = "Scheduled";
/// <summary>Staff pre-creates fixed-time FacilitySessions (classes) that many bookings
/// share one capacity pool against. Independent of SupportsBooking -- both can be true,
/// e.g. a court that hosts a scheduled class AND accepts ad-hoc walk-in bookings outside
/// class hours.</summary>
public bool SupportsClasses { get; set; } = true;
/// <summary>A booking can claim one of NumberOfUnits identical units directly for an
/// arbitrary time window, no pre-created session needed (courts/pool). At least one of
/// SupportsClasses/SupportsBooking must be true.</summary>
public bool SupportsBooking { get; set; } = false;
[MaxLength(500)]
public string? Description { get; set; }
/// <summary>Default per-session headcount limit when BookingMode == "Scheduled"; a
/// specific FacilitySession can override.</summary>
/// <summary>Default per-session headcount limit when SupportsClasses; a specific
/// FacilitySession can override.</summary>
public int DefaultCapacity { get; set; } = 1;
/// <summary>Number of identical, independently-bookable units when BookingMode ==
/// "AdHoc" (e.g. 3 for "3 courts") -- availability is this minus overlapping
/// non-cancelled/non-completed AdHoc bookings in the requested window.</summary>
/// <summary>Number of identical, independently-bookable units when SupportsBooking (e.g.
/// 3 for "3 courts") -- availability is this minus overlapping non-cancelled/
/// non-completed WalkIn bookings in the requested window.</summary>
public int NumberOfUnits { get; set; } = 1;
/// <summary>Hourly rate used to compute a guest AdHoc booking's suggested AmountCharged
/// <summary>Hourly rate used to compute a guest WalkIn booking's suggested AmountCharged
/// (PricePerHour * duration-in-hours) at creation time.</summary>
public decimal PricePerHour { get; set; } = 0m;
+71
View File
@@ -0,0 +1,71 @@
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace Fitness_core_BE.Models
{
/// <summary>A recurring class definition (Zumba, Yoga) on a Facility that SupportsClasses --
/// generates FacilitySession rows ("occurrences") on a schedule. Replaces manually creating
/// one-off FacilitySession rows from the Bookings page for anything that recurs.</summary>
public class FacilityClass
{
[Key]
public Guid FacilityClassId { get; set; }
public Guid FKClientId { get; set; }
[ForeignKey(nameof(FKClientId))]
public Client Client { get; set; }
public Guid FKFacilityId { get; set; }
[ForeignKey(nameof(FKFacilityId))]
public Facility Facility { get; set; }
[MaxLength(128)]
public string Name { get; set; } = string.Empty;
[MaxLength(500)]
public string? Description { get; set; }
/// <summary>"Daily" | "Weekly" | "Monthly" | "Custom". Custom skips every rule field
/// below -- occurrences are written explicitly (as FacilitySession rows) at creation/
/// edit time with their own dates, instead of being generated from a rule.</summary>
[MaxLength(20)]
public string RecurrenceType { get; set; } = "Weekly";
/// <summary>The class's daily time window, in the facility's local time (not UTC) -- the
/// generator converts to UTC per-occurrence using the club's timezone. Unused (0) for
/// Custom, where each occurrence's own FacilitySession.StartTime/EndTime is explicit.</summary>
public TimeSpan StartTimeOfDay { get; set; }
public int DurationMinutes { get; set; } = 60;
/// <summary>Weekly only. Bit flags, Sunday = 1 (bit 0) through Saturday = 64 (bit 6).</summary>
public int WeekDaysMask { get; set; } = 0;
/// <summary>Monthly only. Comma-separated day-of-month list, e.g. "1,15".</summary>
[MaxLength(200)]
public string? MonthDays { get; set; }
/// <summary>Unused for Custom (occurrences are explicit, not generated from a range).</summary>
public DateTime SeriesStartDate { get; set; } = DateTime.UtcNow.Date;
/// <summary>Null = ongoing, no end date. Unused for Custom.</summary>
public DateTime? SeriesEndDate { get; set; }
/// <summary>Null = unlimited (see IsUnlimitedCapacity); otherwise the per-occurrence
/// headcount cap, same meaning as Facility.DefaultCapacity/FacilitySession.Capacity.</summary>
public int? Capacity { get; set; }
/// <summary>When true, Capacity is ignored and every generated occurrence has no cap --
/// a distinct flag rather than a sentinel value, since FacilitySession.Capacity == null
/// already means "use the facility default," and int.MaxValue would overflow the
/// checked Sum() in FacilityService.GetAvailability.</summary>
public bool IsUnlimitedCapacity { get; set; } = false;
public bool IsActive { get; set; } = true;
/// <summary>Watermark: occurrences have been generated through this date already.
/// Advanced by FacilityService.EnsureOccurrencesGeneratedAsync; never consulted for
/// Custom classes (their occurrences are all written explicitly, never generated).</summary>
public DateTime OccurrencesGeneratedThrough { get; set; } = DateTime.UtcNow.Date;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
}
}
+19 -1
View File
@@ -22,12 +22,30 @@ namespace Fitness_core_BE.Models
public DateTime StartTime { get; set; }
public DateTime EndTime { get; set; }
/// <summary>Overrides Facility.DefaultCapacity when set; null = use the facility default.</summary>
/// <summary>Overrides Facility.DefaultCapacity when set; null = use the facility default.
/// Ignored when IsUnlimitedCapacity is true.</summary>
public int? Capacity { get; set; }
/// <summary>Copied from FacilityClass.IsUnlimitedCapacity at generation time (or set
/// directly for a manually-created session) -- see that flag's doc comment for why this
/// isn't just a Capacity sentinel value.</summary>
public bool IsUnlimitedCapacity { get; set; } = false;
public bool IsCancelled { get; set; } = false;
public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
/// <summary>Null for a manually-created session (the pre-Classes path, unaffected).
/// Set for a class occurrence -- which FacilityClass generated or explicitly added it.</summary>
public Guid? FKFacilityClassId { get; set; }
[ForeignKey(nameof(FKFacilityClassId))]
public FacilityClass? FacilityClass { get; set; }
/// <summary>Set together by FacilityService's "mark not held" cascade (which replaces
/// the old bare-IsCancelled CancelFacilitySession) -- null means this occurrence is
/// either still scheduled or was never a class occurrence at all.</summary>
public string? NotHeldReason { get; set; }
public DateTime? NotHeldAt { get; set; }
public virtual ICollection<Booking> Bookings { get; set; }
}
}