-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into develop
- Loading branch information
Showing
4 changed files
with
83 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ain/java/com/hobak/happinessql/domain/record/application/RecordCalendarDetailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.hobak.happinessql.domain.record.application; | ||
|
||
import com.hobak.happinessql.domain.record.converter.RecordConverter; | ||
import com.hobak.happinessql.domain.record.domain.Record; | ||
import com.hobak.happinessql.domain.record.dto.RecordResponseDto; | ||
import com.hobak.happinessql.domain.record.repository.RecordRepository; | ||
import com.hobak.happinessql.domain.user.application.UserFindService; | ||
import com.hobak.happinessql.domain.user.domain.User; | ||
import com.hobak.happinessql.global.util.TimeConverter; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class RecordCalendarDetailService { | ||
|
||
private final RecordRepository recordRepository; | ||
private final UserFindService userFindService; | ||
|
||
public List<RecordResponseDto> getRecords(String date, Long userId) { | ||
LocalDate dt = TimeConverter.stringToLocalDate(date); | ||
User user = userFindService.findUserById(userId); | ||
List<Record> records = findRecordsBy(dt, user); | ||
return RecordConverter.toRecordResponseDtos(records); | ||
} | ||
|
||
private List<Record> findRecordsBy(LocalDate date, User user) { | ||
LocalDateTime startOfDay = date.atStartOfDay(); | ||
LocalDateTime endOfDay = date.atTime(23, 59); | ||
return recordRepository.findAllByCreatedAtBetweenAndUser(startOfDay, endOfDay, user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/com/hobak/happinessql/global/util/TimeConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.hobak.happinessql.global.util; | ||
|
||
import com.hobak.happinessql.global.exception.GeneralException; | ||
|
||
import java.time.LocalDate; | ||
import java.time.format.DateTimeFormatter; | ||
import java.time.format.DateTimeParseException; | ||
|
||
public class TimeConverter { | ||
public static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd"); | ||
|
||
public static LocalDate stringToLocalDate(String dateString) { | ||
try { | ||
return LocalDate.parse(dateString, formatter); | ||
} catch (DateTimeParseException e) { | ||
throw new GeneralException("Invalid date format. Please use yyyy-MM-dd."); | ||
} | ||
} | ||
} |