-
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.
- Loading branch information
Showing
27 changed files
with
471 additions
and
80 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
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
39 changes: 39 additions & 0 deletions
39
src/main/java/com/gdschongik/gdsc/domain/studyv2/api/MentorStudyAchievementControllerV2.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,39 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.api; | ||
|
||
import com.gdschongik.gdsc.domain.study.dto.request.OutstandingStudentRequest; | ||
import com.gdschongik.gdsc.domain.studyv2.application.MentorStudyAchievementServiceV2; | ||
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.DeleteMapping; | ||
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.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Mentor StudyAchievement V2", description = "멘토 스터디 우수 스터디원 관리 V2 API입니다.") | ||
@RestController | ||
@RequestMapping("/v2/mentor/study-achievements") | ||
@RequiredArgsConstructor | ||
public class MentorStudyAchievementControllerV2 { | ||
|
||
private final MentorStudyAchievementServiceV2 mentorStudyAchievementService; | ||
|
||
@Operation(summary = "우수 스터디원 지정", description = "우수 스터디원으로 지정합니다.") | ||
@PostMapping | ||
public ResponseEntity<Void> designateOutstandingStudent( | ||
@RequestParam(name = "studyId") Long studyId, @RequestBody OutstandingStudentRequest request) { | ||
mentorStudyAchievementService.designateOutstandingStudent(studyId, request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
|
||
@Operation(summary = "우수 스터디원 철회", description = "우수 스터디원 지정을 철회합니다.") | ||
@DeleteMapping | ||
public ResponseEntity<Void> withdrawOutstandingStudent( | ||
@RequestParam(name = "studyId") Long studyId, @RequestBody OutstandingStudentRequest request) { | ||
mentorStudyAchievementService.withdrawOutstandingStudent(studyId, request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/gdschongik/gdsc/domain/studyv2/api/StudentStudyHistoryControllerV2.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,29 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.api; | ||
|
||
import com.gdschongik.gdsc.domain.studyv2.application.StudentStudyHistoryServiceV2; | ||
import com.gdschongik.gdsc.domain.studyv2.dto.request.StudyHistoryRepositoryUpdateRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "Student Study History V2", description = "학생 스터디 수강이력 API입니다.") | ||
@RestController | ||
@RequestMapping("/v2/study-histories") | ||
@RequiredArgsConstructor | ||
public class StudentStudyHistoryControllerV2 { | ||
|
||
private final StudentStudyHistoryServiceV2 studentStudyHistoryServiceV2; | ||
|
||
@Operation(summary = "내 레포지토리 입력", description = "나의 과제 제출 레포지토리를 입력합니다.") | ||
@PutMapping("/repositories/me") | ||
public ResponseEntity<Void> updateMyRepository(@Valid @RequestBody StudyHistoryRepositoryUpdateRequest request) { | ||
studentStudyHistoryServiceV2.updateMyRepository(request); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
83 changes: 83 additions & 0 deletions
83
.../java/com/gdschongik/gdsc/domain/studyv2/application/MentorStudyAchievementServiceV2.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,83 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.application; | ||
|
||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.dao.MemberRepository; | ||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.study.dto.request.OutstandingStudentRequest; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyAchievementV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyHistoryV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyAchievementV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyAchievementValidatorV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyHistoryValidatorV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyValidatorV2; | ||
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 MentorStudyAchievementServiceV2 { | ||
|
||
private final MemberUtil memberUtil; | ||
private final StudyValidatorV2 studyValidator; | ||
private final StudyHistoryValidatorV2 studyHistoryValidator; | ||
private final StudyAchievementValidatorV2 studyAchievementValidator; | ||
private final StudyV2Repository studyRepository; | ||
private final StudyHistoryV2Repository studyHistoryRepository; | ||
private final StudyAchievementV2Repository studyAchievementRepository; | ||
private final MemberRepository memberRepository; | ||
|
||
@Transactional | ||
public void designateOutstandingStudent(Long studyId, OutstandingStudentRequest request) { | ||
Member currentMember = memberUtil.getCurrentMember(); | ||
StudyV2 study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); | ||
studyValidator.validateStudyMentor(currentMember, study); | ||
|
||
long studyHistoryCount = studyHistoryRepository.countByStudyIdAndStudentIds(studyId, request.studentIds()); | ||
studyHistoryValidator.validateAppliedToStudy( | ||
studyHistoryCount, request.studentIds().size()); | ||
|
||
long studyAchievementsAlreadyExistCount = | ||
studyAchievementRepository.countByStudyIdAndAchievementTypeAndStudentIds( | ||
studyId, request.achievementType(), request.studentIds()); | ||
studyAchievementValidator.validateDesignateOutstandingStudent(studyAchievementsAlreadyExistCount); | ||
|
||
List<Member> outstandingStudents = memberRepository.findAllById(request.studentIds()); | ||
List<StudyAchievementV2> studyAchievements = outstandingStudents.stream() | ||
.map(member -> StudyAchievementV2.create(request.achievementType(), member, study)) | ||
.toList(); | ||
studyAchievementRepository.saveAll(studyAchievements); | ||
|
||
log.info( | ||
"[MentorStudyAchievementServiceV2] 우수 스터디원 지정: studyId={}, studentIds={}", | ||
studyId, | ||
request.studentIds()); | ||
} | ||
|
||
@Transactional | ||
public void withdrawOutstandingStudent(Long studyId, OutstandingStudentRequest request) { | ||
Member currentMember = memberUtil.getCurrentMember(); | ||
StudyV2 study = studyRepository.findById(studyId).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); | ||
studyValidator.validateStudyMentor(currentMember, study); | ||
|
||
long studyHistoryCount = studyHistoryRepository.countByStudyIdAndStudentIds(studyId, request.studentIds()); | ||
studyHistoryValidator.validateAppliedToStudy( | ||
studyHistoryCount, request.studentIds().size()); | ||
|
||
studyAchievementRepository.deleteByStudyAndAchievementTypeAndMemberIds( | ||
studyId, request.achievementType(), request.studentIds()); | ||
|
||
log.info( | ||
"[MentorStudyAchievementServiceV2] 우수 스터디원 철회: studyId={}, studentIds={}", | ||
studyId, | ||
request.studentIds()); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
...ain/java/com/gdschongik/gdsc/domain/studyv2/application/StudentStudyHistoryServiceV2.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,51 @@ | ||
package com.gdschongik.gdsc.domain.studyv2.application; | ||
|
||
import static com.gdschongik.gdsc.global.exception.ErrorCode.*; | ||
|
||
import com.gdschongik.gdsc.domain.member.domain.Member; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyHistoryV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.dao.StudyV2Repository; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyHistoryV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyHistoryValidatorV2; | ||
import com.gdschongik.gdsc.domain.studyv2.domain.StudyV2; | ||
import com.gdschongik.gdsc.domain.studyv2.dto.request.StudyHistoryRepositoryUpdateRequest; | ||
import com.gdschongik.gdsc.global.exception.CustomException; | ||
import com.gdschongik.gdsc.global.util.MemberUtil; | ||
import com.gdschongik.gdsc.infra.github.client.GithubClient; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Slf4j | ||
@Service | ||
@RequiredArgsConstructor | ||
public class StudentStudyHistoryServiceV2 { | ||
|
||
private final GithubClient githubClient; | ||
private final MemberUtil memberUtil; | ||
private final StudyV2Repository studyV2Repository; | ||
private final StudyHistoryV2Repository studyHistoryV2Repository; | ||
private final StudyHistoryValidatorV2 studyHistoryValidatorV2; | ||
|
||
@Transactional | ||
public void updateMyRepository(StudyHistoryRepositoryUpdateRequest request) { | ||
Member currentMember = memberUtil.getCurrentMember(); | ||
StudyV2 study = | ||
studyV2Repository.findById(request.studyId()).orElseThrow(() -> new CustomException(STUDY_NOT_FOUND)); | ||
StudyHistoryV2 studyHistory = studyHistoryV2Repository | ||
.findByStudentAndStudy(currentMember, study) | ||
.orElseThrow(() -> new CustomException(STUDY_HISTORY_NOT_FOUND)); | ||
String repositoryOwnerId = githubClient.getOwnerId(request.repositoryLink()); | ||
|
||
studyHistoryValidatorV2.validateUpdateRepository(repositoryOwnerId, currentMember); | ||
|
||
studyHistory.updateRepositoryLink(request.repositoryLink()); | ||
studyHistoryV2Repository.save(studyHistory); | ||
|
||
log.info( | ||
"[StudentStudyHistoryServiceV2] 내 레포지토리 입력 완료: studyHistoryId={}, repositoryLink={}", | ||
studyHistory.getId(), | ||
request.repositoryLink()); | ||
} | ||
} |
Oops, something went wrong.