Files
pos-system/services/booking-service-net/src/BookingService.Infrastructure/Repositories/StaffScheduleRepository.cs
Ho Ngoc Hai 4cd172bee5 feat(booking-service): add shop-wide staff schedules endpoint
Add GET /api/v1/schedules?shopId= to return all staff schedules
for a shop. Existing per-staff endpoint unchanged. BFF needs this
to display all schedules on the admin dashboard.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-04 10:36:43 +07:00

59 lines
1.9 KiB
C#

// EN: Repository implementation for StaffSchedule.
// VI: Implementation repository cho StaffSchedule.
using BookingService.Domain.AggregatesModel.StaffAggregate;
using BookingService.Domain.SeedWork;
using Microsoft.EntityFrameworkCore;
namespace BookingService.Infrastructure.Repositories;
public class StaffScheduleRepository : IStaffScheduleRepository
{
private readonly BookingContext _context;
public IUnitOfWork UnitOfWork => _context;
public StaffScheduleRepository(BookingContext context)
{
_context = context ?? throw new ArgumentNullException(nameof(context));
}
public StaffSchedule Add(StaffSchedule schedule)
{
return _context.StaffSchedules.Add(schedule).Entity;
}
public void Update(StaffSchedule schedule)
{
_context.Entry(schedule).State = EntityState.Modified;
}
public void Remove(StaffSchedule schedule)
{
_context.StaffSchedules.Remove(schedule);
}
public async Task<List<StaffSchedule>> GetByStaffIdAsync(Guid staffId, Guid shopId, CancellationToken cancellationToken = default)
{
return await _context.StaffSchedules
.Where(s => s.StaffId == staffId && s.ShopId == shopId)
.ToListAsync(cancellationToken);
}
public async Task<List<StaffSchedule>> GetByShopIdAndDayAsync(Guid shopId, int dayOfWeek, CancellationToken cancellationToken = default)
{
return await _context.StaffSchedules
.Where(s => s.ShopId == shopId && s.DayOfWeek == dayOfWeek)
.ToListAsync(cancellationToken);
}
public async Task<List<StaffSchedule>> GetByShopIdAsync(Guid shopId, CancellationToken cancellationToken = default)
{
return await _context.StaffSchedules
.Where(s => s.ShopId == shopId)
.OrderBy(s => s.StaffId)
.ThenBy(s => s.DayOfWeek)
.ToListAsync(cancellationToken);
}
}