Skip to content

Commit

Permalink
Merge pull request #29 from Timetris-Trendithon/past
Browse files Browse the repository at this point in the history
♻️Refactor: λ°˜λ³΅λ˜λŠ” μœ μ €ν™•μΈ μ½”λ“œ λ©”μ†Œλ“œν™”
  • Loading branch information
Zena0128 authored Feb 22, 2024
2 parents ec22fcc + ff9288d commit d353cc7
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ public List<PastViewDTO> readPastsAll(long userId) {
LocalDate localDate = LocalDate.now();
int year = localDate.getYear();
int month = localDate.getMonth().getValue();
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
findUser(userId);
List<Date> dateList = dateRepository.findAllByYearAndMonth(year, month);
List<PastViewDTO> result = new ArrayList<>();
dateList.forEach(date -> {
Expand All @@ -52,8 +51,7 @@ public List<PastViewDTO> readPastsAll(long userId) {
public PastViewDTO readPast(long userId, String date) {
DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern("yyyyλ…„MMμ›”dd일"); // ex.2024λ…„02μ›”21일
LocalDate localDate = LocalDate.parse(date, dateTimeFormatter);
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
findUser(userId);
Date date1 = dateRepository.findByDate(localDate);
if (date1 == null){
throw new CustomException(ErrorStatus.PDS_NOT_FOUND_ERROR);
Expand All @@ -70,8 +68,7 @@ public List<PastViewDTO> readPathsMonthAll(long userId, String month) {
String[] strings = month.split("-");
int year = Integer.parseInt(strings[0]);
int localMonth = Integer.parseInt(strings[1]);
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
findUser(userId);
List<Date> dateList = dateRepository.findAllByYearAndMonth(year, localMonth);
List<PastViewDTO> result = new ArrayList<>();
dateList.forEach(date -> {
Expand All @@ -84,5 +81,10 @@ public List<PastViewDTO> readPathsMonthAll(long userId, String month) {
return result;
}

public void findUser(long userId){
User user = userRepository.findById(userId)
.orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR));
}


}

0 comments on commit d353cc7

Please sign in to comment.