-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MATE-79 : [FEAT] 메이트 채팅방 기능 구현 (#76)
* MATE-79 : [FEAT] 메이트 채팅방 컨트롤러 구현 * MATE-79 : [FEAT] 메이트 채팅방 서비스 구현 * MATE-79 : [FEAT] 메이트 채팅방 리포지토리 구현 * MATE-79 : [FEAT] 메이트 채팅방 요청 DTO 구현 * MATE-79 : [FEAT] 메이트 채팅방 반환 DTO 구현 * MATE-79 : [FEAT] 메이트 채팅방 엔티티 수정 * MATE-79 : [FEAT] 메이트 채팅방 에러코드 추가 * MATE-79 : [FEAT] 메이트 채팅방 MessageType 구현 * MATE-79 : [FEAT] 메이트 채팅방 테스트용 html 파일 구현 * MATE-79 : [FEAT] 메이트 채팅 목록 반환 컨트롤러 구현 * MATE-79 : [FEAT] 메이트 채팅 목록 반환 서비스 구현 * MATE-79 : [FEAT] 메이트 채팅 목록 반환 리포지토리 구현 * MATE-79 : [FEAT] 메이트 채팅 목록 반환 리포지토리 구현 * MATE-79 : [FEAT] 메이트 채팅 목록 반환 DTO 반환 * MATE-79 : [FEAT] MateChatRoom 엔티티 변환 * MATE-79 : [CHORE] MateChatRoomController 주석 설명 수정 * MATE-79 : [FEAT] 채팅방 반환값 수정 * MATE-79 : [FEAT] 메이트 채팅방 관련 불필요한 기능 제거 * MATE-79 : [FEAT] 메이트 채팅방 반환 DTO 값 추가 * MATE-79 : [FEAT] 메이트 채팅방 요청, 반환 DTO 값 수정 * MATE-79 : [Chore] 메이트 채팅방 import문 수정 및 사용하지 않는 메서드 정리 * MATE-79 : [FEAT] 메이트 채팅방 입장 및 조회 기능 수정 * MATE-79 : [FEAT] 메이트 채팅방 입장 및 조회 기능 수정 * MATE-79 : [CHORE] 메이트 채팅방 입장 및 조회 기능 Swagger 적용 * MATE-79 : [FEAT] 메이트 채팅방 컨트롤러 구현 * MATE-79 : [FEAT] 메이트 채팅방 생성/입장 서비스 구현 * MATE-79 : [FEAT] 메이트 채팅방 메세지 조회 서비스 구현 * MATE-79 : [FEAT] 메이트 채팅방 목록 조회 서비스 구현 * MATE-79 : [FEAT] 메이트 채팅방 컨트롤러 url 수정 * MATE-79 : [FEAT] 메이트 채팅방 메세지 컨트롤러 구현 * MATE-79 : [FEAT] 메이트 채팅방 사용자 엔티티 구현 * MATE-79 : [FEAT] 메이트 채팅방 엔티티 구현 * MATE-79 : [FEAT] 메이트 채팅방 메세지 엔티티 구현 * MATE-79 : [FEAT] 메이트 채팅방 반환 DTO 구현 * MATE-79 : [FEAT] 메이트 채팅방 목록 반환 DTO 구현 * MATE-79 : [FEAT] 메이트 채팅방 메시지 페이지 반환 DTO 구현 * MATE-79 : [FEAT] 메이트 채팅방 메세지 요청 DTO 구현 * MATE-79 : [FEAT] 메이트 채팅방 관련 리포지토리 구현 * MATE-79 : [FEAT] 메이트 채팅방 멤버 관련 리포지토리 구현 * MATE-79 : [FEAT] 메이트 채팅방 메세지 관련 리포지토리 구현 * MATE-79 : [FEAT] 메이트 채팅방 메세지 서비스 구현 * MATE-79 : [FEAT] 메이트 채팅방 관련 에러 메세지 추가 * MATE-79 : [FEAT] 메이트 채팅방 관련 테스트 html * MATE-79 : [FEAT] 메이트 후기 작성 예외처리 제거 * MATE-79 : [CHORE] 미사용 import문 제거
- Loading branch information
Showing
19 changed files
with
1,186 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/mate/domain/mateChat/controller/MateChatMessageController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.example.mate.domain.mateChat.controller; | ||
|
||
import com.example.mate.domain.mateChat.dto.request.MateChatMessageRequest; | ||
import com.example.mate.domain.mateChat.service.MateChatMessageService; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.messaging.handler.annotation.MessageMapping; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.stereotype.Controller; | ||
|
||
@Controller | ||
@RequiredArgsConstructor | ||
public class MateChatMessageController { | ||
private final MateChatMessageService mateChatMessageService; | ||
|
||
@MessageMapping("/chat/mate/message") | ||
public void handleMessage(@Payload @Valid MateChatMessageRequest message) { | ||
mateChatMessageService.sendMessage(message); | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
src/main/java/com/example/mate/domain/mateChat/controller/MateChatRoomController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.example.mate.domain.mateChat.controller; | ||
|
||
import com.example.mate.common.response.ApiResponse; | ||
import com.example.mate.common.response.PageResponse; | ||
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; | ||
import com.example.mate.domain.mateChat.service.MateChatRoomService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/mates/chat") | ||
@Tag(name = "MateChatRoom", description = "메이트 채팅방 관련 API") | ||
public class MateChatRoomController { | ||
private final MateChatRoomService chatRoomService; | ||
|
||
@PostMapping("/post/{matePostId}") | ||
@Operation(summary = "메이트 게시글 -> 채팅방 생성/입장", description = "메이트 게시글 페이지에서 채팅방으로 입장") | ||
public ResponseEntity<ApiResponse<MateChatRoomResponse>> createOrJoinChatRoomFromPost( | ||
@Parameter(description = "메이트 게시글 ID") @PathVariable Long matePostId, | ||
@Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId | ||
) { | ||
MateChatRoomResponse response = chatRoomService.createOrJoinChatRoomFromPost(matePostId, memberId); | ||
return ResponseEntity.ok(ApiResponse.success(response)); | ||
} | ||
|
||
@PostMapping("/{chatroomId}/join") | ||
@Operation(summary = "채팅방 목록 -> 채팅방 입장", description = "채팅 목록 페이지에서 채팅방으로 입장") | ||
public ResponseEntity<ApiResponse<MateChatRoomResponse>> joinExistingChatRoom( | ||
@Parameter(description = "채팅방 ID") @PathVariable Long chatroomId, | ||
@Parameter(description = "회원 ID (삭제 예정)") @RequestParam Long memberId | ||
) { | ||
MateChatRoomResponse response = chatRoomService.joinExistingChatRoom(chatroomId, memberId); | ||
return ResponseEntity.ok(ApiResponse.success(response)); | ||
} | ||
|
||
@GetMapping("/{chatroomId}/members/{memberId}/messages") | ||
@Operation(summary = "채팅방 메세지 조회", description = "채팅 목록 페이지 -> 채팅방 입장 시, 메시지 내역을 조회합니다.") | ||
public ResponseEntity<ApiResponse<PageResponse<MateChatMessageResponse>>> getChatMessages( | ||
@Parameter(description = "채팅방 ID") @PathVariable Long chatroomId, | ||
@PathVariable Long memberId, | ||
@Parameter(description = "페이지 정보") @PageableDefault Pageable pageable | ||
) { | ||
PageResponse<MateChatMessageResponse> messages = chatRoomService.getChatMessages(chatroomId, memberId, 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로 대체 | ||
) { | ||
chatRoomService.leaveChatRoom(chatroomId, memberId); | ||
return ResponseEntity.noContent().build(); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/main/java/com/example/mate/domain/mateChat/dto/request/MateChatMessageRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package com.example.mate.domain.mateChat.dto.request; | ||
|
||
import com.example.mate.domain.mateChat.entity.MateChatMessage; | ||
import com.example.mate.domain.mateChat.entity.MateChatRoom; | ||
import com.example.mate.domain.mateChat.message.MessageType; | ||
import com.example.mate.domain.member.entity.Member; | ||
import jakarta.validation.constraints.NotBlank; | ||
import jakarta.validation.constraints.NotNull; | ||
import lombok.*; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor | ||
public class MateChatMessageRequest { | ||
@NotNull(message = "메시지 타입은 필수입니다.") | ||
private String type; | ||
|
||
@NotNull(message = "채팅방 ID는 필수입니다.") | ||
private Long roomId; | ||
|
||
@NotNull(message = "발신자 ID는 필수입니다.") | ||
private Long senderId; | ||
|
||
@NotBlank(message = "메시지 내용은 필수입니다.") | ||
private String message; | ||
|
||
public static MateChatMessage toEntity(MateChatRoom chatRoom, MateChatMessageRequest request, Member sender) { | ||
return MateChatMessage.builder() | ||
.mateChatRoom(chatRoom) | ||
.sender(sender) | ||
.type(MessageType.valueOf(request.getType())) | ||
.content(request.getMessage()) | ||
.sendTime(LocalDateTime.now()) | ||
.build(); | ||
} | ||
|
||
public static MateChatMessageRequest createEnterMessage(Long roomId, Long senderId, String nickname) { | ||
return MateChatMessageRequest.builder() | ||
.type(MessageType.ENTER.name()) | ||
.roomId(roomId) | ||
.senderId(senderId) | ||
.message(nickname + "님이 들어왔습니다.") | ||
.build(); | ||
} | ||
|
||
public static MateChatMessageRequest createLeaveMessage(Long roomId, Long senderId, String nickname) { | ||
return MateChatMessageRequest.builder() | ||
.type(MessageType.LEAVE.name()) | ||
.roomId(roomId) | ||
.senderId(senderId) | ||
.message(nickname + "님이 나갔습니다.") | ||
.build(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/example/mate/domain/mateChat/dto/response/MateChatMessageResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.example.mate.domain.mateChat.dto.response; | ||
|
||
import com.example.mate.domain.mateChat.entity.MateChatMessage; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
public class MateChatMessageResponse { | ||
private Long messageId; | ||
private Long roomId; | ||
private Long senderId; | ||
private String senderNickname; | ||
private String message; | ||
private String messageType; | ||
private String senderImageUrl; | ||
private LocalDateTime sendTime; | ||
|
||
public static MateChatMessageResponse of(MateChatMessage message) { | ||
return MateChatMessageResponse.builder() | ||
.messageId(message.getId()) | ||
.roomId(message.getMateChatRoom().getId()) | ||
.senderId(message.getSender().getId()) | ||
.senderNickname(message.getSender().getNickname()) | ||
.message(message.getContent()) | ||
.messageType(message.getType().getValue()) | ||
.senderImageUrl(message.getSender().getImageUrl()) | ||
.sendTime(message.getSendTime()) | ||
.build(); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
src/main/java/com/example/mate/domain/mateChat/dto/response/MateChatRoomListResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package com.example.mate.domain.mateChat.dto.response; | ||
|
||
import com.example.mate.domain.mateChat.entity.MateChatRoom; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
@Getter | ||
@Builder | ||
public class MateChatRoomListResponse { | ||
private Long roomId; | ||
private Long postId; | ||
private String postImageUrl; | ||
private String postTitle; | ||
private String lastMessageContent; | ||
private LocalDateTime lastMessageTime; | ||
private Integer currentMembers; | ||
private Boolean isActive; | ||
private Boolean isMessageable; | ||
private Boolean isAuthorLeft; | ||
private Boolean isAuthor; | ||
|
||
public static MateChatRoomListResponse from(MateChatRoom chatRoom, boolean isAuthor) { | ||
return MateChatRoomListResponse.builder() | ||
.roomId(chatRoom.getId()) | ||
.postId(chatRoom.getMatePost().getId()) | ||
.postImageUrl(chatRoom.getMatePost().getImageUrl()) | ||
.postTitle(chatRoom.getMatePost().getTitle()) | ||
.lastMessageContent(chatRoom.getLastChatContent()) | ||
.lastMessageTime(chatRoom.getLastChatSentAt()) | ||
.currentMembers(chatRoom.getCurrentMembers()) | ||
.isActive(chatRoom.getIsActive()) | ||
.isMessageable(chatRoom.getIsMessageable()) | ||
.isAuthorLeft(chatRoom.getIsAuthorLeft()) | ||
.isAuthor(isAuthor) | ||
.build(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/example/mate/domain/mateChat/dto/response/MateChatRoomResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package com.example.mate.domain.mateChat.dto.response; | ||
|
||
import com.example.mate.common.response.PageResponse; | ||
import com.example.mate.domain.mateChat.entity.MateChatRoom; | ||
import com.example.mate.domain.mateChat.entity.MateChatRoomMember; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
public class MateChatRoomResponse { | ||
private Long roomId; | ||
private Long matePostId; | ||
private Long memberId; | ||
private Integer currentMembers; | ||
private Boolean isRoomActive; | ||
private Boolean isMessageable; | ||
private Boolean isAuthorLeft; | ||
private Boolean isAuthor; | ||
private PageResponse<MateChatMessageResponse> initialMessages; | ||
|
||
public static MateChatRoomResponse from( | ||
MateChatRoom chatRoom, | ||
MateChatRoomMember member, | ||
PageResponse<MateChatMessageResponse> messages) { | ||
return MateChatRoomResponse.builder() | ||
.roomId(chatRoom.getId()) | ||
.matePostId(chatRoom.getMatePost().getId()) | ||
.memberId(member.getMember().getId()) | ||
.currentMembers(chatRoom.getCurrentMembers()) | ||
.isRoomActive(chatRoom.getIsActive()) | ||
.isMessageable(chatRoom.getIsMessageable()) | ||
.isAuthorLeft(chatRoom.getIsAuthorLeft()) | ||
.isAuthor(chatRoom.getMatePost().getAuthor().getId().equals(member.getMember().getId())) | ||
.initialMessages(messages) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.