Refactor CustomerPlanService to use FacilityRepository, remove PlaceService, and introduce RfidTagService
- Updated CustomerPlanService to replace references to PlaceRepo with FacilityRepository for managing customer plans and associated facilities. - Removed PlaceService and its related methods, consolidating functionality into FacilityService. - Added RfidTagService for managing RFID tags, including methods for creating, updating, and setting statuses of tags. - Updated TenantDbContext to include new DbSet for RfidTags and CustomerPlanFacilities, and adjusted model configurations accordingly. - Enhanced FacilityService to support new booking modes and validation for facility creation and updates.
This commit is contained in:
@@ -32,6 +32,18 @@ namespace Fitness_core_BE.Controllers
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreateMemberBooking([FromBody] CreateMemberBookingRequest request)
|
||||
=> Response(await _bookingService.CreateMemberBooking(new { facilitySessionId = request.FacilitySessionId }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[HttpPost("api/app/bookings/adhoc")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreateMemberAdhocBooking([FromBody] CreateAdhocBookingRequest request)
|
||||
=> Response(await _bookingService.CreateMemberAdhocBooking(new
|
||||
{
|
||||
facilityId = request.FacilityId,
|
||||
startTime = request.StartTime.ToString("o"),
|
||||
durationMinutes = request.DurationMinutes,
|
||||
partySize = request.PartySize
|
||||
}, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[HttpGet("api/app/bookings/mine")]
|
||||
@@ -56,6 +68,19 @@ namespace Fitness_core_BE.Controllers
|
||||
guestPhone = request.GuestPhone
|
||||
}, HttpContext));
|
||||
|
||||
[AllowAnonymous]
|
||||
[HttpPost("api/public/bookings/guest/adhoc")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreateGuestAdhocBooking([FromBody] CreateGuestAdhocBookingRequest request)
|
||||
=> Response(await _bookingService.CreateGuestAdhocBooking(new
|
||||
{
|
||||
facilityId = request.FacilityId,
|
||||
startTime = request.StartTime.ToString("o"),
|
||||
durationMinutes = request.DurationMinutes,
|
||||
guestName = request.GuestName,
|
||||
guestPhone = request.GuestPhone,
|
||||
partySize = request.PartySize
|
||||
}, HttpContext));
|
||||
|
||||
// The actual "copy the link and share it" page -- BookingDto.ShareUrl points here.
|
||||
// Plain HTML, not the JSON ApiResponse envelope, since this is meant to be opened
|
||||
// directly in a browser (or a chat app's link preview), not consumed by a client SDK.
|
||||
@@ -72,6 +97,24 @@ namespace Fitness_core_BE.Controllers
|
||||
|
||||
// ---------- Staff ----------
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpGet("api/client/bookings")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> GetBookings(
|
||||
[FromQuery] Guid? facilityId, [FromQuery] Guid? facilitySessionId,
|
||||
[FromQuery] DateTime? fromDate, [FromQuery] DateTime? toDate, [FromQuery] string? status)
|
||||
=> Response(await _bookingService.GetBookings(new
|
||||
{
|
||||
facilityId,
|
||||
facilitySessionId,
|
||||
fromDate = fromDate?.ToString("o"),
|
||||
toDate = toDate?.ToString("o"),
|
||||
status
|
||||
}, HttpContext));
|
||||
|
||||
// Kept as a thin backward-compat wrapper around the unified GetBookings above --
|
||||
// prefer GET api/client/bookings?facilitySessionId= going forward.
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
@@ -84,7 +127,7 @@ namespace Fitness_core_BE.Controllers
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPost("api/client/bookings/check-in")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CheckInBooking([FromBody] CheckInBookingRequest request)
|
||||
=> Response(await _bookingService.CheckInBooking(new { otpCode = request.OtpCode }, HttpContext));
|
||||
=> Response(await _bookingService.CheckInBooking(new { otpCode = request.OtpCode, rfidTagId = request.RfidTagId }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
@@ -99,5 +142,44 @@ namespace Fitness_core_BE.Controllers
|
||||
[HttpPost("api/client/bookings/{id:guid}/cancel")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CancelBooking(Guid id)
|
||||
=> Response(await _bookingService.CancelBooking(new { bookingId = id }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPut("api/client/bookings/{id:guid}/reassign")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> ReassignBooking(Guid id, [FromBody] ReassignBookingRequest request)
|
||||
=> Response(await _bookingService.ReassignBooking(new
|
||||
{
|
||||
bookingId = id,
|
||||
guestName = request.GuestName,
|
||||
guestPhone = request.GuestPhone
|
||||
}, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPut("api/client/bookings/{id:guid}/reschedule")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> RescheduleBooking(Guid id, [FromBody] RescheduleBookingRequest request)
|
||||
=> Response(await _bookingService.RescheduleBooking(new
|
||||
{
|
||||
bookingId = id,
|
||||
startTime = request.StartTime?.ToString("o"),
|
||||
durationMinutes = request.DurationMinutes,
|
||||
facilitySessionId = request.FacilitySessionId
|
||||
}, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPost("api/client/bookings/{id:guid}/no-show")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> MarkNoShow(Guid id)
|
||||
=> Response(await _bookingService.MarkNoShow(new { bookingId = id }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPost("api/client/bookings/{id:guid}/complete")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CompleteBooking(Guid id)
|
||||
=> Response(await _bookingService.CompleteBooking(new { bookingId = id }, HttpContext));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,18 +8,15 @@ using static Fitness_core_BE.Helpers.ApiResponseHelper;
|
||||
|
||||
namespace Fitness_core_BE.Controllers
|
||||
{
|
||||
// Staff/owner-facing facility + facility-session management. Gated on the "bookings" nav
|
||||
// permission (NavItem seeded in CentralDbContext.OnModelCreating).
|
||||
// Staff/owner-facing facility (bookable area + access zone -- merged from the former
|
||||
// Facility/Place split) management. Reads stay on the "bookings" nav permission (the
|
||||
// Bookings page's tabs need the list); mutations (create/edit/status/device-assign) are on
|
||||
// "memberships" since facility setup now lives on the Memberships page.
|
||||
[ApiController]
|
||||
[Route("api/client/facilities")]
|
||||
public class FacilityController : ControllerBase
|
||||
public class FacilityController(IFacilityService facilityService) : ControllerBase
|
||||
{
|
||||
private readonly IFacilityService _facilityService;
|
||||
|
||||
public FacilityController(IFacilityService facilityService)
|
||||
{
|
||||
_facilityService = facilityService;
|
||||
}
|
||||
private readonly IFacilityService _facilityService = facilityService;
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
@@ -30,28 +27,32 @@ namespace Fitness_core_BE.Controllers
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPost("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreateFacility([FromBody] CreateFacilityRequest request)
|
||||
=> Response(await _facilityService.CreateFacility(new
|
||||
{
|
||||
name = request.Name,
|
||||
facilityType = request.FacilityType,
|
||||
bookingMode = request.BookingMode,
|
||||
description = request.Description,
|
||||
defaultCapacity = request.DefaultCapacity
|
||||
defaultCapacity = request.DefaultCapacity,
|
||||
numberOfUnits = request.NumberOfUnits,
|
||||
pricePerHour = request.PricePerHour
|
||||
}, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> UpdateFacility(Guid id, [FromBody] UpdateFacilityRequest request)
|
||||
{
|
||||
var payload = new Dictionary<string, object> { ["facilityId"] = id };
|
||||
if (request.Name != null) payload["name"] = request.Name;
|
||||
if (request.FacilityType != null) payload["facilityType"] = request.FacilityType;
|
||||
if (request.BookingMode != null) payload["bookingMode"] = request.BookingMode;
|
||||
if (request.Description != null) payload["description"] = request.Description;
|
||||
if (request.DefaultCapacity.HasValue) payload["defaultCapacity"] = request.DefaultCapacity.Value;
|
||||
if (request.NumberOfUnits.HasValue) payload["numberOfUnits"] = request.NumberOfUnits.Value;
|
||||
if (request.PricePerHour.HasValue) payload["pricePerHour"] = request.PricePerHour.Value;
|
||||
if (request.IsActive.HasValue) payload["isActive"] = request.IsActive.Value;
|
||||
|
||||
return Response(await _facilityService.UpdateFacility(payload, HttpContext));
|
||||
@@ -59,11 +60,18 @@ namespace Fitness_core_BE.Controllers
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPatch("{id:guid}/status")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> SetFacilityStatus(Guid id, [FromBody] SetFacilityStatusRequest request)
|
||||
=> Response(await _facilityService.SetFacilityStatus(new { facilityId = id, isActive = request.IsActive }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPut("{id:guid}/device")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> AssignDevice(Guid id, [FromBody] AssignFacilityDeviceRequest request)
|
||||
=> Response(await _facilityService.AssignDevice(new { facilityId = id, deviceId = request.DeviceId }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
@@ -96,5 +104,18 @@ namespace Fitness_core_BE.Controllers
|
||||
[HttpDelete("sessions/{id:guid}")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CancelFacilitySession(Guid id)
|
||||
=> Response(await _facilityService.CancelFacilitySession(new { facilitySessionId = id }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpGet("availability")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> GetAvailability(
|
||||
[FromQuery] Guid? facilityId, [FromQuery] DateTime startTime, [FromQuery] int durationMinutes)
|
||||
=> Response(await _facilityService.GetAvailability(new
|
||||
{
|
||||
facilityId,
|
||||
startTime = startTime.ToString("o"),
|
||||
durationMinutes
|
||||
}, HttpContext));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
using Fitness_core_BE.DTOs.Place;
|
||||
using Fitness_core_BE.Helpers;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Fitness_core_BE.Helpers.JwtMiddleware;
|
||||
using static Fitness_core_BE.Helpers.ApiResponseHelper;
|
||||
|
||||
namespace Fitness_core_BE.Controllers
|
||||
{
|
||||
// Staff/owner-facing management of physical access zones (Places) and which fingerprint
|
||||
// terminal (AccessDevice) sits in each. Gated on "memberships" since Places exist to
|
||||
// scope membership-plan access, not bookings.
|
||||
[ApiController]
|
||||
[Route("api/client/places")]
|
||||
public class PlaceController : ControllerBase
|
||||
{
|
||||
private readonly IPlaceService _placeService;
|
||||
|
||||
public PlaceController(IPlaceService placeService)
|
||||
{
|
||||
_placeService = placeService;
|
||||
}
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpGet("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> GetAllPlaces([FromQuery] bool includeInactive = false)
|
||||
=> Response(await _placeService.GetAllPlaces(new { includeInactive }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPost("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreatePlace([FromBody] CreatePlaceRequest request)
|
||||
=> Response(await _placeService.CreatePlace(new
|
||||
{
|
||||
name = request.Name,
|
||||
description = request.Description
|
||||
}, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> UpdatePlace(Guid id, [FromBody] UpdatePlaceRequest request)
|
||||
{
|
||||
var payload = new Dictionary<string, object> { ["placeId"] = id };
|
||||
if (request.Name != null) payload["name"] = request.Name;
|
||||
if (request.Description != null) payload["description"] = request.Description;
|
||||
if (request.IsActive.HasValue) payload["isActive"] = request.IsActive.Value;
|
||||
|
||||
return Response(await _placeService.UpdatePlace(payload, HttpContext));
|
||||
}
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPatch("{id:guid}/status")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> SetPlaceStatus(Guid id, [FromBody] SetPlaceStatusRequest request)
|
||||
=> Response(await _placeService.SetPlaceStatus(new { placeId = id, isActive = request.IsActive }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("memberships")]
|
||||
[HttpPut("{id:guid}/device")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> AssignDevice(Guid id, [FromBody] AssignPlaceDeviceRequest request)
|
||||
=> Response(await _placeService.AssignDevice(new { placeId = id, deviceId = request.DeviceId }, HttpContext));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using Fitness_core_BE.DTOs.RfidTag;
|
||||
using Fitness_core_BE.Helpers;
|
||||
using Fitness_core_BE.Interfaces.Services;
|
||||
using Fitness_core_BE.Models.IOs;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using static Fitness_core_BE.Helpers.JwtMiddleware;
|
||||
using static Fitness_core_BE.Helpers.ApiResponseHelper;
|
||||
|
||||
namespace Fitness_core_BE.Controllers
|
||||
{
|
||||
// Staff-facing RFID tag inventory -- the pool of physical tags handed to a booked party at
|
||||
// check-in (Booking.FKRfidTagId). "InUse" is never staff-settable here, only reached via a
|
||||
// booking check-in/complete.
|
||||
[ApiController]
|
||||
[Route("api/client/rfid-tags")]
|
||||
public class RfidTagController(IRfidTagService rfidTagService) : ControllerBase
|
||||
{
|
||||
private readonly IRfidTagService _rfidTagService = rfidTagService;
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpGet("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> GetAllTags([FromQuery] string? status)
|
||||
=> Response(await _rfidTagService.GetAllTags(new { status }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPost("")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> CreateTag([FromBody] CreateRfidTagRequest request)
|
||||
=> Response(await _rfidTagService.CreateTag(new { tagCode = request.TagCode, label = request.Label }, HttpContext));
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPut("{id:guid}")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> UpdateTag(Guid id, [FromBody] UpdateRfidTagRequest request)
|
||||
{
|
||||
var payload = new Dictionary<string, object> { ["tagId"] = id };
|
||||
if (request.TagCode != null) payload["tagCode"] = request.TagCode;
|
||||
if (request.Label != null) payload["label"] = request.Label;
|
||||
|
||||
return Response(await _rfidTagService.UpdateTag(payload, HttpContext));
|
||||
}
|
||||
|
||||
[CustomMiddleware]
|
||||
[TenantResolution]
|
||||
[RequiresPermission("bookings")]
|
||||
[HttpPatch("{id:guid}/status")]
|
||||
public async Task<ActionResult<ApiResponse<object>>> SetTagStatus(Guid id, [FromBody] SetRfidTagStatusRequest request)
|
||||
=> Response(await _rfidTagService.SetTagStatus(new { tagId = id, status = request.Status }, HttpContext));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user