Skip to content

Commit

Permalink
fix: 스터디 공지 조회 API 역할 검증 로직 제거 (#768)
Browse files Browse the repository at this point in the history
fix: 스터디 공지 조회 api 역할 검증 로직 제거
  • Loading branch information
Sangwook02 authored Sep 5, 2024
1 parent 076bc66 commit e9e4c62
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,19 @@

import static com.gdschongik.gdsc.global.exception.ErrorCode.*;

import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.domain.study.dao.AssignmentHistoryRepository;
import com.gdschongik.gdsc.domain.study.dao.AttendanceRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyAnnouncementRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyHistoryRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyRepository;
import com.gdschongik.gdsc.domain.study.domain.Study;
import com.gdschongik.gdsc.domain.study.domain.StudyAnnouncement;
import com.gdschongik.gdsc.domain.study.domain.StudyHistory;
import com.gdschongik.gdsc.domain.study.domain.StudyValidator;
import com.gdschongik.gdsc.domain.study.dto.response.CommonStudyResponse;
import com.gdschongik.gdsc.domain.study.dto.response.StudyAnnouncementResponse;
import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.global.util.MemberUtil;
import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
Expand All @@ -44,12 +41,6 @@ public CommonStudyResponse getStudyInformation(Long studyId) {

@Transactional(readOnly = true)
public List<StudyAnnouncementResponse> getStudyAnnouncements(Long studyId) {
Member currentMember = memberUtil.getCurrentMember();
final Study study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND));
Optional<StudyHistory> studyHistory = studyHistoryRepository.findByStudentAndStudyId(currentMember, studyId);

studyValidator.validateStudyMentorOrStudent(currentMember, study, studyHistory);

final List<StudyAnnouncement> studyAnnouncements =
studyAnnouncementRepository.findAllByStudyIdOrderByCreatedAtDesc(studyId);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.gdschongik.gdsc.domain.member.domain.Member;
import com.gdschongik.gdsc.global.annotation.DomainService;
import com.gdschongik.gdsc.global.exception.CustomException;
import java.util.Optional;

@DomainService
public class StudyValidator {
Expand All @@ -25,21 +24,4 @@ public void validateStudyMentor(Member currentMember, Study study) {
throw new CustomException(STUDY_MENTOR_INVALID);
}
}

public void validateStudyMentorOrStudent(Member currentMember, Study study, Optional<StudyHistory> studyHistory) {
// 어드민인 경우 검증 통과
if (currentMember.isAdmin()) {
return;
}

// 해당 스터디의 수강생인지 검증
if (currentMember.isStudent() && studyHistory.isEmpty()) {
throw new CustomException(STUDY_ACCESS_NOT_ALLOWED);
}

// 해당 스터디의 담당 멘토인지 검증
if (!currentMember.getId().equals(study.getMentor().getId())) {
throw new CustomException(STUDY_MENTOR_INVALID);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.gdschongik.gdsc.global.exception.CustomException;
import com.gdschongik.gdsc.helper.FixtureHelper;
import java.time.LocalDateTime;
import java.util.Optional;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;

Expand Down Expand Up @@ -89,45 +88,4 @@ class 스터디_멘토역할_검증시 {
.doesNotThrowAnyException();
}
}

@Nested
class 스터디_멘토_또는_학생역할_검증시 {

@Test
void 수강하지않는_스터디가_아니라면_실패한다() {
// given
Member student = createMember(1L);
Member mentor = createMentor(2L);
LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1);
Study study = fixtureHelper.createStudy(
mentor,
Period.createPeriod(assignmentCreatedDate.plusDays(5), assignmentCreatedDate.plusDays(10)),
Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate));
StudyHistory studyHistory = null;

// when & then
assertThatThrownBy(() -> studyValidator.validateStudyMentorOrStudent(
student, study, Optional.ofNullable(studyHistory)))
.isInstanceOf(CustomException.class)
.hasMessage(STUDY_ACCESS_NOT_ALLOWED.getMessage());
}

@Test
void 멘토이지만_자신이_맡은_스터디가_아니라면_실패한다() {
// given
Member currentMember = createMentor(1L);
Member mentor = createMentor(2L);
LocalDateTime assignmentCreatedDate = LocalDateTime.now().minusDays(1);
Study study = fixtureHelper.createStudy(
mentor,
Period.createPeriod(assignmentCreatedDate.plusDays(5), assignmentCreatedDate.plusDays(10)),
Period.createPeriod(assignmentCreatedDate.minusDays(5), assignmentCreatedDate));

// when & then
assertThatThrownBy(
() -> studyValidator.validateStudyMentorOrStudent(currentMember, study, Optional.empty()))
.isInstanceOf(CustomException.class)
.hasMessage(STUDY_MENTOR_INVALID.getMessage());
}
}
}

0 comments on commit e9e4c62

Please sign in to comment.