Skip to content

Commit

Permalink
refactor: 레포지토리 메서드명 변경
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Oct 9, 2024
1 parent 8d63cdd commit 00352c3
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ public class MentorStudyAchievementService {
public void designateOutstandingStudent(Long studyId, OutstandingStudentRequest request) {
Member currentMember = memberUtil.getCurrentMember();
Study study = studyRepository.getById(studyId);
boolean isAllAppliedToStudy =
studyHistoryRepository.existsByStudyIdAndStudentIds(studyId, request.studentIds());
Long countByStudyIdAndStudentIds =
studyHistoryRepository.countByStudyIdAndStudentIds(studyId, request.studentIds());

studyValidator.validateStudyMentor(currentMember, study);
studyHistoryValidator.validateAppliedToStudy(isAllAppliedToStudy);
studyHistoryValidator.validateAppliedToStudy(
countByStudyIdAndStudentIds, request.studentIds().size());

List<Member> outstandingStudents = memberRepository.findAllById(request.studentIds());
List<StudyAchievement> studyAchievements = outstandingStudents.stream()
Expand All @@ -54,11 +55,12 @@ public void designateOutstandingStudent(Long studyId, OutstandingStudentRequest
public void withdrawOutstandingStudent(Long studyId, OutstandingStudentRequest request) {
Member currentMember = memberUtil.getCurrentMember();
Study study = studyRepository.getById(studyId);
boolean isAllAppliedToStudy =
studyHistoryRepository.existsByStudyIdAndStudentIds(studyId, request.studentIds());
Long countByStudyIdAndStudentIds =
studyHistoryRepository.countByStudyIdAndStudentIds(studyId, request.studentIds());

studyValidator.validateStudyMentor(currentMember, study);
studyHistoryValidator.validateAppliedToStudy(isAllAppliedToStudy);
studyHistoryValidator.validateAppliedToStudy(
countByStudyIdAndStudentIds, request.studentIds().size());

studyAchievementRepository.deleteByStudyAndAchievementTypeAndMemberIds(
studyId, request.achievementType(), request.studentIds());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

public interface StudyHistoryCustomRepository {

boolean existsByStudyIdAndStudentIds(Long studyId, List<Long> studentIds);
Long countByStudyIdAndStudentIds(Long studyId, List<Long> studentIds);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,12 @@ public class StudyHistoryCustomRepositoryImpl implements StudyHistoryCustomRepos
private final JPAQueryFactory queryFactory;

@Override
public boolean existsByStudyIdAndStudentIds(Long studyId, List<Long> studentIds) {
Long count = queryFactory
public Long countByStudyIdAndStudentIds(Long studyId, List<Long> studentIds) {
return queryFactory
.select(studyHistory.count())
.from(studyHistory)
.where(eqStudyId(studyId), studyHistory.student.id.in(studentIds))
.fetchOne();
return count != null && count == studentIds.size();
}

private BooleanExpression eqStudyId(Long studyId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public void validateUpdateRepository(
}
}

public void validateAppliedToStudy(boolean isAllAppliedToStudy) {
if (!isAllAppliedToStudy) {
public void validateAppliedToStudy(Long countStudyHistory, int studentCount) {
if (countStudyHistory != studentCount) {
throw new CustomException(STUDY_HISTORY_NOT_APPLIED_STUDENT_EXISTS);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,13 @@ class 스터디_수강신청_여부_확인시 {

@Test
void 해당_스터디를_신청하지_않은_멤버가_있다면_실패한다() {
// given
Long countStudyHistory = 1L;
int requestStudentCount = 2;

// when & then
assertThatThrownBy(() -> studyHistoryValidator.validateAppliedToStudy(false))
assertThatThrownBy(
() -> studyHistoryValidator.validateAppliedToStudy(countStudyHistory, requestStudentCount))
.isInstanceOf(CustomException.class)
.hasMessage(STUDY_HISTORY_NOT_APPLIED_STUDENT_EXISTS.getMessage());
}
Expand Down

0 comments on commit 00352c3

Please sign in to comment.