Skip to content

Commit

Permalink
MATE-105 : [FEAT] 메이트 채팅방 매핑 url 변경 (#94)
Browse files Browse the repository at this point in the history
  • Loading branch information
MisaSohee authored Dec 6, 2024
1 parent fdbd6c0 commit ac00bfe
Showing 1 changed file with 27 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -22,54 +24,55 @@
public class MateChatRoomController {
private final MateChatRoomService chatRoomService;

@PostMapping("/post/{matePostId}")
@PostMapping("/post/{matePostId}/join")
@Operation(summary = "메이트 게시글 -> 채팅방 생성/입장", description = "메이트 게시글 페이지에서 채팅방으로 입장")
public ResponseEntity<ApiResponse<MateChatRoomResponse>> 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<ApiResponse<PageResponse<MateChatRoomListResponse>>> getMyChatRooms(
@Parameter(description = "페이지 정보") @PageableDefault Pageable pageable,
@AuthenticationPrincipal AuthMember member

) {
PageResponse<MateChatRoomListResponse> response = chatRoomService.getMyChatRooms(member.getMemberId(), pageable);
return ResponseEntity.ok(ApiResponse.success(response));
}

@PostMapping("chat/{chatroomId}/join")
@Operation(summary = "내 채팅방 목록 -> 채팅방 입장", description = "채팅 목록 페이지에서 채팅방으로 입장")
public ResponseEntity<ApiResponse<MateChatRoomResponse>> 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<ApiResponse<PageResponse<MateChatMessageResponse>>> 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<MateChatMessageResponse> messages = chatRoomService.getChatMessages(chatroomId, memberId, pageable);
PageResponse<MateChatMessageResponse> messages = chatRoomService.getChatMessages(chatroomId, member.getMemberId(), pageable);
return ResponseEntity.ok(ApiResponse.success(messages));
}

@GetMapping("/me")
@Operation(summary = "내 채팅방 목록 조회", description = "사용자의 채팅방 목록을 조회합니다.")
public ResponseEntity<ApiResponse<PageResponse<MateChatRoomListResponse>>> getMyChatRooms(
@Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId, // 추후 @AuthenticationPrincipal로 대체
@Parameter(description = "페이지 정보") @PageableDefault Pageable pageable
) {
PageResponse<MateChatRoomListResponse> response = chatRoomService.getMyChatRooms(memberId, pageable);
return ResponseEntity.ok(ApiResponse.success(response));
}

@DeleteMapping("{chatroomId}/leave")
@Operation(summary = "채팅방 나가기", description = "채팅방에서 퇴장합니다.")
public ResponseEntity<Void> 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();
}
}

0 comments on commit ac00bfe

Please sign in to comment.