-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 스터디 휴강 처리 api 추가 * fix: 엔드포인트 수정 * fix: 에러코드 수정 * refactor: study를 외부에서 받아서 사용하도록 수정 * feat: 현재 멤버의 멘토 여부 검증 추가 * refactor: save 호출하도록 수정 * fix: 시큐리티 설정 추가 * remove: 클래스 레벨 트랜잭셔널 어노테이션 제거 * refactor: 현멤버의 멘토 여부 검증 로직을 메서드로 추출 * refactor: 스터디를 주입받도록 수정
- Loading branch information
1 parent
285e23f
commit 6acc16c
Showing
12 changed files
with
229 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/com/gdschongik/gdsc/domain/study/domain/StudyDetailValidator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.global.annotation.DomainService; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.exception.ErrorCode; | ||
|
||
@DomainService | ||
public class StudyDetailValidator { | ||
|
||
public void validateCancelStudyAssignment(Member currentMember, StudyDetail studyDetail) { | ||
validateMemberIsMentor(currentMember, studyDetail); | ||
} | ||
|
||
// 멘토가 아니라면 과제를 휴강처리 할 수 없다. | ||
private void validateMemberIsMentor(Member member, StudyDetail studyDetail) { | ||
if (!member.equals(studyDetail.getStudy().getMentor())) { | ||
throw new CustomException(ErrorCode.STUDY_DETAIL_NOT_MODIFIABLE_INVALID_ROLE); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/test/java/com/gdschongik/gdsc/domain/study/application/StudyMentorServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.gdschongik.gdsc.domain.study.application; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.member.domain.MemberRole; | ||
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; | ||
import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository; | ||
import com.gdschongik.gdsc.domain.study.domain.Study; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyDetail; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyStatus; | ||
import com.gdschongik.gdsc.helper.IntegrationTest; | ||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
|
||
public class StudyMentorServiceTest extends IntegrationTest { | ||
|
||
@Autowired | ||
private StudyMentorService studyMentorService; | ||
|
||
@Autowired | ||
private StudyDetailRepository studyDetailRepository; | ||
|
||
@Nested | ||
class 스터디_과제_휴강_처리시 { | ||
|
||
@Test | ||
void 성공한다() { | ||
// given | ||
LocalDateTime now = LocalDateTime.now(); | ||
Member mentor = createAssociateMember(); | ||
Study study = createStudy( | ||
mentor, | ||
Period.createPeriod(now.plusDays(5), now.plusDays(10)), | ||
Period.createPeriod(now.minusDays(5), now)); | ||
StudyDetail studyDetail = createStudyDetail(study, now, now.plusDays(7)); | ||
logoutAndReloginAs(studyDetail.getStudy().getMentor().getId(), MemberRole.ASSOCIATE); | ||
|
||
// when | ||
studyMentorService.cancelStudyAssignment(studyDetail.getId()); | ||
|
||
// then | ||
StudyDetail cancelledStudyDetail = | ||
studyDetailRepository.findById(studyDetail.getId()).get(); | ||
assertThat(cancelledStudyDetail.getAssignment().getStatus()).isEqualTo(StudyStatus.CANCELLED); | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyDetailTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; | ||
import com.gdschongik.gdsc.helper.FixtureHelper; | ||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class StudyDetailTest { | ||
|
||
@Nested | ||
class 과제_휴강_처리시 { | ||
|
||
FixtureHelper fixtureHelper = new FixtureHelper(); | ||
|
||
@Test | ||
void 과제_상태가_휴강이_된다() { | ||
// given | ||
Member mentor = fixtureHelper.createAssociateMember(1L); | ||
LocalDateTime now = LocalDateTime.now(); | ||
Study study = fixtureHelper.createStudy( | ||
mentor, | ||
Period.createPeriod(now.plusDays(5), now.plusDays(10)), | ||
Period.createPeriod(now.minusDays(5), now)); | ||
StudyDetail studyDetail = fixtureHelper.createStudyDetail(study, now, now.plusDays(7)); | ||
|
||
// when | ||
studyDetail.cancelAssignment(); | ||
|
||
// then | ||
assertThat(studyDetail.getAssignment().getStatus()).isEqualTo(StudyStatus.CANCELLED); | ||
} | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/java/com/gdschongik/gdsc/domain/study/domain/StudyDetailValidatorTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.gdschongik.gdsc.domain.study.domain; | ||
|
||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.helper.FixtureHelper; | ||
import java.time.LocalDateTime; | ||
import org.junit.jupiter.api.Nested; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class StudyDetailValidatorTest { | ||
|
||
FixtureHelper fixtureHelper = new FixtureHelper(); | ||
StudyDetailValidator studyDetailValidator = new StudyDetailValidator(); | ||
|
||
@Nested | ||
class 과제_휴강_처리시 { | ||
|
||
@Test | ||
void 멘토가_아니라면_실패한다() { | ||
// given | ||
LocalDateTime now = LocalDateTime.now(); | ||
Member mentor = fixtureHelper.createAssociateMember(1L); | ||
Study study = fixtureHelper.createStudy( | ||
mentor, | ||
Period.createPeriod(now.plusDays(5), now.plusDays(10)), | ||
Period.createPeriod(now.minusDays(5), now)); | ||
StudyDetail studyDetail = fixtureHelper.createStudyDetail(study, now, now.plusDays(7)); | ||
Member anotherMember = fixtureHelper.createAssociateMember(2L); | ||
|
||
// when & then | ||
assertThatThrownBy(() -> studyDetailValidator.validateCancelStudyAssignment(anotherMember, studyDetail)) | ||
.isInstanceOf(CustomException.class) | ||
.hasMessage(STUDY_DETAIL_NOT_MODIFIABLE_INVALID_ROLE.getMessage()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters