Skip to content

Commit

Permalink
MATE-102 : [FEAT] 메이트 채팅방 제약 기능 추가 (#93)
Browse files Browse the repository at this point in the history
* MATE-102 : [FEAT] 메이트 채팅방 에러코드 추가

* MATE-102 : [FEAT] 방장인 경우의 채팅방 입장 제약조건 기능 구현

* MATE-102 : [FEAT] 방장이 채팅방을 나갔을 경우 사용자들 입장 제약 조건 추가

* MATE-102 : [CHORE] import문 정리
  • Loading branch information
MisaSohee authored Dec 6, 2024
1 parent 5d037dd commit fdbd6c0
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/main/java/com/example/mate/common/error/ErrorCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ public enum ErrorCode {
ALREADY_JOINED_CHAT_ROOM(HttpStatus.BAD_REQUEST, "CHAT004", "이미 참여 중인 채팅방입니다."),
CHAT_ROOM_CLOSED(HttpStatus.BAD_REQUEST, "CHAT005", "종료된 채팅방입니다."),
CHAT_ROOM_ACCESS_DENIED(HttpStatus.FORBIDDEN, "CHAT006", "직관 완료된 채팅방에는 새로운 유저가 입장할 수 없습니다."),
CHAT_AUTHOR_JOIN_DENIED(HttpStatus.FORBIDDEN, "CHAT006", "방장은 채팅방 퇴장 시 재입장할 수 없습니다."),
AUTHOR_LEAVE_NOT_ALLOWED(HttpStatus.FORBIDDEN, "CHAT007", "방장은 직관완료가 안된 채팅방에서 나갈 수 없습니다."),
CHAT_ROOM_NOT_MESSAGEABLE(HttpStatus.FORBIDDEN, "CHAT008", "메세지 전송이 불가능한 채팅방입니다."),

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.example.mate.domain.mate.repository;

import com.example.mate.domain.mate.entity.Visit;
import com.example.mate.domain.mate.entity.VisitPart;
import com.example.mate.domain.mate.entity.VisitPartId;
import com.example.mate.domain.member.entity.Member;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface VisitPartRepository extends JpaRepository<VisitPart, VisitPartId> {

int countByMember(Member member);
Expand All @@ -21,5 +21,12 @@ public interface VisitPartRepository extends JpaRepository<VisitPart, VisitPartI
""")
List<Member> findMembersByVisitIdExcludeMember(@Param("visitId") Long visitId, @Param("memberId") Long memberId);

boolean existsByVisitAndMember(Visit visit, Member member);
@Query("""
SELECT COUNT(vp) > 0
FROM VisitPart vp
WHERE vp.visit.id = :visitId
AND vp.member.id = :memberId
""")
boolean existsByVisitAndMember(@Param("visitId") Long visitId, @Param("memberId") Long memberId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ private MateChatRoomResponse processChatRoomJoin(MateChatRoom chatRoom, Member m
}

private void validateChatRoomJoin(MatePost matePost, Member member) {
// 방장인 경우 모든 제한을 건너뜀
// 방장인 경우, 직관 완료 상태가 아닐 때만 입장 가능
if (matePost.getAuthor().getId().equals(member.getId())) {
if (matePost.getStatus() == Status.VISIT_COMPLETE) {
throw new CustomException(ErrorCode.CHAT_AUTHOR_JOIN_DENIED);
}
return;
}

Expand All @@ -120,12 +123,13 @@ private void validateChatRoomJoin(MatePost matePost, Member member) {
}

// 3. 직관 완료 상태인 경우 접근 권한 검증
if (matePost.getStatus() == Status.VISIT_COMPLETE) {
if (matePost.getStatus() == Status.VISIT_COMPLETE && matePost.getVisit() != null) {
boolean isVisitParticipant = visitPartRepository.existsByVisitAndMember(
matePost.getVisit(), member);
boolean isAuthor = matePost.getAuthor().getId().equals(member.getId());
matePost.getVisit().getId(), // Visit 엔티티 대신 ID 전달
member.getId() // Member 엔티티 대신 ID 전달
);

if (!isVisitParticipant && !isAuthor) {
if (!isVisitParticipant) {
throw new CustomException(ErrorCode.CHAT_ROOM_ACCESS_DENIED);
}
}
Expand Down

0 comments on commit fdbd6c0

Please sign in to comment.