-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feat/#28/채팅 비지니스 로직 개선
- Loading branch information
Showing
11 changed files
with
115 additions
and
49 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
27 changes: 15 additions & 12 deletions
27
src/main/java/com/leets/X/domain/chat/controller/ChattingController.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 |
---|---|---|
@@ -1,39 +1,42 @@ | ||
package com.leets.X.domain.chat.controller; | ||
|
||
import com.leets.X.domain.chat.dto.request.GetChatRoomRequestDto; | ||
import com.leets.X.domain.chat.dto.response.ChattingDto; | ||
import com.leets.X.domain.chat.dto.response.ChattingListResponseDto; | ||
import com.leets.X.domain.chat.service.ChattingService; | ||
import com.leets.X.global.common.response.ResponseDto; | ||
import jakarta.validation.Valid; | ||
import jakarta.validation.constraints.NotNull; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
import static com.leets.X.domain.chat.controller.ResponseMessage.GET_CHATROOM; | ||
import static com.leets.X.domain.chat.controller.ResponseMessage.GET_CHATTING_LIST; | ||
import static com.leets.X.domain.chat.controller.ResponseMessage.CHATROOM_GET; | ||
import static com.leets.X.domain.chat.controller.ResponseMessage.CHATTINGLIST_GET; | ||
|
||
@Tag(name="Chatting(ChatMessage)") | ||
@RestController | ||
@RequestMapping("/api/v1") | ||
@RequiredArgsConstructor | ||
public class ChattingController { | ||
|
||
private final ChattingService chattingService; | ||
|
||
// 채팅방 하나를 조회해준다. (대화 내역을 돌려준다는 의미) | ||
@GetMapping("/chatting/{roomId}/{page}/{size}") | ||
public ResponseDto<ChattingDto> findChatting(@PathVariable Long roomId, @PathVariable Integer page, @PathVariable Integer size) { | ||
ChattingDto response = chattingService.getChatRoom(roomId, page, size); | ||
return ResponseDto.response(GET_CHATROOM.getCode(), GET_CHATROOM.getMessage(), response); | ||
@Operation(summary = "하나의 채팅방 + 해당 채팅 내역 조회") | ||
public ResponseDto<ChattingDto> findChatting(@PathVariable Long roomId, @PathVariable Integer page, | ||
@PathVariable Integer size, @AuthenticationPrincipal String email) { | ||
ChattingDto response = chattingService.getChatRoom(roomId, page, size, email); | ||
return ResponseDto.response(CHATROOM_GET.getCode(), CHATROOM_GET.getMessage(), response); | ||
} | ||
|
||
|
||
@GetMapping("/chattingList/{userId}") | ||
public ResponseDto<List<ChattingListResponseDto>> findChattingList(@PathVariable Long userId){ | ||
List<ChattingListResponseDto> response = chattingService.getChattingList(userId); | ||
return ResponseDto.response(GET_CHATTING_LIST.getCode(), GET_CHATTING_LIST.getMessage(), response); | ||
@Operation(summary = "유저가 속한 모든 채팅방 조회") | ||
public ResponseDto<List<ChattingListResponseDto>> findChattingList(@PathVariable Long userId, @AuthenticationPrincipal String email){ | ||
List<ChattingListResponseDto> response = chattingService.getChattingList(userId, email); | ||
return ResponseDto.response(CHATTINGLIST_GET.getCode(), CHATTINGLIST_GET.getMessage(), response); | ||
} | ||
|
||
} |
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
22 changes: 18 additions & 4 deletions
22
src/main/java/com/leets/X/domain/chat/dto/response/ChattingDto.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 |
---|---|---|
@@ -1,12 +1,26 @@ | ||
package com.leets.X.domain.chat.dto.response; | ||
|
||
import com.leets.X.domain.user.domain.User; | ||
|
||
import java.util.List; | ||
|
||
public record ChattingDto( | ||
Long user1Id, | ||
Long user2Id, | ||
String user1Name, | ||
String user2Name, | ||
Long senderId, | ||
String senderName, | ||
|
||
Long opponentId, | ||
String opponentImageUrl, | ||
String opponentName, | ||
|
||
List<ChatMessageResponseDto> chatMessageList | ||
) { | ||
|
||
public static ChattingDto of(User sender, User opponent, List<ChatMessageResponseDto> chatMessageList) { | ||
return new ChattingDto( | ||
sender.getId(), sender.getName(), | ||
opponent.getId(), opponent.getName(), opponent.getImage().getUrl(), | ||
chatMessageList | ||
); | ||
} | ||
|
||
} |
23 changes: 13 additions & 10 deletions
23
src/main/java/com/leets/X/domain/chat/dto/response/ChattingListResponseDto.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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/leets/X/domain/chat/exception/ChatRoomExistException.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,11 @@ | ||
package com.leets.X.domain.chat.exception; | ||
|
||
import com.leets.X.global.common.exception.BaseException; | ||
|
||
import static com.leets.X.domain.chat.exception.ErrorMessage.CHATROOM_EXIST; | ||
|
||
public class ChatRoomExistException extends BaseException { | ||
public ChatRoomExistException() { | ||
super(CHATROOM_EXIST.getCode(),CHATROOM_EXIST.getMessage()); | ||
} | ||
} |
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
4 changes: 2 additions & 2 deletions
4
src/main/java/com/leets/X/domain/chat/exception/NotFoundChatRoomException.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 |
---|---|---|
@@ -1,10 +1,10 @@ | ||
package com.leets.X.domain.chat.exception; | ||
|
||
import com.leets.X.global.common.exception.BaseException; | ||
import static com.leets.X.domain.chat.exception.ErrorMessage.NOT_FOUND_CHATROOM; | ||
import static com.leets.X.domain.chat.exception.ErrorMessage.CHATROOM_NOT_FOUND; | ||
|
||
public class NotFoundChatRoomException extends BaseException { | ||
public NotFoundChatRoomException() { | ||
super(NOT_FOUND_CHATROOM.getCode(), NOT_FOUND_CHATROOM.getMessage()); | ||
super(CHATROOM_NOT_FOUND.getCode(), CHATROOM_NOT_FOUND.getMessage()); | ||
} | ||
} |
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