Skip to content

Commit

Permalink
[refactor] 학습리포트 전체조회 requestParam 삭제
Browse files Browse the repository at this point in the history
[refactor] 학습리포트 전체조회 requestParam 삭제
  • Loading branch information
bangyewon authored Jan 13, 2025
2 parents d58f15a + 5929394 commit 5c7db0a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,9 @@ public ApiResponse<ShowStudentReportResponse> showStudentReport(@AuthMember Memb
@GetMapping("/all-report")
@Operation(summary = "학습 리포트 전체조회", description = "학원 별 생성한 성적 리포트 전체조회 API입니다.")
public ApiResponse<List<FindAllReportResponse>> findAllReport(
@AuthMember Member member,
@RequestParam(name = "academyId") Long academyId) {
@AuthMember Member member) {

List<FindAllReportResponse> response = scoreReportService.findAllReport(member, academyId);
List<FindAllReportResponse> response = scoreReportService.findAllReport(member);

return ApiResponse.success(response, 200, "FIND-ALL-STUDENT-REPORTS");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public CreateReportResponse createReport(@AuthMember Member member,
SubClass subClass = subClassRepository.findById(request.subClassId())
.orElseThrow(
() -> new ClassfitException("서브 클래스를 찾을 수 없어요.", HttpStatus.NOT_FOUND));
validateAcademy(member, member.getAcademy().getId());

List<Exam> exams = examRepository.findAllById(request.examIdList());
if (exams.isEmpty()) {
Expand Down Expand Up @@ -143,6 +144,7 @@ public List<FindReportResponse> findReport(@AuthMember Member member, Long mainC
SubClass subClass = subClassRepository.findById(subClassId)
.orElseThrow(
() -> new ClassfitException("서브 클래스를 찾을 수 없어요.", HttpStatus.NOT_FOUND));
validateAcademy(member, mainClass.getMember().getAcademy().getId());
List<ScoreReport> studentReports = scoreReportRepository.findFirstReportByStudent(
mainClassId, subClassId);

Expand All @@ -159,15 +161,13 @@ public List<FindReportResponse> findReport(@AuthMember Member member, Long mainC
}

@Transactional(readOnly = true)
public List<FindAllReportResponse> findAllReport(@AuthMember Member member, Long academyId) {
public List<FindAllReportResponse> findAllReport(@AuthMember Member member) {

Long academyId = member.getAcademy().getId();

Academy academy = academyRepository.findById(academyId)
.orElseThrow(() -> new ClassfitException("학원을 찾을 수 없어요.", HttpStatus.NOT_FOUND));

if (!Objects.equals(member.getAcademy().getId(), academyId)) {
throw new ClassfitException("해당 학원에 접근할 권한이 없습니다.", HttpStatus.FORBIDDEN);
}

List<ScoreReport> scoreReports = scoreReportRepository.findAllByAcademy(academy);

return scoreReports.stream()
Expand All @@ -191,12 +191,15 @@ public void deleteReport(@AuthMember Member member, Long studentReportId) {
@Transactional(readOnly = true)
public List<FindClassStudent> findClassStudents(@AuthMember Member member, Long mainClassId,
Long subClassId) {

MainClass mainClass = mainClassRepository.findById(mainClassId)
.orElseThrow(
() -> new ClassfitException("메인 클래스를 찾을 수 없어요.", HttpStatus.NOT_FOUND));
SubClass subClass = subClassRepository.findById(subClassId)
.orElseThrow(
() -> new ClassfitException("서브 클래스를 찾을 수 없어요.", HttpStatus.NOT_FOUND));
validateAcademy(member, mainClass.getMember().getAcademy().getId());

List<FindClassStudent> classStudents = classStudentRepository.findStudentIdsByMainClassIdAndSubClassId(
mainClassId, subClassId);
return classStudents.stream()
Expand All @@ -208,12 +211,14 @@ public List<FindClassStudent> findClassStudents(@AuthMember Member member, Long
@Transactional
public List<SentStudentOpinionResponse> sentStudentOpinion(@AuthMember Member member,
List<SentStudentOpinionRequest> requests) {

List<SentStudentOpinionResponse> responses = new ArrayList<>();

for (SentStudentOpinionRequest request : requests) {
ScoreReport scoreReport = scoreReportRepository.findById(request.reportId())
.orElseThrow(
() -> new ClassfitException("학습리포트를 찾을 수 없어요.", HttpStatus.NOT_FOUND));
validateAcademy(member, scoreReport.getMainClass().getMember().getAcademy().getId());

scoreReport.updateStudentOpinion(request.studentOpinion());

Expand All @@ -234,6 +239,7 @@ public ShowStudentReportResponse showStudentReport(@AuthMember Member member, Lo
.orElseThrow(
() -> new ClassfitException("학습리포트를 찾을 수 없어요.", HttpStatus.NOT_FOUND));

validateAcademy(member, scoreReport.getMainClass().getMember().getAcademy().getId());
List<AttendanceInfo> attendanceInfoList = scoreReport.getStudent().getAttendances().stream()
.collect(Collectors.groupingBy(
Attendance::getStatus,
Expand Down Expand Up @@ -285,4 +291,13 @@ public ShowStudentReportResponse showStudentReport(@AuthMember Member member, Lo

}

private void validateAcademy(Member member, Long academyId) {
Academy academy = academyRepository.findById(academyId)
.orElseThrow(() -> new ClassfitException("학원을 찾을 수 없어요.", HttpStatus.NOT_FOUND));
if (!Objects.equals(member.getAcademy().getId(), academyId)) {
throw new ClassfitException("해당 학원에 접근할 권한이 없습니다.", HttpStatus.FORBIDDEN);
}
}


}

0 comments on commit 5c7db0a

Please sign in to comment.