diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java b/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java index 7457301..00bc106 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/controller/MainPageController.java @@ -23,7 +23,7 @@ public class MainPageController { private final MainPageService mainPageService; private final TokenProvider tokenProvider; - @GetMapping +// @GetMapping public ApiResponse getMainPage(HttpServletRequest request) { Long userId = tokenProvider.getUserId(request); @@ -33,7 +33,7 @@ public ApiResponse getMainPage(HttpServletRequest r return ApiResponse.success(SuccessStatus.OK, mainPageDTO); } - @GetMapping("/test") + @GetMapping("") public ApiResponse getMainPage2(HttpServletRequest request) { Long userId = tokenProvider.getUserId(request); diff --git a/src/main/java/com/trendithon/timetris/domain/mainpage/service/MainPageServiceImpl.java b/src/main/java/com/trendithon/timetris/domain/mainpage/service/MainPageServiceImpl.java index 05fc864..961a216 100644 --- a/src/main/java/com/trendithon/timetris/domain/mainpage/service/MainPageServiceImpl.java +++ b/src/main/java/com/trendithon/timetris/domain/mainpage/service/MainPageServiceImpl.java @@ -33,11 +33,15 @@ public class MainPageServiceImpl implements MainPageService{ public MainPageDTO getMainPage(long userId) { LocalDate localDate = LocalDate.now(); Date date = dateRepository.findByDate(localDate); + User user = userRepository.findById(userId) + .orElseThrow(() -> new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR)); - if (userRepository.findById(userId).isEmpty()){ - throw new CustomException(ErrorStatus.USER_NOT_FOUND_ERROR); - } UserDate userDate = userDateRepository.findByUser_IdAndDate_Id(userId, date.getId()); + if (userDate == null){ + UserDateCreateDTO userDateCreateDTO = new UserDateCreateDTO(user, date); + UserDate userDate1 = new UserDate(userDateCreateDTO); + userDateRepository.save(userDate1); + } List planList = planRepository.findAllByUserDate(userDate); List doList = doRepository.findAllByUserDate(userDate); @@ -63,6 +67,7 @@ public void createUserDate() { DateCreateDTO dateCreateDTO = new DateCreateDTO(localDate); Date date = new Date(dateCreateDTO); dateRepository.save(date); + System.out.println("created Date: "+localDate); users.stream() .forEach(user -> { UserDateCreateDTO userDateCreateDTO = new UserDateCreateDTO(user, date);