Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,7 +11,7 @@
import java.util.Optional;

public interface ChatRoomRepository extends JpaRepository<ChatRoom, Long> {
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)")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -30,17 +31,36 @@ Page<MemberDetail> 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<MemberDetail> 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<MemberDetail> 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 " +
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -17,6 +19,7 @@
public class GetMentorListServiceImpl implements GetMentorListService {

private final MemberDetailRepository memberDetailRepository;
private final MemberUtil memberUtil;

@Override
@Transactional(readOnly = true)
Expand All @@ -25,9 +28,10 @@ public Page<GetMentorResponse> execute(
String name,
Integer generation,
Pageable pageable) {
Member member = memberUtil.getCurrentMember();

Page<MemberDetail> detailsPage = memberDetailRepository.findAllWithFiltersIncludingSeniors(
major, name, generation, pageable
Page<MemberDetail> detailsPage = memberDetailRepository.findAllWithFiltersIncludingSeniorsExcludeActiveRoom(
major, name, generation, member.getId(), RoomStatus.ACTIVE, pageable
);

return detailsPage.map(detail -> {
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -44,7 +45,7 @@ public MentoringApplyResponse execute(Long mentorId) {
throw new AlreadyRegisteredMentorException();
}

if (chatRoomRepository.existsByMenteeIdAndMentorId(mentee.getId(), mentorId)) {
if (chatRoomRepository.existsByMenteeIdAndMentorIdAndRoomStatus(mentee.getId(), mentorId, RoomStatus.ACTIVE)) {
throw new AlreadyExistChatRoomException();
}

Expand Down