7d8a8478ff
- 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.
186 lines
8.6 KiB
C#
186 lines
8.6 KiB
C#
using Fitness_core_BE.DTOs.Booking;
|
|
using Fitness_core_BE.Helpers;
|
|
using Fitness_core_BE.Interfaces.Services;
|
|
using Fitness_core_BE.Models.IOs;
|
|
using Microsoft.AspNetCore.Authorization;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using static Fitness_core_BE.Helpers.JwtMiddleware;
|
|
using static Fitness_core_BE.Helpers.ApiResponseHelper;
|
|
|
|
namespace Fitness_core_BE.Controllers
|
|
{
|
|
// Booking spans three audiences with very different auth needs, so routes are absolute
|
|
// per-action rather than grouped under one controller-level [Route] prefix: "api/app/..."
|
|
// for logged-in members (same convention as CustomerController), "api/public/..." for a
|
|
// non-member's anonymous guest booking, "api/client/..." for staff (check-in, cancel,
|
|
// session roster, manual payment recording).
|
|
[ApiController]
|
|
public class BookingController : ControllerBase
|
|
{
|
|
private readonly IBookingService _bookingService;
|
|
|
|
public BookingController(IBookingService bookingService)
|
|
{
|
|
_bookingService = bookingService;
|
|
}
|
|
|
|
// ---------- Member (logged-in) ----------
|
|
|
|
[CustomMiddleware]
|
|
[TenantResolution]
|
|
[HttpPost("api/app/bookings")]
|
|
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")]
|
|
public async Task<ActionResult<ApiResponse<object>>> GetMyBookings()
|
|
=> Response(await _bookingService.GetMyBookings(new { }, HttpContext));
|
|
|
|
[CustomMiddleware]
|
|
[TenantResolution]
|
|
[HttpPost("api/app/bookings/{id:guid}/cancel")]
|
|
public async Task<ActionResult<ApiResponse<object>>> CancelMyBooking(Guid id)
|
|
=> Response(await _bookingService.CancelBooking(new { bookingId = id }, HttpContext));
|
|
|
|
// ---------- Guest (no account at all) ----------
|
|
|
|
[AllowAnonymous]
|
|
[HttpPost("api/public/bookings/guest")]
|
|
public async Task<ActionResult<ApiResponse<object>>> CreateGuestBooking([FromBody] CreateGuestBookingRequest request)
|
|
=> Response(await _bookingService.CreateGuestBooking(new
|
|
{
|
|
facilitySessionId = request.FacilitySessionId,
|
|
guestName = request.GuestName,
|
|
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.
|
|
[AllowAnonymous]
|
|
[HttpGet("api/public/bookings/{id:guid}/view")]
|
|
public async Task<ContentResult> ViewBooking(Guid id)
|
|
{
|
|
var booking = await _bookingService.GetBookingView(new { bookingId = id }) as BookingDto;
|
|
if (booking == null)
|
|
return Content(BookingViewHtml.NotFound(), "text/html");
|
|
|
|
return Content(BookingViewHtml.Render(booking), "text/html");
|
|
}
|
|
|
|
// ---------- 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")]
|
|
[HttpGet("api/client/bookings/session/{facilitySessionId:guid}")]
|
|
public async Task<ActionResult<ApiResponse<object>>> GetSessionBookings(Guid facilitySessionId)
|
|
=> Response(await _bookingService.GetSessionBookings(new { facilitySessionId }, HttpContext));
|
|
|
|
[CustomMiddleware]
|
|
[TenantResolution]
|
|
[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, rfidTagId = request.RfidTagId }, HttpContext));
|
|
|
|
[CustomMiddleware]
|
|
[TenantResolution]
|
|
[RequiresPermission("bookings")]
|
|
[HttpPost("api/client/bookings/{id:guid}/mark-paid")]
|
|
public async Task<ActionResult<ApiResponse<object>>> MarkGuestBookingPaid(Guid id, [FromBody] MarkGuestBookingPaidRequest request)
|
|
=> Response(await _bookingService.MarkGuestBookingPaid(new { bookingId = id, amountCharged = request.AmountCharged }, HttpContext));
|
|
|
|
[CustomMiddleware]
|
|
[TenantResolution]
|
|
[RequiresPermission("bookings")]
|
|
[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));
|
|
}
|
|
}
|