first commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
using Fitness_core_BE.Interfaces;
|
||||
using Fitness_core_BE.Models;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Fitness_core_BE.Repos
|
||||
{
|
||||
public class BookingRepository : IBookingRepository
|
||||
{
|
||||
private readonly TenantDbContext _context;
|
||||
|
||||
public BookingRepository(TenantDbContext context)
|
||||
{
|
||||
_context = context;
|
||||
}
|
||||
|
||||
public async Task<Booking> CreateBooking(Booking booking)
|
||||
{
|
||||
booking.BookingId = Guid.NewGuid();
|
||||
booking.CreatedAt = DateTime.UtcNow;
|
||||
|
||||
_context.Bookings.Add(booking);
|
||||
return booking;
|
||||
}
|
||||
|
||||
public Task<Booking?> GetBookingById(Guid bookingId)
|
||||
=> _context.Bookings
|
||||
.Include(b => b.FacilitySession).ThenInclude(s => s.Facility)
|
||||
.FirstOrDefaultAsync(b => b.BookingId == bookingId);
|
||||
|
||||
public Task<Booking?> GetActiveBookingByOtp(string otpCode)
|
||||
=> _context.Bookings
|
||||
.Include(b => b.FacilitySession).ThenInclude(s => s.Facility)
|
||||
.FirstOrDefaultAsync(b => b.OtpCode == otpCode && b.Status == "Confirmed");
|
||||
|
||||
public Task<List<Booking>> GetBookingsForSession(Guid facilitySessionId)
|
||||
=> _context.Bookings
|
||||
.Where(b => b.FKFacilitySessionId == facilitySessionId)
|
||||
.OrderBy(b => b.BookedAt)
|
||||
.ToListAsync();
|
||||
|
||||
public Task<List<Booking>> GetBookingsForCustomer(Guid customerId)
|
||||
=> _context.Bookings
|
||||
.Include(b => b.FacilitySession).ThenInclude(s => s.Facility)
|
||||
.Where(b => b.FKCustomerId == customerId)
|
||||
.OrderByDescending(b => b.BookedAt)
|
||||
.ToListAsync();
|
||||
|
||||
public Task<bool> CustomerHasActiveBookingForSession(Guid facilitySessionId, Guid customerId)
|
||||
=> _context.Bookings.AnyAsync(b =>
|
||||
b.FKFacilitySessionId == facilitySessionId &&
|
||||
b.FKCustomerId == customerId &&
|
||||
b.Status != "Cancelled");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user