Skip to content

Commit

Permalink
feat: 스터디 휴강 처리 api 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
Sangwook02 committed Aug 1, 2024
1 parent 98241bc commit 27409b0
Show file tree
Hide file tree
Showing 10 changed files with 184 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.gdschongik.gdsc.domain.study.api;

import com.gdschongik.gdsc.domain.study.application.StudyMentorService;
import com.gdschongik.gdsc.domain.study.domain.request.AssignmentCreateRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -14,10 +15,19 @@
@RequiredArgsConstructor
public class StudyMentorController {

private final StudyMentorService studyMentorService;

@Operation(summary = "스터디 과제 개설", description = "멘토만 과제를 개설할 수 있습니다.")
@PutMapping("/assignment/{assignmentId}")
public ResponseEntity<Void> createStudyAssignment(
@PathVariable Long assignmentId, @Valid @RequestBody AssignmentCreateRequest request) {
return null;
}

@Operation(summary = "스터디 과제 휴강 처리", description = "해당 주차 과제를 휴강 처리합니다.")
@PatchMapping("/assignment/{studyDetailId}/cancel")
public ResponseEntity<Void> cancelStudyAssignment(@PathVariable Long studyDetailId) {
studyMentorService.cancelStudyAssignment(studyDetailId);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.gdschongik.gdsc.domain.study.application;

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

import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository;
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import com.gdschongik.gdsc.global.exception.CustomException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Slf4j
@Service
@RequiredArgsConstructor
@Transactional(readOnly = true)
public class StudyMentorService {

private final StudyDetailRepository studyDetailRepository;

@Transactional
public void cancelStudyAssignment(Long studyDetailId) {
StudyDetail studyDetail = studyDetailRepository
.findById(studyDetailId)
.orElseThrow(() -> new CustomException(ASSIGNMENT_NOT_FOUND));

studyDetail.cancelAssignment();

log.info("[StudyMentorService] 과제 휴강 처리: studyDetailId={}", studyDetail.getId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,8 @@ public static StudyDetail createStudyDetail(Study study, Long week, String atten
.assignment(Assignment.createEmptyAssignment())
.build();
}

public void cancelAssignment() {
assignment = Assignment.cancelAssignment();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gdschongik.gdsc.domain.study.domain.vo;

import static com.gdschongik.gdsc.domain.study.domain.StudyStatus.*;

import com.gdschongik.gdsc.domain.study.domain.Difficulty;
import com.gdschongik.gdsc.domain.study.domain.StudyStatus;
import jakarta.persistence.Column;
Expand Down Expand Up @@ -46,6 +48,10 @@ private Assignment(
}

public static Assignment createEmptyAssignment() {
return Assignment.builder().status(StudyStatus.NONE).build();
return Assignment.builder().status(NONE).build();
}

public static Assignment cancelAssignment() {
return Assignment.builder().status(CANCELLED).build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@ public enum ErrorCode {

// Order - MoneyInfo
ORDER_FINAL_PAYMENT_AMOUNT_MISMATCH(HttpStatus.CONFLICT, "주문 최종결제금액은 주문총액에서 할인금액을 뺀 값이어야 합니다."),

// Assignment
ASSIGNMENT_NOT_FOUND(HttpStatus.NOT_FOUND, "과제가 존재하지 않습니다."),
;

private final HttpStatus status;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.gdschongik.gdsc.domain.study.application;

import static org.assertj.core.api.Assertions.*;

import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository;
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();
StudyDetail studyDetail = createStudyDetail(now, now.plusDays(7));

// when
studyMentorService.cancelStudyAssignment(studyDetail.getId());

// then
StudyDetail cancelledStudyDetail =
studyDetailRepository.findById(studyDetail.getId()).get();
assertThat(cancelledStudyDetail.getAssignment().getStatus()).isEqualTo(StudyStatus.CANCELLED);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
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();
StudyDetail studyDetail = fixtureHelper.createStudyDetail(
mentor,
Period.createPeriod(now.plusDays(5), now.plusDays(10)),
Period.createPeriod(now.minusDays(5), now),
now,
now.plusDays(7));

// when
studyDetail.cancelAssignment();

// then
assertThat(studyDetail.getAssignment().getStatus()).isEqualTo(StudyStatus.CANCELLED);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ private StudyConstant() {}
public static final DayOfWeek DAY_OF_WEEK = DayOfWeek.FRIDAY;
public static final LocalTime STUDY_START_TIME = LocalTime.of(19, 0, 0);
public static final LocalTime STUDY_END_TIME = LocalTime.of(20, 0, 0);

// StudyDetail
public static final String ATTENDANCE_NUMBER = "1234";
}
8 changes: 8 additions & 0 deletions src/test/java/com/gdschongik/gdsc/helper/FixtureHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.gdschongik.gdsc.domain.recruitment.domain.RoundType;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.study.domain.Study;
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import java.time.LocalDateTime;
import org.springframework.test.util.ReflectionTestUtils;

Expand Down Expand Up @@ -79,4 +80,11 @@ public Study createStudy(Member mentor, Period period, Period applicationPeriod)
STUDY_START_TIME,
STUDY_END_TIME);
}

public StudyDetail createStudyDetail(
Member mentor, Period period, Period applicationPeriod, LocalDateTime startDate, LocalDateTime endDate) {
Study study = createStudy(mentor, period, applicationPeriod);

return StudyDetail.createStudyDetail(study, 1L, ATTENDANCE_NUMBER, Period.createPeriod(startDate, endDate));
}
}
40 changes: 40 additions & 0 deletions src/test/java/com/gdschongik/gdsc/helper/IntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import static com.gdschongik.gdsc.global.common.constant.MemberConstant.*;
import static com.gdschongik.gdsc.global.common.constant.RecruitmentConstant.*;
import static com.gdschongik.gdsc.global.common.constant.SemesterConstant.*;
import static com.gdschongik.gdsc.global.common.constant.StudyConstant.*;
import static org.mockito.Mockito.*;

import com.gdschongik.gdsc.domain.common.model.SemesterType;
Expand All @@ -25,6 +26,10 @@
import com.gdschongik.gdsc.domain.recruitment.domain.RecruitmentRound;
import com.gdschongik.gdsc.domain.recruitment.domain.RoundType;
import com.gdschongik.gdsc.domain.recruitment.domain.vo.Period;
import com.gdschongik.gdsc.domain.study.dao.StudyDetailRepository;
import com.gdschongik.gdsc.domain.study.dao.StudyRepository;
import com.gdschongik.gdsc.domain.study.domain.Study;
import com.gdschongik.gdsc.domain.study.domain.StudyDetail;
import com.gdschongik.gdsc.global.security.PrincipalDetails;
import com.gdschongik.gdsc.infra.feign.payment.client.PaymentClient;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -62,6 +67,12 @@ public abstract class IntegrationTest {
@Autowired
protected RecruitmentRoundRepository recruitmentRoundRepository;

@Autowired
protected StudyRepository studyRepository;

@Autowired
protected StudyDetailRepository studyDetailRepository;

@MockBean
protected OnboardingRecruitmentService onboardingRecruitmentService;

Expand Down Expand Up @@ -160,4 +171,33 @@ protected IssuedCoupon createAndIssue(Money money, Member member) {
IssuedCoupon issuedCoupon = IssuedCoupon.issue(coupon, member);
return issuedCouponRepository.save(issuedCoupon);
}

protected Study createStudy(Member mentor, Period period, Period applicationPeriod) {
Study study = Study.createStudy(
ACADEMIC_YEAR,
SEMESTER_TYPE,
mentor,
period,
applicationPeriod,
TOTAL_WEEK,
ONLINE_STUDY,
DAY_OF_WEEK,
STUDY_START_TIME,
STUDY_END_TIME);

return studyRepository.save(study);
}

protected StudyDetail createStudyDetail(LocalDateTime startDate, LocalDateTime endDate) {
Member mentor = createAssociateMember();
LocalDateTime now = LocalDateTime.now();
Study study = createStudy(
mentor,
Period.createPeriod(now.plusDays(5), now.plusDays(10)),
Period.createPeriod(now.minusDays(5), now));

StudyDetail studyDetail =
StudyDetail.createStudyDetail(study, 1L, ATTENDANCE_NUMBER, Period.createPeriod(startDate, endDate));
return studyDetailRepository.save(studyDetail);
}
}

0 comments on commit 27409b0

Please sign in to comment.