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
+17 -1
View File
@@ -12,6 +12,7 @@ namespace Fitness_core_BE.Services.CustomerPlanService
public class CustomerPlanService(
ICustomerPlanRepository customerPlanRepository,
IFacilityRepository facilityRepository,
IFacilityClassRepository facilityClassRepository,
IUnitOfWork uow,
UserRoleHelper userRoleHelper) : ICustomerPlanService
{
@@ -26,6 +27,7 @@ namespace Fitness_core_BE.Services.CustomerPlanService
private readonly ICustomerPlanRepository _customerPlanRepository = customerPlanRepository;
private readonly IFacilityRepository _facilityRepository = facilityRepository;
private readonly IFacilityClassRepository _facilityClassRepository = facilityClassRepository;
private readonly IUnitOfWork _uow = uow;
private readonly UserRoleHelper _userRoleHelper = userRoleHelper;
@@ -101,6 +103,16 @@ namespace Fitness_core_BE.Services.CustomerPlanService
Guid userId = DataExtractor.GetUserIdFromContext(httpContext);
Guid clientId = await _userRoleHelper.GetClientId(userId);
// Only meaningful when facilityClassId is set below (the Classes tab's "Manage
// Plan" action) -- never consulted for an ordinary plan, which always grants gym
// access regardless of this stored value. Defaults to false for a class plan
// (the "sportsman" case: class access only) unless staff opts it on.
Guid? facilityClassId = data.ContainsKey("facilityClassId") && data["facilityClassId"].ValueKind != JsonValueKind.Null
? Guid.Parse(data["facilityClassId"].GetString()!) : null;
var grantsGymAccess = facilityClassId.HasValue
? data.ContainsKey("grantsGymAccess") && data["grantsGymAccess"].GetBoolean()
: true;
var customerPlan = new Models.CustomerPlan
{
FKClientId = clientId,
@@ -124,7 +136,8 @@ namespace Fitness_core_BE.Services.CustomerPlanService
: null,
SessionRolloverPolicy = data.ContainsKey("sessionRolloverPolicy") ? data["sessionRolloverPolicy"].GetString() ?? RolloverNone : RolloverNone,
RolloverGraceDays = data.ContainsKey("rolloverGraceDays") ? data["rolloverGraceDays"].GetInt32() : 0,
BillingTiming = data.ContainsKey("billingTiming") ? data["billingTiming"].GetString() ?? BillingPrepaid : BillingPrepaid
BillingTiming = data.ContainsKey("billingTiming") ? data["billingTiming"].GetString() ?? BillingPrepaid : BillingPrepaid,
GrantsGymAccess = grantsGymAccess
};
NormalizeAndValidate(customerPlan);
@@ -132,6 +145,9 @@ namespace Fitness_core_BE.Services.CustomerPlanService
var result = await _customerPlanRepository.CreateCustomerPlan(customerPlan);
await _uow.SaveChangesAsync();
if (facilityClassId.HasValue)
await _facilityClassRepository.LinkPlanToClassAsync(result.CustomerPlanId, facilityClassId.Value);
var placeIds = DataExtractor.GetOptionalGuidList(data, "placeIds");
if (placeIds != null)
await _facilityRepository.SetPlanFacilitiesAsync(result.CustomerPlanId, placeIds);