49 lines
2.2 KiB
C#
49 lines
2.2 KiB
C#
using Fitness_core_BE.Interfaces;
|
|
using Fitness_core_BE.Models;
|
|
using Microsoft.EntityFrameworkCore;
|
|
|
|
namespace Fitness_core_BE.Repos
|
|
{
|
|
public class CustomerNotificationRepository : ICustomerNotificationRepository
|
|
{
|
|
private readonly CentralDbContext _context;
|
|
public CustomerNotificationRepository(CentralDbContext context) => _context = context;
|
|
|
|
public async Task CreateAsync(CustomerNotification notification, CancellationToken ct = default) =>
|
|
await _context.CustomerNotifications.AddAsync(notification, ct);
|
|
|
|
public async Task CreateManyAsync(IEnumerable<CustomerNotification> notifications, CancellationToken ct = default) =>
|
|
await _context.CustomerNotifications.AddRangeAsync(notifications, ct);
|
|
|
|
public async Task<List<CustomerNotification>> GetByCustomerIdAsync(Guid customerId, CancellationToken ct = default) =>
|
|
await _context.CustomerNotifications
|
|
.AsNoTracking()
|
|
.Where(n => n.FKCustomerId == customerId)
|
|
.OrderByDescending(n => n.CreatedAt)
|
|
.ToListAsync(ct);
|
|
|
|
public async Task<CustomerNotification?> GetByIdAsync(Guid customerNotificationId, Guid customerId, CancellationToken ct = default) =>
|
|
await _context.CustomerNotifications
|
|
.FirstOrDefaultAsync(n => n.CustomerNotificationId == customerNotificationId && n.FKCustomerId == customerId, ct);
|
|
|
|
public async Task<string?> GetCustomerPushTokenAsync(Guid customerId, CancellationToken ct = default) =>
|
|
await _context.Customer
|
|
.AsNoTracking()
|
|
.Where(c => c.CusId == customerId)
|
|
.Select(c => c.PushTokenId)
|
|
.FirstOrDefaultAsync(ct);
|
|
|
|
public async Task<List<string>> GetCustomerPushTokensAsync(IEnumerable<Guid> customerIds, CancellationToken ct = default)
|
|
{
|
|
var ids = customerIds.Distinct().ToList();
|
|
if (ids.Count == 0) return new List<string>();
|
|
|
|
return await _context.Customer
|
|
.AsNoTracking()
|
|
.Where(c => ids.Contains(c.CusId) && c.PushTokenId != null)
|
|
.Select(c => c.PushTokenId!)
|
|
.ToListAsync(ct);
|
|
}
|
|
}
|
|
}
|