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
Expand Up @@ -3,12 +3,22 @@
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 com.gamzabat.algohub.feature.group.studygroup.domain.JoinRequest;

public interface JoinRequestRepository extends JpaRepository<JoinRequest, Long> {

boolean existsByGroup_IdAndRequester_Id(Long groupId, Long userId);

List<JoinRequest> findAllByGroup_Id(Long groupId);
@Query("""
select jr
from JoinRequest jr
join fetch jr.requester u
join fetch jr.group g
where g.id = :groupId
""")
List<JoinRequest> findAllByGroupIdWithFetch(@Param("groupId") Long groupId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Service;
Expand Down Expand Up @@ -59,12 +58,15 @@ public void joinRequest(User user, Long groupId) {
@Transactional(readOnly = true)
public List<JoinRequest> getAllJoinRequests(User user, Long groupId) {
StudyGroup studyGroup = studyGroupRepository.findById(groupId)
.orElseThrow(() -> new StudyGroupValidationException(HttpStatus.NOT_FOUND.value(), "존재하지 않는 그룹 입니다."));
Optional<GroupMember> groupMember = groupMemberRepository.findByUserAndStudyGroup(user, studyGroup);
if (groupMember.isPresent() && RoleOfGroupMember.isParticipant(groupMember.get()) || groupMember.isEmpty()) {
.orElseThrow(() -> new StudyGroupValidationException(
HttpStatus.NOT_FOUND.value(), "존재하지 않는 그룹 입니다."));
final boolean noAuthority = groupMemberRepository.findByUserAndStudyGroup(user, studyGroup)
.map(RoleOfGroupMember::isParticipant)
.orElse(true);
if (noAuthority) {
Comment on lines +63 to +66

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

여기 리팩토링은 이유가 따로 있으신가유?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

가독성 말고는 없습니다!

throw new JoinRequestException("요청 목록을 조회할 권한이 없습니다.");
}
return joinRequestRepository.findAllByGroup_Id(groupId);
return joinRequestRepository.findAllByGroupIdWithFetch(groupId);
}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class JoinRequestServiceTest {
private NotificationSettingRepository notificationSettingRepository;
@Mock
private RankingRepository rankingRepository;

private User user, owner, user2, user3, requester;
private StudyGroup group;
private Problem problem1, problem2;
Expand Down Expand Up @@ -200,7 +200,7 @@ void getAllJoinRequests_Success() {
// given
when(studyGroupRepository.findById(10L)).thenReturn(Optional.of(group));
when(groupMemberRepository.findByUserAndStudyGroup(owner, group)).thenReturn(Optional.of(ownerGroupmember));
when(joinRequestRepository.findAllByGroup_Id(10L)).thenReturn(List.of(joinRequest));
when(joinRequestRepository.findAllByGroupIdWithFetch(10L)).thenReturn(List.of(joinRequest));

// when
List<JoinRequest> requests = joinRequestService.getAllJoinRequests(owner, 10L);
Expand Down
Loading