Add PricePerHour to booking requests and update validation logic
This commit is contained in:
@@ -78,7 +78,8 @@ namespace Fitness_core_BE.Controllers
|
|||||||
durationMinutes = request.DurationMinutes,
|
durationMinutes = request.DurationMinutes,
|
||||||
guestName = request.GuestName,
|
guestName = request.GuestName,
|
||||||
guestPhone = request.GuestPhone,
|
guestPhone = request.GuestPhone,
|
||||||
partySize = request.PartySize
|
partySize = request.PartySize,
|
||||||
|
pricePerHour = request.PricePerHour
|
||||||
}, HttpContext));
|
}, HttpContext));
|
||||||
|
|
||||||
// The actual "copy the link and share it" page -- BookingDto.ShareUrl points here.
|
// The actual "copy the link and share it" page -- BookingDto.ShareUrl points here.
|
||||||
|
|||||||
@@ -52,6 +52,11 @@ namespace Fitness_core_BE.DTOs.Booking
|
|||||||
public string GuestPhone { get; set; } = string.Empty;
|
public string GuestPhone { get; set; } = string.Empty;
|
||||||
|
|
||||||
public int? PartySize { get; set; }
|
public int? PartySize { get; set; }
|
||||||
|
|
||||||
|
/// <summary>Overrides the facility's own PricePerHour for this booking's charge only --
|
||||||
|
/// the FE pre-fills this from the facility but lets staff adjust it.</summary>
|
||||||
|
[Range(typeof(decimal), "0", "79228162514264337593543950335", ErrorMessage = "PricePerHour cannot be negative")]
|
||||||
|
public decimal? PricePerHour { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MarkGuestBookingPaidRequest
|
public class MarkGuestBookingPaidRequest
|
||||||
|
|||||||
@@ -164,7 +164,7 @@ namespace Fitness_core_BE.Services
|
|||||||
await _uow.BeginAsync();
|
await _uow.BeginAsync();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var (facility, startTime, endTime, partySize) = await ValidateAdhocRequestAsync(payload);
|
var (facility, startTime, endTime, partySize, _) = await ValidateAdhocRequestAsync(payload);
|
||||||
|
|
||||||
var cusId = await _userRoleHelper.GetCusId(DataExtractor.GetUserIdFromContext(httpContext));
|
var cusId = await _userRoleHelper.GetCusId(DataExtractor.GetUserIdFromContext(httpContext));
|
||||||
|
|
||||||
@@ -202,7 +202,7 @@ namespace Fitness_core_BE.Services
|
|||||||
await _uow.BeginAsync();
|
await _uow.BeginAsync();
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var (facility, startTime, endTime, partySize) = await ValidateAdhocRequestAsync(payload);
|
var (facility, startTime, endTime, partySize, pricePerHour) = await ValidateAdhocRequestAsync(payload);
|
||||||
|
|
||||||
var data = DeserializePayload.Deserialize(payload);
|
var data = DeserializePayload.Deserialize(payload);
|
||||||
var guestName = data["guestName"].GetString() ?? throw new ArgumentException("guestName is required");
|
var guestName = data["guestName"].GetString() ?? throw new ArgumentException("guestName is required");
|
||||||
@@ -223,7 +223,10 @@ namespace Fitness_core_BE.Services
|
|||||||
GuestName = guestName,
|
GuestName = guestName,
|
||||||
GuestPhone = guestPhone,
|
GuestPhone = guestPhone,
|
||||||
OtpCode = GenerateOtp(),
|
OtpCode = GenerateOtp(),
|
||||||
AmountCharged = Math.Round(facility.PricePerHour * durationHours, 2),
|
// Staff can override the facility's default rate per booking (e.g. a discount)
|
||||||
|
// -- the pre-filled suggestion in the FE comes from facility.PricePerHour, but
|
||||||
|
// the charge actually uses whatever rate was submitted.
|
||||||
|
AmountCharged = Math.Round((pricePerHour ?? facility.PricePerHour) * durationHours, 2),
|
||||||
PaymentStatus = "Unpaid",
|
PaymentStatus = "Unpaid",
|
||||||
Status = "Confirmed"
|
Status = "Confirmed"
|
||||||
};
|
};
|
||||||
@@ -244,7 +247,7 @@ namespace Fitness_core_BE.Services
|
|||||||
/// requested window must have a free unit. Locks the facility row for the duration of the
|
/// requested window must have a free unit. Locks the facility row for the duration of the
|
||||||
/// caller's transaction so two concurrent claims on the same facility serialize instead of
|
/// caller's transaction so two concurrent claims on the same facility serialize instead of
|
||||||
/// both reading "room available" before either commits.</summary>
|
/// both reading "room available" before either commits.</summary>
|
||||||
private async Task<(Facility facility, DateTime startTime, DateTime endTime, int? partySize)> ValidateAdhocRequestAsync(object payload)
|
private async Task<(Facility facility, DateTime startTime, DateTime endTime, int? partySize, decimal? pricePerHour)> ValidateAdhocRequestAsync(object payload)
|
||||||
{
|
{
|
||||||
var data = DeserializePayload.Deserialize(payload);
|
var data = DeserializePayload.Deserialize(payload);
|
||||||
var facilityId = Guid.Parse(data["facilityId"].GetString()!);
|
var facilityId = Guid.Parse(data["facilityId"].GetString()!);
|
||||||
@@ -257,6 +260,14 @@ namespace Fitness_core_BE.Services
|
|||||||
? data["partySize"].GetInt32()
|
? data["partySize"].GetInt32()
|
||||||
: null;
|
: null;
|
||||||
|
|
||||||
|
// Optional per-booking rate override -- the FE pre-fills this from the facility's
|
||||||
|
// own PricePerHour but lets staff adjust it (e.g. a discount) before charging.
|
||||||
|
decimal? pricePerHour = data.ContainsKey("pricePerHour") && data["pricePerHour"].ValueKind != JsonValueKind.Null
|
||||||
|
? data["pricePerHour"].GetDecimal()
|
||||||
|
: null;
|
||||||
|
if (pricePerHour.HasValue && pricePerHour.Value < 0)
|
||||||
|
throw new ArgumentException("pricePerHour cannot be negative");
|
||||||
|
|
||||||
var facility = await _facilityRepository.GetFacilityById(facilityId)
|
var facility = await _facilityRepository.GetFacilityById(facilityId)
|
||||||
?? throw new KeyNotFoundException("Facility not found");
|
?? throw new KeyNotFoundException("Facility not found");
|
||||||
if (facility.BookingMode != "AdHoc")
|
if (facility.BookingMode != "AdHoc")
|
||||||
@@ -269,7 +280,7 @@ namespace Fitness_core_BE.Services
|
|||||||
if (overlapping >= facility.NumberOfUnits)
|
if (overlapping >= facility.NumberOfUnits)
|
||||||
throw new ArgumentException("No units are free for the requested time");
|
throw new ArgumentException("No units are free for the requested time");
|
||||||
|
|
||||||
return (facility, startTime, endTime, partySize);
|
return (facility, startTime, endTime, partySize, pricePerHour);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---------- Payment / check-in / lifecycle ----------
|
// ---------- Payment / check-in / lifecycle ----------
|
||||||
|
|||||||
Reference in New Issue
Block a user