class HabitStatisticServiceImpl implements HabitStatisticService {

    @Transactional
    @CacheEvict(value = CacheConstants.HABIT_ITEM_STATISTIC_CACHE, allEntries = true)
    @Override
    public AddHabitStatisticDto save(AddHabitStatisticDto dto) {
        if (habitStatisticRepo.findHabitStatByDate(dto.getCreatedOn(), dto.getHabitId()).isPresent()) {
            throw new NotSavedException(ErrorMessage.HABIT_STATISTIC_ALREADY_EXISTS);
        }
        boolean proceed = isTodayOrYesterday(
            dateService
                .convertToDatasourceTimezone(dto.getCreatedOn())
                .toLocalDate()
        );
        if (proceed) {
            HabitStatistic habitStatistic = modelMapper.map(dto, HabitStatistic.class);
            habitStatistic.setHabit(habitService.getById(dto.getHabitId()));
            return modelMapper.map(habitStatisticRepo.save(habitStatistic), AddHabitStatisticDto.class);
        }
        throw new BadRequestException(ErrorMessage.WRONG_DATE);
    }

    @Autowired public  HabitStatisticServiceImpl(HabitStatisticRepo habitStatisticRepo,
                                     HabitRepo habitRepo,
                                     HabitService habitService, ModelMapper modelMapper,
                                     DateService dateService);

}