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
+22 -7
View File
@@ -41,7 +41,8 @@ namespace Fitness_core_BE.Repos
?? throw new KeyNotFoundException("Facility not found");
existing.Name = facility.Name;
existing.BookingMode = facility.BookingMode;
existing.SupportsClasses = facility.SupportsClasses;
existing.SupportsBooking = facility.SupportsBooking;
existing.Description = facility.Description;
existing.DefaultCapacity = facility.DefaultCapacity;
existing.NumberOfUnits = facility.NumberOfUnits;
@@ -76,12 +77,15 @@ namespace Fitness_core_BE.Repos
.Include(s => s.Facility)
.FirstOrDefaultAsync(s => s.FacilitySessionId == facilitySessionId);
public async Task<List<FacilitySession>> GetSessions(Guid clientId, Guid? facilityId, DateTime fromUtc, DateTime toUtc)
public async Task<List<FacilitySession>> GetSessions(Guid clientId, Guid? facilityId, DateTime fromUtc, DateTime toUtc, bool includeCancelled = false)
{
var query = _context.FacilitySessions
.Include(s => s.Facility)
.Where(s => s.FKClientId == clientId && s.StartTime >= fromUtc && s.StartTime <= toUtc && !s.IsCancelled);
.Include(s => s.FacilityClass)
.Where(s => s.FKClientId == clientId && s.StartTime >= fromUtc && s.StartTime <= toUtc);
if (!includeCancelled)
query = query.Where(s => !s.IsCancelled);
if (facilityId.HasValue)
query = query.Where(s => s.FKFacilityId == facilityId.Value);
@@ -91,13 +95,24 @@ namespace Fitness_core_BE.Repos
public Task<int> GetActiveBookingCount(Guid facilitySessionId)
=> _context.Bookings.CountAsync(b => b.FKFacilitySessionId == facilitySessionId && b.Status != "Cancelled");
public async Task<FacilitySession?> CancelFacilitySession(Guid facilitySessionId, Guid clientId)
/// <summary>True interval overlap (StartTime &lt; end &amp;&amp; EndTime &gt; start), not a
/// "StartTime falls inside the window" filter like GetSessions -- a class that started
/// before the window and is still running must still count as occupying it.</summary>
public Task<List<FacilitySession>> GetOverlappingActiveSessionsAsync(Guid facilityId, DateTime startUtc, DateTime endUtc)
=> _context.FacilitySessions
.Where(s => s.FKFacilityId == facilityId && !s.IsCancelled && s.StartTime < endUtc && s.EndTime > startUtc)
.ToListAsync();
public async Task<FacilitySession?> MarkFacilitySessionNotHeldAsync(Guid facilitySessionId, Guid clientId, string? reason)
{
var session = await _context.FacilitySessions
.Include(s => s.Bookings)
.FirstOrDefaultAsync(s => s.FacilitySessionId == facilitySessionId && s.FKClientId == clientId);
if (session == null) return null;
session.IsCancelled = true;
session.NotHeldReason = reason;
session.NotHeldAt = DateTime.UtcNow;
return session;
}
@@ -188,13 +203,13 @@ namespace Fitness_core_BE.Repos
.ToDictionary(g => g.Key, g => g.Select(pf => pf.FKFacilityId).ToList());
}
// --- AdHoc booking support (new) ---
// --- WalkIn booking support (new) ---
public Task<int> GetOverlappingAdhocBookingCountAsync(Guid facilityId, DateTime startTime, DateTime endTime, Guid? excludeBookingId = null)
public Task<int> GetOverlappingWalkInBookingCountAsync(Guid facilityId, DateTime startTime, DateTime endTime, Guid? excludeBookingId = null)
{
var query = _context.Bookings.Where(b =>
b.FKFacilityId == facilityId &&
b.FKFacilitySessionId == null && // AdHoc bookings only
b.FKFacilitySessionId == null && // WalkIn bookings only
b.Status != "Cancelled" && b.Status != "NoShow" && b.Status != "Completed" &&
b.StartTime < endTime && b.EndTime > startTime);