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 lines4567893 unmodified lines{public Guid UserId { get; set; }public string HabitName { get; set; } = string.Empty;}public class HabitRecordResponseDto3 unmodified lines456789103 unmodified lines{public Guid UserId { get; set; }public string HabitName { get; set; } = string.Empty;public DateTime? CheckedDate { get; set; }}public class HabitRecordResponseDto
5 unmodified lines6789105 unmodified lines{Task<IEnumerable<HabitRecord>> GetAllByUserIdAsync(Guid userId);Task<HabitRecord?> GetTodayRecordAsync(Guid userId, string habitName);}}5 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 lines232425262728291 unmodified line3132333435363722 unmodified linespublic async Task<HabitRecordResponseDto> RecordHabitAsync(CreateHabitRecordDto dto){var existing = await _repo.GetTodayRecordAsync(dto.UserId, dto.HabitName);if (existing is not null) return MapToDto(existing);var record = new HabitRecord1 unmodified lineId = Guid.NewGuid(),UserId = dto.UserId,HabitName = dto.HabitName,CheckedDate = DateTime.UtcNow};var created = await _repo.CreateAsync(record);22 unmodified lines23242526272829301 unmodified line3233343536373822 unmodified linespublic async Task<HabitRecordResponseDto> RecordHabitAsync(CreateHabitRecordDto dto){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 lineId = Guid.NewGuid(),UserId = dto.UserId,HabitName = dto.HabitName,CheckedDate = targetDate};var created = await _repo.CreateAsync(record);
26 unmodified lines272829303126 unmodified linesr.HabitName == habitName &&r.CheckedDate.Date == today);}}}26 unmodified lines27282930313233343536373839404126 unmodified linesr.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