FlowAPI / FlowAPI.Infrastructure /Repositories /HabitRecordRepository.cs
danylokhodus's picture
init
b9c7f0e
Raw History Blame
1.06 kB
using FlowAPI.Application.Interfaces;
using FlowAPI.Domain.Entities;
using FlowAPI.Infrastructure.Data;
using Microsoft.EntityFrameworkCore;
namespace FlowAPI.Infrastructure.Repositories
{
public class HabitRecordRepository : GenericRepository<HabitRecord>, IHabitRecordRepository
{
public HabitRecordRepository(AppDbContext context) : base(context) { }
public async Task<IEnumerable<HabitRecord>> GetAllByUserIdAsync(Guid userId)
{
return await _dbSet
.Where(r => r.UserId == userId)
.OrderByDescending(r => r.CheckedDate)
.AsNoTracking()
.ToListAsync();
}
public async Task<HabitRecord?> GetTodayRecordAsync(Guid userId, string habitName)
{
var today = DateTime.UtcNow.Date;
return await _dbSet
.FirstOrDefaultAsync(r =>
r.UserId == userId &&
r.HabitName == habitName &&
r.CheckedDate.Date == today);
}
}
}