Skip to content

Commit

Permalink
Merge pull request #200 from Gamegoo-repo/fix/199
Browse files Browse the repository at this point in the history
[Fix/199] ์ฑ„ํŒ… ๋ฉ”์†Œ๋“œ ํ…Œ์ŠคํŠธ ์‹คํŒจ ์ผ€์ด์Šค ์ˆ˜์ •
  • Loading branch information
Eunjin3395 authored Sep 2, 2024
2 parents 2e3fd18 + 21357cc commit 5b87445
Showing 1 changed file with 37 additions and 4 deletions.
41 changes: 37 additions & 4 deletions src/main/java/com/gamegoo/service/chat/ChatCommandService.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.gamegoo.apiPayload.code.status.ErrorStatus;
import com.gamegoo.apiPayload.exception.handler.ChatHandler;
import com.gamegoo.apiPayload.exception.handler.MemberHandler;
import com.gamegoo.converter.ChatConverter;
import com.gamegoo.domain.board.Board;
import com.gamegoo.domain.chat.Chat;
Expand Down Expand Up @@ -83,7 +84,11 @@ public ChatResponse.ChatroomEnterDTO startChatroomByMemberId(Long memberId,
.map(existingChatroom -> enterExistingChatroom(member, targetMember,
existingChatroom, null))// ๊ธฐ์กด ์ฑ„ํŒ…๋ฐฉ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์ฑ„ํŒ…๋ฐฉ์— ์ž…์žฅ
.orElseGet(() -> {
// ๊ธฐ์กด์— ์ฑ„ํŒ…๋ฐฉ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ: ์ƒˆ ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ
// ๊ธฐ์กด์— ์ฑ„ํŒ…๋ฐฉ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ: ์ƒ๋Œ€๋ฐฉ์˜ ์ฐจ๋‹จ ์—ฌ๋ถ€ ๊ฒ€์ฆ
MemberUtils.validateBlocked(targetMember, member,
ErrorStatus.BLOCKED_BY_CHAT_TARGET_CHAT_START_FAILED);

// ์ƒˆ ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ
Chatroom newChatroom = createNewChatroom(member, targetMember, null);
return ChatroomEnterDTO.builder()
.uuid(newChatroom.getUuid())
Expand Down Expand Up @@ -133,8 +138,11 @@ public ChatResponse.ChatroomEnterDTO startChatroomByBoardId(Long memberId, Long
.map(exitChatroom -> enterExistingChatroom(member, targetMember,
exitChatroom, board.getId())) // ๊ธฐ์กด ์ฑ„ํŒ…๋ฐฉ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ, ํ•ด๋‹น ์ฑ„ํŒ…๋ฐฉ์— ์ž…์žฅ ๋ฐ system ๊ฐ’ ํฌํ•จ
.orElseGet(() -> {
// ๊ธฐ์กด์— ์ฑ„ํŒ…๋ฐฉ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ: ์ƒˆ ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ
// ๊ธฐ์กด์— ์ฑ„ํŒ…๋ฐฉ์ด ์กด์žฌํ•˜์ง€ ์•Š๋Š” ๊ฒฝ์šฐ: ์ƒ๋Œ€๋ฐฉ์˜ ์ฐจ๋‹จ ์—ฌ๋ถ€ ๊ฒ€์ฆ
MemberUtils.validateBlocked(targetMember, member,
ErrorStatus.BLOCKED_BY_CHAT_TARGET_CHAT_START_FAILED);

// ์ƒˆ ์ฑ„ํŒ…๋ฐฉ ์ƒ์„ฑ
Chatroom newChatroom = createNewChatroom(member, targetMember, null);
// ์‹œ์Šคํ…œ ๋ฉ”์‹œ์ง€ ๊ธฐ๋Šฅ์„ ์œ„ํ•œ SystemFlagDTO ์ƒ์„ฑ
ChatResponse.SystemFlagDTO systemFlagDTO = ChatResponse.SystemFlagDTO.builder()
Expand Down Expand Up @@ -172,6 +180,21 @@ public String startChatroomByMatching(Long memberId1, Long memberId2) {
Member member1 = profileService.findMember(memberId1);
Member member2 = profileService.findMember(memberId2);

// ๋Œ€์ƒ ํšŒ์›์˜ ํƒˆํ‡ด ์—ฌ๋ถ€ ๊ฒ€์ฆ
if (member2.getBlind()) {
throw new MemberHandler(ErrorStatus.USER_DEACTIVATED);
}

// ๋‚ด๊ฐ€ ์ƒ๋Œ€๋ฅผ ์ฐจ๋‹จํ•œ ๊ฒฝ์šฐ
if (MemberUtils.isBlocked(member1, member2)) {
throw new ChatHandler(ErrorStatus.CHAT_TARGET_IS_BLOCKED_CHAT_START_FAILED);
}

// ์ƒ๋Œ€๊ฐ€ ๋‚˜๋ฅผ ์ฐจ๋‹จํ•œ ๊ฒฝ์šฐ
if (MemberUtils.isBlocked(member2, member1)) {
throw new ChatHandler(ErrorStatus.BLOCKED_BY_CHAT_TARGET_CHAT_START_FAILED);
}

Chatroom chatroom = chatroomRepository
.findChatroomByMemberIds(member1.getId(), member2.getId())
.map(existingChatroom -> updateLastJoinDateWithOutSocket(member1, member2,
Expand Down Expand Up @@ -237,10 +260,14 @@ public Chat addChat(ChatRequest.ChatCreateRequest request, String chatroomUuid,
memberId, chatroom.getId())
.orElseThrow(() -> new ChatHandler(ErrorStatus.CHATROOM_ACCESS_DENIED));

// ํšŒ์› ๊ฐ„ ์ฐจ๋‹จ ์—ฌ๋ถ€ ๊ฒ€์ฆ
// ํšŒ์› ๊ฐ„ ์ฐจ๋‹จ ์—ฌ๋ถ€ ๋ฐ ํƒˆํ‡ด ์—ฌ๋ถ€ ๊ฒ€์ฆ
// ๋Œ€ํ™” ์ƒ๋Œ€ ํšŒ์› ์กฐํšŒ
Member targetMember = memberChatroomRepository.findTargetMemberByChatroomIdAndMemberId(
chatroom.getId(), memberId);
// ์ƒ๋Œ€ ํƒˆํ‡ด ์—ฌ๋ถ€ ๊ฒ€์ฆ
if (targetMember.getBlind()) {
throw new MemberHandler(ErrorStatus.USER_DEACTIVATED);
}
MemberUtils.validateBlocked(member, targetMember,
ErrorStatus.CHAT_TARGET_IS_BLOCKED_SEND_CHAT_FAILED);
MemberUtils.validateBlocked(targetMember, member,
Expand Down Expand Up @@ -552,8 +579,14 @@ private ChatResponse.ChatroomEnterDTO enterExistingChatroom(Member member, Membe
ChatResponse.ChatMessageListDTO chatMessageListDTO = ChatConverter.toChatMessageListDTO(
recentChats);

ChatResponse.SystemFlagDTO systemFlagDTO;
// ์‹œ์Šคํ…œ ํ”Œ๋ž˜๊ทธ ์ƒ์„ฑ, boardId๊ฐ€ null์ธ ๊ฒฝ์šฐ systemFlagDTO๋„ null
ChatResponse.SystemFlagDTO systemFlagDTO = createSystemFlagDTO(memberChatroom, boardId);
// ์ƒ๋Œ€๊ฐ€ ๋‚˜๋ฅผ ์ฐจ๋‹จํ•œ ๊ฒฝ์šฐ boardId null์„ ์ „๋‹ฌํ•ด systemFlagDTO null๋กœ ์„ค์ •
if (MemberUtils.isBlocked(targetMember, member)) {
systemFlagDTO = createSystemFlagDTO(memberChatroom, null);
} else {
systemFlagDTO = createSystemFlagDTO(memberChatroom, boardId);
}

return ChatroomEnterDTO.builder()
.uuid(chatroom.getUuid())
Expand Down

0 comments on commit 5b87445

Please sign in to comment.