Skip to content

Commit

Permalink
Merge: develop branch ๋ณ‘ํ•ฉ
Browse files Browse the repository at this point in the history
  • Loading branch information
oueya1479 committed Nov 6, 2023
2 parents 148534c + 12ac6a8 commit 5eb032d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public BaseResponse<ChatRoomCreateResponse> createChatRoom(@ExtractPayload Long
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„์™€์˜ ์—ฐ๊ฒฐ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
})
@PostMapping("/{chatRoomId}")
public BaseResponse<ChatRoomEnterResponse> enterChatRoom(@Parameter(description = "chatroom id", required = true, example = "1")
public BaseResponse<ChatRoomEnterResponse> enterChatRoom(@ExtractPayload Long memId,
@Parameter(description = "chatroom id", required = true, example = "1")
@PathVariable Long chatRoomId) {
return new BaseResponse<>(chatRoomService.enterChatRoom(chatRoomId));
return new BaseResponse<>(chatRoomService.enterChatRoom(memId, chatRoomId));
}

@PreAuthorize("hasRole('USER')")
Expand All @@ -61,11 +62,12 @@ public BaseResponse<ChatRoomEnterResponse> enterChatRoom(@Parameter(description
@ApiResponse(responseCode = "500", description = "์„œ๋ฒ„์™€์˜ ์—ฐ๊ฒฐ์— ์‹คํŒจํ–ˆ์Šต๋‹ˆ๋‹ค.")
})
@PatchMapping("/{chatRoomId}")
public BaseResponse<Long> updateMessage(@Parameter(description = "chatroom id", required = true, example = "1")
public BaseResponse<Long> updateMessage(@ExtractPayload Long memId,
@Parameter(description = "chatroom id", required = true, example = "1")
@PathVariable Long chatRoomId,
@Parameter(description = "message content", required = true, example = "hello")
@RequestBody String message) {
return new BaseResponse<>(chatRoomService.updateMessage(chatRoomId, message));
return new BaseResponse<>(chatRoomService.updateMessage(memId, chatRoomId, message));
}

@PreAuthorize("hasRole('USER')")
Expand Down
11 changes: 7 additions & 4 deletions src/main/java/com/gaseng/chat/service/ChatRoomService.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ public ChatRoomCreateResponse createChatRoom(Long memId, Long shrId) {
);
}

public ChatRoomEnterResponse enterChatRoom(Long chatRoomId) {
public ChatRoomEnterResponse enterChatRoom(Long memId, Long chatRoomId) {
chatRoomFindService.findByMemIdAndChatRoomId(memId, chatRoomId);
ChatRoom chatRoom = chatRoomFindService.findByChatRoomId(chatRoomId);

return new ChatRoomEnterResponse(
Expand All @@ -63,8 +64,10 @@ public ChatRoomEnterResponse enterChatRoom(Long chatRoomId) {
}

@Transactional
public Long updateMessage(Long chatRoomId, String message) {
public Long updateMessage(Long memId, Long chatRoomId, String message) {
chatRoomFindService.findByMemIdAndChatRoomId(memId, chatRoomId);
ChatRoom chatRoom = chatRoomFindService.findByChatRoomId(chatRoomId);

validateActiveChatRoom(chatRoom);
chatRoom.updateMessage(message);

Expand All @@ -76,7 +79,7 @@ public List<ChatRoomListResponse> getChatRoomList(Long memId, int pageSize, Long
List<ChatRoomListQueryProjection> chatRooms = memberChatRoomRepository.findChatRoomsByMemId(memId);

List<ChatRoomListResponse> chatRoomList = chatRooms.stream()
.map(chatRoom -> filterMemberAndFormatTime(member, chatRoom))
.map(chatRoom -> mapChatRoomToResponse(member, chatRoom))
.collect(Collectors.toList());

int lastIndex = getLastIndex(chatRoomList, lastChatRoomId);
Expand Down Expand Up @@ -107,7 +110,7 @@ private void validateActiveChatRoom(ChatRoom chatRoom) {
}
}

private ChatRoomListResponse filterMemberAndFormatTime(Member member, ChatRoomListQueryProjection chatRoom) {
private ChatRoomListResponse mapChatRoomToResponse(Member member, ChatRoomListQueryProjection chatRoom) {
String partnerNickname = filterPartnerNickname(member, chatRoom);
String formattedTime = formatModifiedDate(chatRoom);

Expand Down
3 changes: 3 additions & 0 deletions src/main/java/com/gaseng/member/dto/LoginResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
public record LoginResponse(
@Schema(description = "member id (index)", example = "1")
Long memId,

@Schema(description = "member name", example = "ํ–„๋ฟก์ด")
String memName,

@Schema(description = "member email", example = "example@gmail.com")
String email,
Expand Down
1 change: 1 addition & 0 deletions src/main/java/com/gaseng/member/service/MemberService.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public LoginResponse login(String email, String password) {

return new LoginResponse(
member.getMemId(),
member.getMemName(),
member.getMemEmail().getValue(),
accessToken,
refreshToken,
Expand Down

0 comments on commit 5eb032d

Please sign in to comment.