5d711bd13e
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>
51 lines
3.2 KiB
C#
51 lines
3.2 KiB
C#
using Fitness_core_BE.Models;
|
|
|
|
namespace Fitness_core_BE.Interfaces
|
|
{
|
|
public interface IFacilityRepository
|
|
{
|
|
Task<List<Facility>> GetAllFacilities(Guid clientId, bool includeInactive = false);
|
|
Task<Facility?> GetFacilityById(Guid facilityId);
|
|
Task<Facility> CreateFacility(Facility facility);
|
|
Task<Facility> UpdateFacility(Facility facility);
|
|
Task<Facility?> SetFacilityActive(Guid facilityId, Guid clientId, bool isActive);
|
|
|
|
Task<FacilitySession> CreateFacilitySession(FacilitySession session);
|
|
Task<FacilitySession?> GetFacilitySessionById(Guid facilitySessionId);
|
|
Task<List<FacilitySession>> GetSessions(Guid clientId, Guid? facilityId, DateTime fromUtc, DateTime toUtc, bool includeCancelled = false);
|
|
Task<int> GetActiveBookingCount(Guid facilitySessionId);
|
|
Task<List<FacilitySession>> GetOverlappingActiveSessionsAsync(Guid facilityId, DateTime startUtc, DateTime endUtc);
|
|
|
|
/// <summary>"Mark not held" -- see FacilityService.CancelFacilitySession for the full
|
|
/// cascade this backs. Returns the session with its Bookings included so the caller can
|
|
/// cancel+refund each Confirmed one.</summary>
|
|
Task<FacilitySession?> MarkFacilitySessionNotHeldAsync(Guid facilitySessionId, Guid clientId, string? reason);
|
|
|
|
// Device binding (absorbed from the old IPlaceRepo -- one AccessDevice per Facility).
|
|
Task<AccessDevice?> GetDeviceByIdForClientAsync(Guid deviceId, Guid clientId);
|
|
Task<Dictionary<Guid, AccessDevice>> GetDevicesByFacilityIdsAsync(List<Guid> facilityIds);
|
|
Task<bool> IsDeviceAssignedToAnotherFacilityAsync(Guid deviceId, Guid facilityId);
|
|
Task AssignDeviceAsync(Guid facilityId, Guid deviceId);
|
|
Task UnassignDeviceAsync(Guid facilityId);
|
|
|
|
// CustomerPlan <-> Facility access-scoping (many-to-many). Replace-all semantics, like a
|
|
// tags field. Absorbed from the old IPlaceRepo.
|
|
Task SetPlanFacilitiesAsync(Guid customerPlanId, List<Guid> facilityIds);
|
|
Task<List<Guid>> GetFacilityIdsForPlanAsync(Guid customerPlanId);
|
|
Task<Dictionary<Guid, List<Guid>>> GetFacilityIdsByPlanIdsAsync(List<Guid> customerPlanIds);
|
|
Task<Dictionary<Guid, string>> GetFacilityNamesByIdsAsync(List<Guid> facilityIds);
|
|
|
|
// WalkIn booking support (new). See TenantDbContext's Booking (FKFacilityId, StartTime,
|
|
// EndTime) index comment -- overlap is checked here rather than by a DB constraint.
|
|
/// <summary>Counts non-cancelled/non-completed WalkIn bookings on this facility whose
|
|
/// [StartTime, EndTime) overlaps the given window. Pass excludeBookingId when
|
|
/// re-checking a booking being rescheduled, so it doesn't count against itself.</summary>
|
|
Task<int> GetOverlappingWalkInBookingCountAsync(Guid facilityId, DateTime startTime, DateTime endTime, Guid? excludeBookingId = null);
|
|
|
|
/// <summary>Issues a row lock on the facility (SELECT ... FOR UPDATE) inside the caller's
|
|
/// already-open unit-of-work transaction, serializing concurrent WalkIn-slot claims on the
|
|
/// same facility so two overlapping bookings can't both pass the overlap-count check.</summary>
|
|
Task LockFacilityForUpdateAsync(Guid facilityId);
|
|
}
|
|
}
|