From e8ae83ca320b9f4245b462555967dbe08bec5068 Mon Sep 17 00:00:00 2001 From: nohy6630 Date: Wed, 15 May 2024 15:28:05 +0900 Subject: [PATCH] =?UTF-8?q?Feat:=20=EB=A7=88=EC=9D=B4=ED=8E=98=EC=9D=B4?= =?UTF-8?q?=EC=A7=80=20=EC=9D=BC=EC=A0=95=20=EB=AA=A9=EB=A1=9D=20api=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../DirectChatRoomRepositoryCustom.java | 2 ++ .../custom/DirectChatRoomRepositoryImpl.java | 13 +++++++ .../custom/GroupChatRoomRepositoryCustom.java | 4 +++ .../custom/GroupChatRoomRepositoryImpl.java | 26 ++++++++++++++ .../user/controller/UserController.java | 34 +++++++++++++++---- .../user/dto/request/ReadCalenderReq.java | 5 +++ .../user/dto/response/AppointmentRes.java | 2 +- .../user/dto/response/ReadCalenderRes.java | 4 +-- .../domain/user/service/UserService.java | 19 ++++++++++- 9 files changed, 99 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryCustom.java b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryCustom.java index a9daec4..db13a20 100644 --- a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryCustom.java +++ b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryCustom.java @@ -13,4 +13,6 @@ public interface DirectChatRoomRepositoryCustom { List findForUser(User user); List findUpdatableRooms(); + + List findAppointmentForUserInMonth(User who, int year, int month); } diff --git a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryImpl.java b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryImpl.java index b5a74b9..3a064d7 100644 --- a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryImpl.java +++ b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/DirectChatRoomRepositoryImpl.java @@ -47,4 +47,17 @@ public List findUpdatableRooms() { .where(directChatRoom.nextAppointment.appointmentDate.before(LocalDate.now())) .fetch(); } + + @Override + public List findAppointmentForUserInMonth(User who, int year, int month) { + return jpaQueryFactory + .selectFrom(directChatRoom) + .join(directChatRoom.userChatRooms, userChatRoom) + .join(userChatRoom.user, user) + .where(user.eq(who) + .and(directChatRoom.nextAppointment.appointmentDate.year().eq(year)) + .and(directChatRoom.nextAppointment.appointmentDate.month().eq(month))) + .orderBy(directChatRoom.updatedAt.desc()) + .fetch(); + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryCustom.java b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryCustom.java index 85c1a4f..0faca42 100644 --- a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryCustom.java +++ b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryCustom.java @@ -10,4 +10,8 @@ public interface GroupChatRoomRepositoryCustom { List findForUser(User user); List findUpdatableRooms(); + + List findAppointmentForUserInMonth(User who, int year, int month); + + List findActivityForUserInMonth(User who, int year, int month); } diff --git a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryImpl.java b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryImpl.java index 7f762ce..4d79ec7 100644 --- a/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryImpl.java +++ b/src/main/java/com/meetup/teame/backend/domain/chatroom/repository/custom/GroupChatRoomRepositoryImpl.java @@ -39,4 +39,30 @@ public List findUpdatableRooms() { .where(groupChatRoom.nextAppointment.appointmentDate.before(LocalDate.now())) .fetch(); } + + @Override + public List findAppointmentForUserInMonth(User who, int year, int month) { + return jpaQueryFactory + .selectFrom(groupChatRoom) + .join(groupChatRoom.userChatRooms, userChatRoom) + .join(userChatRoom.user, user) + .where(user.eq(who) + .and(groupChatRoom.nextAppointment.appointmentDate.year().eq(year)) + .and(groupChatRoom.nextAppointment.appointmentDate.month().eq(month))) + .orderBy(groupChatRoom.updatedAt.desc()) + .fetch(); + } + + @Override + public List findActivityForUserInMonth(User who, int year, int month) { + return jpaQueryFactory + .selectFrom(groupChatRoom) + .join(groupChatRoom.userChatRooms, userChatRoom) + .join(userChatRoom.user, user) + .where(user.eq(who) + .and(groupChatRoom.activity.time.year().eq(year)) + .and(groupChatRoom.activity.time.month().eq(month))) + .orderBy(groupChatRoom.updatedAt.desc()) + .fetch(); + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java index 1456623..746c3b7 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/controller/UserController.java @@ -1,6 +1,8 @@ package com.meetup.teame.backend.domain.user.controller; import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq; +import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq; +import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes; import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes; import com.meetup.teame.backend.domain.user.service.UserService; import io.swagger.v3.oas.annotations.Operation; @@ -20,9 +22,9 @@ public class UserController { @Operation(summary = "메인 페이지 조회", description = """ 현재 로그인한 유저의 메인 페이지를 조회합니다. - 아직 로그인이 없어서 임시로 고정된 더미 유저의 데이터를 전달하는 식으로 구현되어 있습니다. + 임시로 고정된 더미 유저의 데이터를 전달하는 식으로 구현되어 있습니다. - 추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다. + jwt토큰도 같이 전달해서 요청해주셔야 합니다. """) @GetMapping("/main") public ResponseEntity readMainPage() { @@ -33,18 +35,38 @@ public ResponseEntity readMainPage() { @Operation(summary = "온보딩 정보 등록", description = """ 유저의 온보딩 정보를 등록합니다. - 아직 로그인이 없어서 임시로 고정된 더미 유저의 온보딩 정보를 등록하는 식으로 구현되어 있습니다. + 임시로 고정된 더미 유저의 온보딩 정보를 등록하는 식으로 구현되어 있습니다. + + jwt토큰도 같이 전달해서 요청해주셔야 합니다. - 추후 로그인 적용 시에는 jwt토큰도 같이 전달해서 요청해주셔야 합니다. - 현재 온보딩 정보로 입력 가능한 성격 유형 ("잔잔한", "활발한", "평화로운", "자연친화적인", "창의적인", "학문적인", "예술적인", "배울 수 있는") 위 유형들 중 최소 1개 이상을 선택해서 Request Body에 담아 전송해주세요. """) @PatchMapping("/onboarding") - public ResponseEntity setUserPersonality(@RequestBody @Valid OnboardingReq onboardingReq){ + public ResponseEntity setUserPersonality(@RequestBody @Valid OnboardingReq onboardingReq) { userService.setUserPersonality(onboardingReq); return ResponseEntity .ok().build(); } + + + @Operation(summary = "마이페이지 캘린더 조회", description = """ + 유저의 캘린더 정보를 조회합니다. + + 임시로 고정된 더미 유저의 캘린더 정보를 조회하는 식으로 구현되어 있습니다. + + jwt토큰도 같이 전달해서 요청해주셔야 합니다. + + url 쿼리 파라미터로 다음과 같은 값을 전달해 주셔야 합니다. + + year : 년도 + + month : 월 + """) + @GetMapping("/mypage/calender") + public ResponseEntity readCalender(@ModelAttribute @Valid ReadCalenderReq readCalenderReq) { + return ResponseEntity + .ok(userService.readCalender(readCalenderReq)); + } } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/dto/request/ReadCalenderReq.java b/src/main/java/com/meetup/teame/backend/domain/user/dto/request/ReadCalenderReq.java index 377d371..3d2416a 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/dto/request/ReadCalenderReq.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/dto/request/ReadCalenderReq.java @@ -1,5 +1,7 @@ package com.meetup.teame.backend.domain.user.dto.request; +import io.swagger.v3.oas.annotations.media.Schema; +import jakarta.validation.constraints.Min; import jakarta.validation.constraints.NotBlank; import lombok.AccessLevel; import lombok.AllArgsConstructor; @@ -7,11 +9,14 @@ import lombok.NoArgsConstructor; @NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor @Getter public class ReadCalenderReq { @NotBlank(message="year is required.") + @Schema(example = "2024") private Integer year; @NotBlank(message="month is required.") + @Schema(example = "5") private Integer month; } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/AppointmentRes.java b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/AppointmentRes.java index 2579d4a..a874db1 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/AppointmentRes.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/AppointmentRes.java @@ -45,7 +45,7 @@ public static AppointmentRes ofGroupChatRoom(GroupChatRoom groupChatRoom) { return AppointmentRes.builder() .date(groupChatRoom.getNextAppointment().getAppointmentDate()) .tag(groupChatRoom.getActivity().getTitle()) - .description(groupChatRoom.getNextAppointment().getAppointmentDate() + " 약속") + .description(groupChatRoom.getActivity().getTitle() + " 약속") .about(groupChatRoom.getNextAppointment().getAppointmentLocation()) .build(); } diff --git a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadCalenderRes.java b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadCalenderRes.java index 1e35ab0..1288bb0 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadCalenderRes.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/dto/response/ReadCalenderRes.java @@ -16,9 +16,9 @@ public class ReadCalenderRes { List appointments; - public static ReadCalenderRes of(List groupChatRooms, List directChatRooms) { + public static ReadCalenderRes of(List groupChatRoomsByActivity, List directChatRooms, List groupChatRooms) { List appointments = new ArrayList<>(); - appointments.addAll(groupChatRooms.stream() + appointments.addAll(groupChatRoomsByActivity.stream() .map(AppointmentRes::ofActivity) .toList()); appointments.addAll(directChatRooms.stream() diff --git a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java index 83279bf..9e02c36 100644 --- a/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java +++ b/src/main/java/com/meetup/teame/backend/domain/user/service/UserService.java @@ -2,9 +2,13 @@ import com.meetup.teame.backend.domain.activity.repository.ActivityRepository; import com.meetup.teame.backend.domain.auth.oauth.dto.CreateUserRequest; +import com.meetup.teame.backend.domain.chatroom.repository.DirectChatRoomRepository; +import com.meetup.teame.backend.domain.chatroom.repository.GroupChatRoomRepository; import com.meetup.teame.backend.domain.experience.repository.ExperienceRepository; import com.meetup.teame.backend.domain.personality.Personality; import com.meetup.teame.backend.domain.user.dto.request.OnboardingReq; +import com.meetup.teame.backend.domain.user.dto.request.ReadCalenderReq; +import com.meetup.teame.backend.domain.user.dto.response.ReadCalenderRes; import com.meetup.teame.backend.domain.user.dto.response.ReadMainRes; import com.meetup.teame.backend.domain.user.entity.Gender; import com.meetup.teame.backend.domain.user.entity.User; @@ -28,6 +32,8 @@ public class UserService { private final UserRepository userRepository; private final ActivityRepository activityRepository; private final ExperienceRepository experienceRepository; + private final DirectChatRoomRepository directChatRoomRepository; + private final GroupChatRoomRepository groupChatRoomRepository; public ReadMainRes readMainPage() { //todo 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함 @@ -48,7 +54,7 @@ public User createUser(CreateUserRequest request) { return User.builder() .name(request.getName()) .email(request.getEmail()) - .gender(Objects.equals(request.getGender(), "male") ? Gender.MALE:Gender.FEMALE) + .gender(Objects.equals(request.getGender(), "male") ? Gender.MALE : Gender.FEMALE) .age(age) .location(request.getLocation()) .point(0L) @@ -76,4 +82,15 @@ public void setUserPersonality(OnboardingReq onboardingReq) { .toList(); user.setPersonalities(personalities); } + + public ReadCalenderRes readCalender(ReadCalenderReq readCalenderReq) { + //todo 현재는 더미 유저지만 추후에는 SecurityContextHolder 정보를 조회해서 유저 정보를 가져와야 함 + User user = userRepository.findById(5L) + .orElseThrow(() -> new CustomException(ExceptionContent.NOT_FOUND_USER)); + return ReadCalenderRes.of( + groupChatRoomRepository.findActivityForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth()), + directChatRoomRepository.findAppointmentForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth()), + groupChatRoomRepository.findAppointmentForUserInMonth(user, readCalenderReq.getYear(), readCalenderReq.getMonth()) + ); + } }