From ac00bfe70247961ab4775946ae3e3751428acfc6 Mon Sep 17 00:00:00 2001 From: sohee <144431880+MisaSohee@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:50:42 +0900 Subject: [PATCH] =?UTF-8?q?MATE-105=20:=20[FEAT]=20=EB=A9=94=EC=9D=B4?= =?UTF-8?q?=ED=8A=B8=20=EC=B1=84=ED=8C=85=EB=B0=A9=20=EB=A7=A4=ED=95=91=20?= =?UTF-8?q?url=20=EB=B3=80=EA=B2=BD=20(#94)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MateChatRoomController.java | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java b/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java index 08ea4621..7dd0a8b0 100644 --- a/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java +++ b/src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java @@ -2,6 +2,7 @@ import com.example.mate.common.response.ApiResponse; import com.example.mate.common.response.PageResponse; +import com.example.mate.common.security.auth.AuthMember; import com.example.mate.domain.mateChat.dto.response.MateChatMessageResponse; import com.example.mate.domain.mateChat.dto.response.MateChatRoomListResponse; import com.example.mate.domain.mateChat.dto.response.MateChatRoomResponse; @@ -13,6 +14,7 @@ import org.springframework.data.domain.Pageable; import org.springframework.data.web.PageableDefault; import org.springframework.http.ResponseEntity; +import org.springframework.security.core.annotation.AuthenticationPrincipal; import org.springframework.web.bind.annotation.*; @RestController @@ -22,54 +24,55 @@ public class MateChatRoomController { private final MateChatRoomService chatRoomService; - @PostMapping("/post/{matePostId}") + @PostMapping("/post/{matePostId}/join") @Operation(summary = "메이트 게시글 -> 채팅방 생성/입장", description = "메이트 게시글 페이지에서 채팅방으로 입장") public ResponseEntity> createOrJoinChatRoomFromPost( @Parameter(description = "메이트 게시글 ID") @PathVariable Long matePostId, - @Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId + @AuthenticationPrincipal AuthMember member ) { - MateChatRoomResponse response = chatRoomService.createOrJoinChatRoomFromPost(matePostId, memberId); + MateChatRoomResponse response = chatRoomService.createOrJoinChatRoomFromPost(matePostId, member.getMemberId()); return ResponseEntity.ok(ApiResponse.success(response)); } - @PostMapping("/{chatroomId}/join") - @Operation(summary = "채팅방 목록 -> 채팅방 입장", description = "채팅 목록 페이지에서 채팅방으로 입장") + @GetMapping("/me") + @Operation(summary = "내 채팅방 목록 조회", description = "사용자의 채팅방 목록을 조회합니다.") + public ResponseEntity>> getMyChatRooms( + @Parameter(description = "페이지 정보") @PageableDefault Pageable pageable, + @AuthenticationPrincipal AuthMember member + + ) { + PageResponse response = chatRoomService.getMyChatRooms(member.getMemberId(), pageable); + return ResponseEntity.ok(ApiResponse.success(response)); + } + + @PostMapping("chat/{chatroomId}/join") + @Operation(summary = "내 채팅방 목록 -> 채팅방 입장", description = "채팅 목록 페이지에서 채팅방으로 입장") public ResponseEntity> joinExistingChatRoom( @Parameter(description = "채팅방 ID") @PathVariable Long chatroomId, - @Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId + @AuthenticationPrincipal AuthMember member ) { - MateChatRoomResponse response = chatRoomService.joinExistingChatRoom(chatroomId, memberId); + MateChatRoomResponse response = chatRoomService.joinExistingChatRoom(chatroomId, member.getMemberId()); return ResponseEntity.ok(ApiResponse.success(response)); } - @GetMapping("/{chatroomId}/members/{memberId}/messages") - @Operation(summary = "채팅방 메세지 조회", description = "채팅 목록 페이지 -> 채팅방 입장 시, 메시지 내역을 조회합니다.") + @GetMapping("/{chatroomId}/messages") + @Operation(summary = "채팅방 메세지 조회", description = "메시지 내역을 조회합니다.") public ResponseEntity>> getChatMessages( @Parameter(description = "채팅방 ID") @PathVariable Long chatroomId, - @PathVariable Long memberId, - @Parameter(description = "페이지 정보") @PageableDefault Pageable pageable + @AuthenticationPrincipal AuthMember member, + @Parameter(description = "페이지 정보") @PageableDefault(page = 1, size = 20) Pageable pageable ) { - PageResponse messages = chatRoomService.getChatMessages(chatroomId, memberId, pageable); + PageResponse messages = chatRoomService.getChatMessages(chatroomId, member.getMemberId(), pageable); return ResponseEntity.ok(ApiResponse.success(messages)); } - @GetMapping("/me") - @Operation(summary = "내 채팅방 목록 조회", description = "사용자의 채팅방 목록을 조회합니다.") - public ResponseEntity>> getMyChatRooms( - @Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId, // 추후 @AuthenticationPrincipal로 대체 - @Parameter(description = "페이지 정보") @PageableDefault Pageable pageable - ) { - PageResponse response = chatRoomService.getMyChatRooms(memberId, pageable); - return ResponseEntity.ok(ApiResponse.success(response)); - } - @DeleteMapping("{chatroomId}/leave") @Operation(summary = "채팅방 나가기", description = "채팅방에서 퇴장합니다.") public ResponseEntity leaveChatRoom( @Parameter(description = "채팅방 ID") @PathVariable Long chatroomId, - @Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId // 추후 @AuthenticationPrincipal로 대체 + @AuthenticationPrincipal AuthMember member ) { - chatRoomService.leaveChatRoom(chatroomId, memberId); + chatRoomService.leaveChatRoom(chatroomId, member.getMemberId()); return ResponseEntity.noContent().build(); } }