Kavita/API/Data/Repositories/EmailHistoryRepository.cs
Joe Milazzo 9f29fa593d
Progress Overhaul + Profile Page and a LOT more! (#4262)
Co-authored-by: Amelia <77553571+Fesaa@users.noreply.github.com>
Co-authored-by: Robbie Davis <robbie@therobbiedavis.com>
2025-12-09 10:00:11 -07:00

37 lines
942 B
C#

using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using API.DTOs.Email;
using API.Helpers;
using AutoMapper;
using AutoMapper.QueryableExtensions;
using Microsoft.EntityFrameworkCore;
namespace API.Data.Repositories;
public interface IEmailHistoryRepository
{
Task<IList<EmailHistoryDto>> GetEmailDtos(UserParams userParams);
}
public class EmailHistoryRepository : IEmailHistoryRepository
{
private readonly DataContext _context;
private readonly IMapper _mapper;
public EmailHistoryRepository(DataContext context, IMapper mapper)
{
_context = context;
_mapper = mapper;
}
public async Task<IList<EmailHistoryDto>> GetEmailDtos(UserParams userParams)
{
return await _context.EmailHistory
.OrderByDescending(h => h.SendDate)
.ProjectTo<EmailHistoryDto>(_mapper.ConfigurationProvider)
.ToListAsync();
}
}