From cdfc85dadeda5e9e856cc5a4654186ac1838c25f Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Sun, 3 Mar 2024 20:29:34 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[chore]=20#35=20=EC=9C=A0=ED=9A=A8=ED=95=98?= =?UTF-8?q?=EC=A7=80=20=EC=95=8A=EC=9D=80=20=EB=A9=A4=EB=B2=84=20=ED=83=80?= =?UTF-8?q?=EC=9E=85=20=EB=A9=94=EC=84=B8=EC=A7=80=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/harang/server/dto/type/ErrorMessage.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/java/org/harang/server/dto/type/ErrorMessage.java b/src/main/java/org/harang/server/dto/type/ErrorMessage.java index 03032a7..8b4ac5e 100644 --- a/src/main/java/org/harang/server/dto/type/ErrorMessage.java +++ b/src/main/java/org/harang/server/dto/type/ErrorMessage.java @@ -50,6 +50,7 @@ public enum ErrorMessage { ONLY_SPROUT_CAN_CREATE_MATCH("50005", HttpStatus.INTERNAL_SERVER_ERROR, "새싹인 유저만 매칭을 생성할 수 있습니다."), ONLY_WATERING_CAN_HELP_SPROUT("50006", HttpStatus.INTERNAL_SERVER_ERROR, "물뿌리개인 유저만 새싹을 도와줄 수 있습니다."), CHAT_ALREADY_STARTED("50007", HttpStatus.INTERNAL_SERVER_ERROR, "이미 채팅을 시작한 게시글입니다."), + INVALID_MEMBER_TYPE("50008", HttpStatus.INTERNAL_SERVER_ERROR, "유효하지 않은 사용자 타입입니다."), ; private String code; From 6be5cf6a73bd9d5d2de56092a866cb341b139b93 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Sun, 3 Mar 2024 20:31:15 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[feat]=20#35=20memberId=EB=A1=9C=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/org/harang/server/repository/PostRepository.java | 2 ++ .../java/org/harang/server/repository/WaitingRepository.java | 2 ++ 2 files changed, 4 insertions(+) diff --git a/src/main/java/org/harang/server/repository/PostRepository.java b/src/main/java/org/harang/server/repository/PostRepository.java index fcb5104..026a447 100644 --- a/src/main/java/org/harang/server/repository/PostRepository.java +++ b/src/main/java/org/harang/server/repository/PostRepository.java @@ -13,4 +13,6 @@ default Post findByIdOrThrow(Long id) { } List findByTitleIsContaining(String title); + + List findAllByMemberId(Long memberId); } diff --git a/src/main/java/org/harang/server/repository/WaitingRepository.java b/src/main/java/org/harang/server/repository/WaitingRepository.java index 36f55b2..fa8a6ba 100644 --- a/src/main/java/org/harang/server/repository/WaitingRepository.java +++ b/src/main/java/org/harang/server/repository/WaitingRepository.java @@ -9,4 +9,6 @@ @Repository public interface WaitingRepository extends JpaRepository { List findAllByPostId(Long postId); + + List findAllByMemberId(Long memberId); } From 2c96f7018547022ffd0fa5e72aee8d6330d3c3b3 Mon Sep 17 00:00:00 2001 From: nykoh2001 Date: Sun, 3 Mar 2024 20:32:25 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[feat]=20#35=20=EC=B1=84=ED=8C=85=20?= =?UTF-8?q?=EB=AA=A9=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../server/controller/ChatController.java | 24 +++++++++++++++++ .../harang/server/service/PostService.java | 26 +++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/org/harang/server/controller/ChatController.java diff --git a/src/main/java/org/harang/server/controller/ChatController.java b/src/main/java/org/harang/server/controller/ChatController.java new file mode 100644 index 0000000..ceaeae1 --- /dev/null +++ b/src/main/java/org/harang/server/controller/ChatController.java @@ -0,0 +1,24 @@ +package org.harang.server.controller; + +import lombok.RequiredArgsConstructor; +import org.harang.server.annotation.MemberId; +import org.harang.server.dto.common.ApiResponse; +import org.harang.server.service.PostService; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequestMapping("/v1/chats") +@RequiredArgsConstructor +public class ChatController { + // 엔드포인트 고려하여 새로운 컨트롤러 생성 + + private final PostService postService; + + @GetMapping + public ApiResponse getChattings(@MemberId Long memberId) { + // 사용자가 참여한 채팅방 목록을 조회 + return ApiResponse.success(postService.getChattings(memberId)); + } +} diff --git a/src/main/java/org/harang/server/service/PostService.java b/src/main/java/org/harang/server/service/PostService.java index e266d2c..02c4ce6 100644 --- a/src/main/java/org/harang/server/service/PostService.java +++ b/src/main/java/org/harang/server/service/PostService.java @@ -5,8 +5,11 @@ import lombok.RequiredArgsConstructor; import org.harang.server.domain.*; import org.harang.server.domain.enums.Status; +import org.harang.server.domain.enums.Type; import org.harang.server.dto.request.PostRequest; import org.harang.server.dto.response.PostResponse; +import org.harang.server.dto.type.ErrorMessage; +import org.harang.server.exception.CustomException; import org.harang.server.repository.*; import org.hibernate.event.spi.PostDeleteEventListener; import org.springframework.stereotype.Service; @@ -26,6 +29,7 @@ public class PostService { private final CategoryRepository categoryRepository; private final LocationRepository locationRepository; private final PostCategoryRepository postCategoryRepository; + private final WaitingRepository waitingRepository; @Transactional public Post createPost(Long memberId, PostRequest request) { @@ -111,4 +115,26 @@ public List getRecommendedPosts() { .map(p -> PostResponse.of(p)) .toList(); } + + public List getChattings(Long memberId) { + // 사용자가 물뿌리개인 경우 - 매칭 대기 리스트의 게시글 조회 + // 사용자가 새싹인 경우 - 자신이 작성한 게시글 조회 + + Member member = memberRepository.findByIdOrThrow(memberId); + Type type = member.getType(); + List posts; + + if (type.equals(Type.SPROUT)) { + // 자신이 작성한 게시글 조회 + posts = postRepository.findAllByMemberId(memberId); + } else if ((type.equals(Type.WATERING))) { + // 자신이 매칭 대기 중인 게시글 조회 + List myWaitings = waitingRepository.findAllByMemberId(memberId); + posts = myWaitings.stream().map(w -> w.getPost()).toList(); + } else { + throw new CustomException(ErrorMessage.INVALID_MEMBER_TYPE); + } + + return posts.stream().map(p -> PostResponse.of(p)).toList(); + } }