| | | 1 | | using LifeChart.Application.DTOs; |
| | | 2 | | using LifeChart.Domain.Entries; |
| | | 3 | | using LifeChart.Domain.Services; |
| | | 4 | | |
| | | 5 | | namespace LifeChart.Application.UseCases.Entries; |
| | | 6 | | |
| | | 7 | | public class SaveDailyEntryUseCase |
| | | 8 | | { |
| | | 9 | | private readonly IDailyEntryRepository _repository; |
| | | 10 | | private readonly CrisisThresholdService _crisisService; |
| | | 11 | | |
| | 9 | 12 | | public SaveDailyEntryUseCase( |
| | 9 | 13 | | IDailyEntryRepository repository, |
| | 9 | 14 | | CrisisThresholdService crisisService) |
| | | 15 | | { |
| | 9 | 16 | | _repository = repository; |
| | 9 | 17 | | _crisisService = crisisService; |
| | 9 | 18 | | } |
| | | 19 | | |
| | 15 | 20 | | public record Result(bool IsCritical); |
| | | 21 | | |
| | | 22 | | public async Task<Result> ExecuteAsync(DailyEntryDto dto) |
| | | 23 | | { |
| | 9 | 24 | | var entry = new DailyEntry( |
| | 9 | 25 | | dto.Date, |
| | 9 | 26 | | new MoodScore(dto.Mood), |
| | 9 | 27 | | new FunctionalityScore(dto.Functionality), |
| | 9 | 28 | | new SleepHours(dto.SleepHours), |
| | 9 | 29 | | dto.MedicationTaken, |
| | 9 | 30 | | dto.MenstrualCycle, |
| | 9 | 31 | | dto.Symptoms, |
| | 9 | 32 | | dto.Notes, |
| | 9 | 33 | | dto.IsHypomanic); |
| | | 34 | | |
| | 8 | 35 | | await _repository.SaveAsync(entry); |
| | 8 | 36 | | return new Result(_crisisService.IsCritical(entry)); |
| | 8 | 37 | | } |
| | | 38 | | } |