Add PricePerHour to booking requests and update validation logic

This commit is contained in:
2026-09-30 11:41:57 +05:30
parent 7d8a8478ff
commit 6abef835e8
3 changed files with 23 additions and 6 deletions
+2 -1
View File
@@ -78,7 +78,8 @@ namespace Fitness_core_BE.Controllers
durationMinutes = request.DurationMinutes,
guestName = request.GuestName,
guestPhone = request.GuestPhone,
partySize = request.PartySize
partySize = request.PartySize,
pricePerHour = request.PricePerHour
}, HttpContext));
// The actual "copy the link and share it" page -- BookingDto.ShareUrl points here.
+5
View File
@@ -52,6 +52,11 @@ namespace Fitness_core_BE.DTOs.Booking
public string GuestPhone { get; set; } = string.Empty;
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
+16 -5
View File
@@ -164,7 +164,7 @@ namespace Fitness_core_BE.Services
await _uow.BeginAsync();
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));
@@ -202,7 +202,7 @@ namespace Fitness_core_BE.Services
await _uow.BeginAsync();
try
{
var (facility, startTime, endTime, partySize) = await ValidateAdhocRequestAsync(payload);
var (facility, startTime, endTime, partySize, pricePerHour) = await ValidateAdhocRequestAsync(payload);
var data = DeserializePayload.Deserialize(payload);
var guestName = data["guestName"].GetString() ?? throw new ArgumentException("guestName is required");
@@ -223,7 +223,10 @@ namespace Fitness_core_BE.Services
GuestName = guestName,
GuestPhone = guestPhone,
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",
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
/// caller's transaction so two concurrent claims on the same facility serialize instead of
/// 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 facilityId = Guid.Parse(data["facilityId"].GetString()!);
@@ -257,6 +260,14 @@ namespace Fitness_core_BE.Services
? data["partySize"].GetInt32()
: 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)
?? throw new KeyNotFoundException("Facility not found");
if (facility.BookingMode != "AdHoc")
@@ -269,7 +280,7 @@ namespace Fitness_core_BE.Services
if (overlapping >= facility.NumberOfUnits)
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 ----------