Spaces:
Running
Running
Commit ·
03ee889
1
Parent(s): 0e9dbdf
feat(habits): support custom checked date in backend DTO, repository, and service
Browse filesFiles changed (4)
3 unmodified lines456789103 unmodified lines { public Guid UserId { get; set; } public string HabitName { get; set; } = string.Empty; public DateTime? CheckedDate { get; set; } }
public class HabitRecordResponseDto5 unmodified lines678910115 unmodified lines { Task<IEnumerable<HabitRecord>> GetAllByUserIdAsync(Guid userId); Task<HabitRecord?> GetTodayRecordAsync(Guid userId, string habitName); Task<HabitRecord?> GetRecordForDateAsync(Guid userId, string habitName, DateTime date); }}22 unmodified lines2324252626272829301 unmodified line323334343536373822 unmodified lines
public async Task<HabitRecordResponseDto> RecordHabitAsync(CreateHabitRecordDto dto) { var existing = await _repo.GetTodayRecordAsync(dto.UserId, dto.HabitName); var targetDate = dto.CheckedDate ?? DateTime.UtcNow; var existing = await _repo.GetRecordForDateAsync(dto.UserId, dto.HabitName, targetDate.Date); if (existing is not null) return MapToDto(existing);
var record = new HabitRecord1 unmodified line Id = Guid.NewGuid(), UserId = dto.UserId, HabitName = dto.HabitName, CheckedDate = DateTime.UtcNow CheckedDate = targetDate };
var created = await _repo.CreateAsync(record);26 unmodified lines27282930313233343536373839404126 unmodified lines 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); } }}FlowAPI.Application/DTOs/Habit/HabitDtos.cs+1
FlowAPI.Application/Interfaces/IHabitRecordRepository.cs+1
FlowAPI.Application/Services/HabitService.cs+3-2
FlowAPI.Infrastructure/Repositories/HabitRecordRepository.cs+10