Skip to content

Commit

Permalink
[fix] 학습리포트 작성자 추가
Browse files Browse the repository at this point in the history
[fix] 학습리포트 작성자 추가
  • Loading branch information
bangyewon authored Jan 17, 2025
2 parents 330c8ec + 611975a commit 00002ee
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import jakarta.persistence.Table;
import java.time.LocalDate;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
Expand All @@ -23,6 +24,8 @@
@Table(name = "score_report")
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@Getter
@Builder
@AllArgsConstructor
public class ScoreReport extends BaseEntity {

@Id
Expand Down Expand Up @@ -61,21 +64,11 @@ public class ScoreReport extends BaseEntity {
@Column(name = "include_average")
private Boolean includeAverage;

@Column(name = "report_created_by")
private String reportCreatedBy;



@Builder
public ScoreReport(SubClass subClass, MainClass mainClass, String reportName, Student student,
String overallOpinion, LocalDate startDate,
LocalDate endDate,boolean includeAverage) {
this.subClass = subClass;
this.mainClass = mainClass;
this.reportName = reportName;
this.student = student;
this.overallOpinion = overallOpinion;
this.startDate = startDate;
this.endDate = endDate;
this.includeAverage = includeAverage;
}

public void updateStudentOpinion(String studentOpinion) {
this.studentOpinion = studentOpinion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,34 +14,40 @@
public interface ScoreReportRepository extends JpaRepository<ScoreReport, Long> {

@Query("SELECT new classfit.example.classfit.scoreReport.dto.process.ReportExam(" +
"e.id, e.examPeriod, e.mainClass.mainClassName, e.subClass.subClassName, e.examName,e.createdAt) " +
"e.id, e.examPeriod, e.mainClass.mainClassName, e.subClass.subClassName, e.examName, e.createdAt) " +
"FROM Exam e " +
"WHERE FUNCTION('DATE', e.createdAt) BETWEEN :startDate AND :endDate " +
"AND e.mainClass.id = :mainClassId " +
"AND e.subClass.id = :subClassId " +
"AND e.mainClass.academy.id = :academyId " +
"ORDER BY e.createdAt ASC")
List<ReportExam> findExamsByCreatedAtBetween(
@Param("startDate") LocalDate startDate,
@Param("endDate") LocalDate endDate,
@Param("mainClassId") Long mainClassId,
@Param("subClassId") Long subClassId);
@Param("subClassId") Long subClassId,
@Param("academyId") Long academyId);

@Query("""
SELECT sr
FROM ScoreReport sr
WHERE sr.mainClass.id = :mainClassId
AND sr.subClass.id = :subClassId
""")
List<ScoreReport> findAllReportsByMainClassAndSubClass(@Param("mainClassId") Long mainClassId,
@Param("subClassId") Long subClassId);

AND sr.mainClass.academy.id = :academyId
""")
List<ScoreReport> findAllReportsByMainClassAndSubClass(
@Param("mainClassId") Long mainClassId,
@Param("subClassId") Long subClassId,
@Param("academyId") Long academyId);

@Query("SELECT sr FROM ScoreReport sr WHERE sr.id = :studentReportId")
Optional<ScoreReport> findByStudentReportId(@Param("studentReportId") Long studentReportId);
@Query("SELECT sr FROM ScoreReport sr WHERE sr.id = :studentReportId " +
"AND sr.mainClass.academy.id = :academyId")
Optional<ScoreReport> findByStudentReportId(
@Param("studentReportId") Long studentReportId,
@Param("academyId") Long academyId);

@Query("SELECT r FROM ScoreReport r " +
"WHERE r.mainClass.academy = :academy")
List<ScoreReport> findAllByAcademy(@Param("academy") Academy academy);

"WHERE r.mainClass.academy.id = :academyId")
List<ScoreReport> findAllByAcademy(@Param("academyId") Long academyId);
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import classfit.example.classfit.category.domain.MainClass;
import classfit.example.classfit.category.domain.SubClass;
import classfit.example.classfit.member.domain.Member;
import classfit.example.classfit.scoreReport.domain.ScoreReport;
import classfit.example.classfit.student.domain.Student;
import jakarta.validation.constraints.NotNull;
Expand All @@ -17,13 +18,14 @@ public record CreateReportRequest(Long mainClassId, Long subClassId, String repo
@NotNull(message = "종합 의견을 입력해주세요.")
String overallOpinion) {

public ScoreReport toEntity(SubClass subClass, MainClass mainClass,Student student) {
public ScoreReport toEntity(SubClass subClass, MainClass mainClass,Student student, Member member) {
return ScoreReport.builder()
.subClass(subClass)
.mainClass(mainClass)
.student(student)
.reportName(reportName)
.overallOpinion(overallOpinion)
.reportCreatedBy(member.getName())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
public record CreateReportResponse( boolean includeAverage ,Long mainClassId, Long subClassId,
List<StudentList> studentList,
String reportName, LocalDate startDate, LocalDate endDate,
List<Long> examIdList, String overallOpinion) {
List<Long> examIdList, String overallOpinion,String reportCreatedBy) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDate;

public record FindAllReportResponse(Long studentReportId, Long studentId, String studentName,
String reportName, String memberName,
String reportName, String ReportCreatedByName,
LocalDate createAt) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDate;

public record FindReportResponse(Long studentReportId, Long studentId, String studentName,
String reportName, String memberName,
String reportName, String reportCreatedByName,
LocalDate createAt) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,7 @@ public CreateReportResponse createReport(@AuthMember Member member,
for (ClassStudent classStudent : studentsInSubClass) {
Student student = classStudent.getStudent();

ScoreReport report = ScoreReport.builder()
.mainClass(mainClass)
.subClass(subClass)
.includeAverage(request.includeAverage())
.student(student)
.reportName(request.reportName())
.overallOpinion(request.overallOpinion())
.startDate(request.startDate())
.endDate(request.endDate())
.build();
ScoreReport report = request.toEntity(subClass, mainClass, student, member);
scoreReportRepository.save(report);

allStudents.add(new StudentList(report.getId(), student.getId(), student.getName()));
Expand Down Expand Up @@ -126,7 +117,7 @@ public List<ReportExam> showReportExam(@AuthMember Member member, LocalDate star
Long subClassId) {
validateAcademy(member, member.getAcademy().getId());
List<ReportExam> reports = scoreReportRepository.findExamsByCreatedAtBetween(startDate,
endDate, mainClassId, subClassId);
endDate, mainClassId, subClassId,member.getAcademy().getId());
return reports.stream()
.map(report -> new ReportExam(
report.examId(),
Expand All @@ -151,7 +142,7 @@ public List<FindReportResponse> findReport(@AuthMember Member member, Long mainC
() -> new ClassfitException("서브 클래스를 찾을 수 없어요.", HttpStatus.NOT_FOUND));
validateAcademy(member, mainClass.getAcademy().getId());
List<ScoreReport> studentReports = scoreReportRepository.findAllReportsByMainClassAndSubClass(
mainClassId, subClassId);
mainClassId, subClassId,member.getAcademy().getId());

return studentReports.stream()
.map(report -> new FindReportResponse(
Expand All @@ -167,27 +158,27 @@ public List<FindReportResponse> findReport(@AuthMember Member member, Long mainC

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

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

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

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

return scoreReports.stream()
.map(report -> new FindAllReportResponse(
report.getId(),
report.getStudent().getId(),
report.getStudent().getName(),
report.getReportName(),
report.getMainClass().getAcademy().getMembers().getFirst().getName(),
report.getReportCreatedBy(),
report.getCreatedAt().toLocalDate()
))
.collect(Collectors.toList());
}



@Transactional
public void deleteReport(@AuthMember Member member, Long studentReportId) {
validateAcademy(member, member.getAcademy().getId());
Expand Down

0 comments on commit 00002ee

Please sign in to comment.