-
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: api 설명 수정 * fix: 로그 수정 * fix: 수강 이력 조회 시 studyId를 이용하도록 수정 * fix: valid 어노테이션 제거 * feat: studyId를 dto에 포함 * fix: post 요청으로 변경
- Loading branch information
1 parent
0e1612f
commit 5fc0d43
Showing
8 changed files
with
155 additions
and
3 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
35 changes: 35 additions & 0 deletions
35
src/main/java/com/gdschongik/gdsc/domain/study/api/MentorStudyHistoryController.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,35 @@ | ||
package com.gdschongik.gdsc.domain.study.api; | ||
|
||
import com.gdschongik.gdsc.domain.study.application.MentorStudyHistoryService; | ||
import com.gdschongik.gdsc.domain.study.dto.request.StudyCompleteRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Mentor Study History", description = "멘토 스터디 수강 이력 API입니다.") | ||
@RestController | ||
@RequestMapping("/mentor/study-history") | ||
@RequiredArgsConstructor | ||
public class MentorStudyHistoryController { | ||
|
||
private final MentorStudyHistoryService mentorStudyHistoryService; | ||
|
||
@Operation(summary = "스터디 수료 처리", description = "스터디 수료 처리합니다.") | ||
@PostMapping("/complete") | ||
public ResponseEntity<Void> completeStudy(@RequestBody StudyCompleteRequest request) { | ||
mentorStudyHistoryService.completeStudy(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@Operation(summary = "스터디 수료 철회", description = "스터디 수료 처리를 철회합니다.") | ||
@PostMapping("/withdraw-completion") | ||
public ResponseEntity<Void> withdrawStudyCompletion(@RequestBody StudyCompleteRequest request) { | ||
mentorStudyHistoryService.withdrawStudyCompletion(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
src/main/java/com/gdschongik/gdsc/domain/study/application/MentorStudyHistoryService.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,71 @@ | ||
package com.gdschongik.gdsc.domain.study.application; | ||
|
||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
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.StudyHistory; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyHistoryValidator; | ||
import com.gdschongik.gdsc.domain.study.domain.StudyValidator; | ||
import com.gdschongik.gdsc.domain.study.dto.request.StudyCompleteRequest; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.util.MemberUtil; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class MentorStudyHistoryService { | ||
|
||
private final MemberUtil memberUtil; | ||
private final StudyValidator studyValidator; | ||
private final StudyHistoryValidator studyHistoryValidator; | ||
private final StudyRepository studyRepository; | ||
private final StudyHistoryRepository studyHistoryRepository; | ||
|
||
@Transactional | ||
public void completeStudy(StudyCompleteRequest request) { | ||
Member currentMember = memberUtil.getCurrentMember(); | ||
Study study = | ||
studyRepository.findById(request.studyId()).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); | ||
List<StudyHistory> studyHistories = | ||
studyHistoryRepository.findAllByStudyIdAndStudentIds(request.studyId(), request.studentIds()); | ||
|
||
studyValidator.validateStudyMentor(currentMember, study); | ||
studyHistoryValidator.validateAppliedToStudy( | ||
studyHistories.size(), request.studentIds().size()); | ||
|
||
studyHistories.forEach(StudyHistory::complete); | ||
|
||
log.info( | ||
"[MentorStudyHistoryService] 스터디 수료 처리: studyId={}, studentIds={}", | ||
request.studyId(), | ||
request.studentIds()); | ||
} | ||
|
||
@Transactional | ||
public void withdrawStudyCompletion(StudyCompleteRequest request) { | ||
Member currentMember = memberUtil.getCurrentMember(); | ||
Study study = | ||
studyRepository.findById(request.studyId()).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); | ||
List<StudyHistory> studyHistories = | ||
studyHistoryRepository.findAllByStudyIdAndStudentIds(request.studyId(), request.studentIds()); | ||
|
||
studyValidator.validateStudyMentor(currentMember, study); | ||
studyHistoryValidator.validateAppliedToStudy( | ||
studyHistories.size(), request.studentIds().size()); | ||
|
||
studyHistories.forEach(StudyHistory::withdrawCompletion); | ||
|
||
log.info( | ||
"[MentorStudyHistoryService] 스터디 수료 철회: studyId={}, studentIds={}", | ||
request.studyId(), | ||
request.studentIds()); | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/java/com/gdschongik/gdsc/domain/study/dao/StudyHistoryCustomRepository.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 |
---|---|---|
@@ -1,8 +1,11 @@ | ||
package com.gdschongik.gdsc.domain.study.dao; | ||
|
||
import com.gdschongik.gdsc.domain.study.domain.StudyHistory; | ||
import java.util.List; | ||
|
||
public interface StudyHistoryCustomRepository { | ||
|
||
long countByStudyIdAndStudentIds(Long studyId, List<Long> studentIds); | ||
|
||
List<StudyHistory> findAllByStudyIdAndStudentIds(Long studyId, List<Long> studentIds); | ||
} |
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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/gdschongik/gdsc/domain/study/dto/request/StudyCompleteRequest.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,5 @@ | ||
package com.gdschongik.gdsc.domain.study.dto.request; | ||
|
||
import java.util.List; | ||
|
||
public record StudyCompleteRequest(Long studyId, List<Long> studentIds) {} |
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