Spaces:
Running
Running
Download FlowAPI.Infrastructure/Repositories/HabitRecordRepository.cs from DanilDrotik/FlowAPI: direct link, hf CLI and curl.
- Browser
- Download file 1.44 kB
-
https://huggingface.co/spaces/DanilDrotik/FlowAPI/resolve/c8301b4e0f289c0e69fa026bb49f7828aec1850d/FlowAPI.Infrastructure/Repositories/HabitRecordRepository.cs
- Command line
-
hf download hf://spaces/DanilDrotik/FlowAPI@c8301b4e0f289c0e69fa026bb49f7828aec1850d/FlowAPI.Infrastructure/Repositories/HabitRecordRepository.cs
-
curl -L -o HabitRecordRepository.cs https://huggingface.co/spaces/DanilDrotik/FlowAPI/resolve/c8301b4e0f289c0e69fa026bb49f7828aec1850d/FlowAPI.Infrastructure/Repositories/HabitRecordRepository.cs
1.44 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); | |
| } | |
| public async Task<HabitRecord?> GetRecordForDateAsync(Guid userId, string habitName, DateTime date) | |
| { | |
| var targetDate = date.Date; | |
| return await _dbSet | |
| .FirstOrDefaultAsync(r => | |
| r.UserId == userId && | |
| r.HabitName == habitName && | |
| r.CheckedDate.Date == targetDate); | |
| } | |
| } | |
| } | |