diff --git a/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java b/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java index c84f745f..7f8e4cb9 100644 --- a/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java +++ b/src/main/java/com/team/cklob/gami/domain/chat/repository/ChatRoomRepository.java @@ -1,6 +1,7 @@ package com.team.cklob.gami.domain.chat.repository; import com.team.cklob.gami.domain.chat.entity.ChatRoom; +import com.team.cklob.gami.domain.chat.entity.constant.RoomStatus; import com.team.cklob.gami.domain.member.entity.MemberDetail; import org.springframework.data.repository.query.Param; import org.springframework.data.jpa.repository.JpaRepository; @@ -10,7 +11,7 @@ import java.util.Optional; public interface ChatRoomRepository extends JpaRepository { - boolean existsByMenteeIdAndMentorId(Long menteeId, Long mentorId); + boolean existsByMenteeIdAndMentorIdAndRoomStatus(Long menteeId, Long mentorId, RoomStatus roomStatus); @Query("SELECT CASE WHEN COUNT(cr) > 0 THEN true ELSE false END FROM ChatRoom cr " + "WHERE cr.id = :roomId AND (cr.mentor.id = :memberId OR cr.mentee.id = :memberId)") diff --git a/src/main/java/com/team/cklob/gami/domain/chat/service/impl/CreateChatRoomServiceImpl.java b/src/main/java/com/team/cklob/gami/domain/chat/service/impl/CreateChatRoomServiceImpl.java index dabe5959..dbf7c4b7 100644 --- a/src/main/java/com/team/cklob/gami/domain/chat/service/impl/CreateChatRoomServiceImpl.java +++ b/src/main/java/com/team/cklob/gami/domain/chat/service/impl/CreateChatRoomServiceImpl.java @@ -29,7 +29,7 @@ public class CreateChatRoomServiceImpl implements CreateChatRoomService { @Transactional public void execute(Long applyId, Long menteeId, Long mentorId) { - if (chatRoomRepository.existsByMenteeIdAndMentorId(menteeId, mentorId)) { + if (chatRoomRepository.existsByMenteeIdAndMentorIdAndRoomStatus(menteeId, mentorId, RoomStatus.ACTIVE)) { throw new AlreadyExistChatRoomException(); } Apply apply = applyRepository.findById(applyId) diff --git a/src/main/java/com/team/cklob/gami/domain/member/repository/MemberDetailRepository.java b/src/main/java/com/team/cklob/gami/domain/member/repository/MemberDetailRepository.java index b64f7487..d35045a0 100644 --- a/src/main/java/com/team/cklob/gami/domain/member/repository/MemberDetailRepository.java +++ b/src/main/java/com/team/cklob/gami/domain/member/repository/MemberDetailRepository.java @@ -1,5 +1,6 @@ package com.team.cklob.gami.domain.member.repository; +import com.team.cklob.gami.domain.chat.entity.constant.RoomStatus; import com.team.cklob.gami.domain.member.entity.MemberDetail; import com.team.cklob.gami.domain.member.entity.constant.Major; import org.springframework.data.repository.query.Param; @@ -30,17 +31,36 @@ Page findAllWithFilters( Pageable pageable ); - @Query("SELECT md FROM MemberDetail md JOIN md.member m WHERE " + - "(:major IS NULL OR md.major = :major) AND " + - "(:name IS NULL OR m.name LIKE %:name%) AND " + - "(:generation IS NULL OR md.generation < :generation)") - Page findAllWithFiltersIncludingSeniors( + @Query(""" + SELECT md + FROM MemberDetail md + JOIN md.member m + WHERE + (:major IS NULL OR md.major = :major) + AND (:name IS NULL OR m.name LIKE %:name%) + AND (:generation IS NULL OR md.generation < :generation) + AND m.id <> :memberId + AND NOT EXISTS ( + SELECT 1 + FROM ChatRoom r + WHERE r.roomStatus = :roomStatus + AND ( + (r.mentor.id = :memberId AND r.mentee.id = m.id) + OR + (r.mentor.id = m.id AND r.mentee.id = :memberId) + ) + ) + """) + Page findAllWithFiltersIncludingSeniorsExcludeActiveRoom( @Param("major") Major major, @Param("name") String name, @Param("generation") Integer generation, + @Param("memberId") Long memberId, + @Param("roomStatus") RoomStatus roomStatus, Pageable pageable ); + @Query(value = "SELECT * FROM member_detail md " + "WHERE md.major = :#{#major.name()} " + "AND md.generation < :generation " + diff --git a/src/main/java/com/team/cklob/gami/domain/mentoring/repository/ApplyRepository.java b/src/main/java/com/team/cklob/gami/domain/mentoring/repository/ApplyRepository.java index 2f6e1429..06cc1d8e 100644 --- a/src/main/java/com/team/cklob/gami/domain/mentoring/repository/ApplyRepository.java +++ b/src/main/java/com/team/cklob/gami/domain/mentoring/repository/ApplyRepository.java @@ -10,7 +10,7 @@ public interface ApplyRepository extends JpaRepository { - Boolean existsByMenteeIdAndMentorIdAndApplyStatusIn(Long menteeId, Long mentorId, List applyStatus); + Boolean existsByMenteeIdAndMentorIdAndApplyStatus(Long menteeId, Long mentorId, ApplyStatus applyStatus); @Query("SELECT a FROM Apply a JOIN FETCH a.mentor WHERE a.mentee.id = :menteeId AND a.applyStatus = :applyStatus ORDER BY a.createdAt DESC") List findAllByMenteeIdAndApplyStatusWithMentor(@Param("menteeId") Long menteeId, @Param("applyStatus") ApplyStatus applyStatus); diff --git a/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/GetMentorListServiceImpl.java b/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/GetMentorListServiceImpl.java index db67375d..59543680 100644 --- a/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/GetMentorListServiceImpl.java +++ b/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/GetMentorListServiceImpl.java @@ -1,11 +1,13 @@ package com.team.cklob.gami.domain.mentoring.service.impl; +import com.team.cklob.gami.domain.chat.entity.constant.RoomStatus; import com.team.cklob.gami.domain.member.entity.Member; import com.team.cklob.gami.domain.member.entity.MemberDetail; import com.team.cklob.gami.domain.member.entity.constant.Major; import com.team.cklob.gami.domain.member.repository.MemberDetailRepository; import com.team.cklob.gami.domain.mentoring.dto.response.GetMentorResponse; import com.team.cklob.gami.domain.mentoring.service.GetMentorListService; +import com.team.cklob.gami.global.util.MemberUtil; import lombok.RequiredArgsConstructor; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; @@ -17,6 +19,7 @@ public class GetMentorListServiceImpl implements GetMentorListService { private final MemberDetailRepository memberDetailRepository; + private final MemberUtil memberUtil; @Override @Transactional(readOnly = true) @@ -25,9 +28,10 @@ public Page execute( String name, Integer generation, Pageable pageable) { + Member member = memberUtil.getCurrentMember(); - Page detailsPage = memberDetailRepository.findAllWithFiltersIncludingSeniors( - major, name, generation, pageable + Page detailsPage = memberDetailRepository.findAllWithFiltersIncludingSeniorsExcludeActiveRoom( + major, name, generation, member.getId(), RoomStatus.ACTIVE, pageable ); return detailsPage.map(detail -> { diff --git a/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/MentoringApplyServiceImpl.java b/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/MentoringApplyServiceImpl.java index 9654f94e..0e762217 100644 --- a/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/MentoringApplyServiceImpl.java +++ b/src/main/java/com/team/cklob/gami/domain/mentoring/service/impl/MentoringApplyServiceImpl.java @@ -1,5 +1,6 @@ package com.team.cklob.gami.domain.mentoring.service.impl; +import com.team.cklob.gami.domain.chat.entity.constant.RoomStatus; import com.team.cklob.gami.domain.chat.exception.AlreadyExistChatRoomException; import com.team.cklob.gami.domain.chat.repository.ChatRoomRepository; import com.team.cklob.gami.domain.member.entity.Member; @@ -40,11 +41,11 @@ public MentoringApplyResponse execute(Long mentorId) { throw new SelfApplyNotAllowedException(); } - if (applyRepository.existsByMenteeIdAndMentorIdAndApplyStatusIn(mentee.getId(), mentor.getId(), List.of(ApplyStatus.PENDING, ApplyStatus.ACCEPTED))) { + if (applyRepository.existsByMenteeIdAndMentorIdAndApplyStatus(mentee.getId(), mentor.getId(), ApplyStatus.PENDING)) { throw new AlreadyRegisteredMentorException(); } - if (chatRoomRepository.existsByMenteeIdAndMentorId(mentee.getId(), mentorId)) { + if (chatRoomRepository.existsByMenteeIdAndMentorIdAndRoomStatus(mentee.getId(), mentorId, RoomStatus.ACTIVE)) { throw new AlreadyExistChatRoomException(); } diff --git a/src/main/java/com/team/cklob/gami/global/filter/JwtFilter.java b/src/main/java/com/team/cklob/gami/global/filter/JwtFilter.java index abf1b670..cf1b2207 100644 --- a/src/main/java/com/team/cklob/gami/global/filter/JwtFilter.java +++ b/src/main/java/com/team/cklob/gami/global/filter/JwtFilter.java @@ -37,6 +37,11 @@ protected void doFilterInternal( FilterChain filterChain ) throws ServletException, IOException { + if ("OPTIONS".equalsIgnoreCase(request.getMethod())) { + filterChain.doFilter(request, response); + return; + } + String jwt = tokenParser.resolveToken(request); if (StringUtils.hasText(jwt) && jwtProvider.validateAccessToken(jwt)) { diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index 487e771e..4af53b35 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -58,7 +58,7 @@ app: env: ${APP_ENV:local} cors: - allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:3000,https://port-0-gami-server-mj0rdvda8d11523e.sel3.cloudtype.app, http://localhost:5173, https://cklob-gami.vercel.app} + allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:3000,https://port-0-gami-server-mj0rdvda8d11523e.sel3.cloudtype.app,http://localhost:5173,https://cklob-gami.vercel.app} cloud: aws: