diff --git a/src/main/java/Chaeda_spring/domain/review_note/problem/controller/ReviewNoteProblemController.java b/src/main/java/Chaeda_spring/domain/review_note/problem/controller/ReviewNoteProblemController.java index c45da8a..517df5d 100644 --- a/src/main/java/Chaeda_spring/domain/review_note/problem/controller/ReviewNoteProblemController.java +++ b/src/main/java/Chaeda_spring/domain/review_note/problem/controller/ReviewNoteProblemController.java @@ -1,6 +1,8 @@ package Chaeda_spring.domain.review_note.problem.controller; import Chaeda_spring.domain.member.entity.Member; +import Chaeda_spring.domain.review_note.problem.dto.IncorrectProblemForReviewNoteRequest; +import Chaeda_spring.domain.review_note.problem.dto.IncorrectProblemRecordRequest; import Chaeda_spring.domain.review_note.problem.dto.ReviewNoteProblemInfo; import Chaeda_spring.domain.review_note.problem.dto.ReviewNoteProblemResponse; import Chaeda_spring.domain.review_note.problem.service.ReviewNoteProblemService; @@ -46,4 +48,12 @@ public ResponseEntity deleteProblemFromStorage( reviewNoteProblemService.deleteProblemFromStorage(member, reviewNoteProblemIds); return ResponseEntity.ok().body(null); } + + @PostMapping("/byDateRange") + @Operation(summary = "특정 날짜 범위 내의 틀린 문제 기록 조회") + public ResponseEntity> getWrongProblemsByDateRange( + @RequestBody IncorrectProblemRecordRequest request) { + List response = reviewNoteProblemService.findWrongProblemsByDateRange(request); + return ResponseEntity.ok(response); + } } diff --git a/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemForReviewNoteRequest.java b/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemForReviewNoteRequest.java new file mode 100644 index 0000000..84a7209 --- /dev/null +++ b/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemForReviewNoteRequest.java @@ -0,0 +1,40 @@ +package Chaeda_spring.domain.review_note.problem.dto; + +import Chaeda_spring.domain.Problem.math.MathProblem; +import Chaeda_spring.domain.submission.assignment.entity.WrongProblemRecord; +import Chaeda_spring.global.constant.Chapter; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; +import lombok.Builder; + +import java.time.LocalDate; +import java.util.List; +import java.util.stream.Collectors; + +@Builder +public record IncorrectProblemForReviewNoteRequest( + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd", timezone = "Asia/Seoul") + @Schema(description = "문제를 틀린 날짜", example = "2024-05-22") + LocalDate incorrectDate, + @Schema(description = "교재 이름", example = "쎈 미적분") + String textbookName, + + @Schema(description = "문제 번호", example = "101") + String problemNum, + + @Schema(description = "문제가 속한 챕터") + List chapters +) { + public static IncorrectProblemForReviewNoteRequest from(WrongProblemRecord record) { + MathProblem mathProblem = record.getMathProblem(); + List chapters = mathProblem.getProblemTypeMappings().stream() + .map(type -> type.getMathProblemType().getChapter()) + .collect(Collectors.toList()); + return IncorrectProblemForReviewNoteRequest.builder() + .incorrectDate(record.getIncorrectDate()) + .textbookName(mathProblem.getTextbook().getName()) + .problemNum(mathProblem.getProblemNumber()) + .chapters(chapters) + .build(); + } +} diff --git a/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemRecordRequest.java b/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemRecordRequest.java new file mode 100644 index 0000000..d09653b --- /dev/null +++ b/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemRecordRequest.java @@ -0,0 +1,17 @@ +package Chaeda_spring.domain.review_note.problem.dto; + +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; + +import java.time.LocalDate; + +public record IncorrectProblemRecordRequest( + @Schema(description = "시작 날짜", example = "2024-04-01") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + LocalDate startDate, + @Schema(description = "끝 날짜", example = "2024-04-30") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + LocalDate endDate +) { +} + diff --git a/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemRecordResponse.java b/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemRecordResponse.java new file mode 100644 index 0000000..255eabf --- /dev/null +++ b/src/main/java/Chaeda_spring/domain/review_note/problem/dto/IncorrectProblemRecordResponse.java @@ -0,0 +1,20 @@ +package Chaeda_spring.domain.review_note.problem.dto; + +import Chaeda_spring.global.constant.DifficultyLevel; +import com.fasterxml.jackson.annotation.JsonFormat; +import io.swagger.v3.oas.annotations.media.Schema; + +import java.time.LocalDate; + +public record IncorrectProblemRecordResponse( + @Schema(description = "틀린 문제 ID", example = "1") + Long id, + @Schema(description = "틀린 날짜", example = "2024-04-15") + @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd") + LocalDate incorrectDate, + @Schema(description = "난이도", example = "HARD") + DifficultyLevel difficulty, + @Schema(description = "문제 반호", example = "1") + String problemNumber +) { +} diff --git a/src/main/java/Chaeda_spring/domain/review_note/problem/service/ReviewNoteProblemService.java b/src/main/java/Chaeda_spring/domain/review_note/problem/service/ReviewNoteProblemService.java index 78b0ca1..c17f7e8 100644 --- a/src/main/java/Chaeda_spring/domain/review_note/problem/service/ReviewNoteProblemService.java +++ b/src/main/java/Chaeda_spring/domain/review_note/problem/service/ReviewNoteProblemService.java @@ -8,10 +8,14 @@ import Chaeda_spring.domain.File.service.ImageService; import Chaeda_spring.domain.member.entity.Member; import Chaeda_spring.domain.member.entity.Student; +import Chaeda_spring.domain.review_note.problem.dto.IncorrectProblemForReviewNoteRequest; +import Chaeda_spring.domain.review_note.problem.dto.IncorrectProblemRecordRequest; import Chaeda_spring.domain.review_note.problem.dto.ReviewNoteProblemInfo; import Chaeda_spring.domain.review_note.problem.dto.ReviewNoteProblemResponse; import Chaeda_spring.domain.review_note.problem.entity.ReviewNoteProblem; import Chaeda_spring.domain.review_note.problem.entity.ReviewNoteProblemRepository; +import Chaeda_spring.domain.submission.assignment.entity.WrongProblemRecord; +import Chaeda_spring.domain.submission.assignment.entity.WrongProblemRecordRepository; import Chaeda_spring.global.exception.ErrorCode; import Chaeda_spring.global.exception.NotEqualsException; import Chaeda_spring.global.exception.NotFoundException; @@ -30,7 +34,7 @@ public class ReviewNoteProblemService { private final ImageService imageService; private final ImageRepository imageRepository; private final S3Utils s3Utils; - + private final WrongProblemRecordRepository wrongProblemRecordRepository; /** * 사용자로부터 수신된 정보를 사용하여 ReviewNoteProblem을 생성하고 저장합니다. @@ -95,4 +99,18 @@ public void deleteProblemFromStorage(Member member, List reviewNoteProblem s3Utils.deleteS3Object(image.getFilename()); }); } + + + /** + * 주어진 날짜 범위 내에서 틀린 문제 기록을 찾습니다. + * + * @param request 날짜 범위 요청 데이터를 포함하는 WrongProblemRecordRequest 객체. + * @return WrongProblemRecordResponse 객체 목록으로, 각 틀린 문제의 기록을 포함합니다. + */ + public List findWrongProblemsByDateRange(IncorrectProblemRecordRequest request) { + List records = wrongProblemRecordRepository.findAllByWrongDateBetween(request.startDate(), request.endDate()); + return records.stream() + .map(record -> IncorrectProblemForReviewNoteRequest.from(record)) + .collect(Collectors.toList()); + } } diff --git a/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecord.java b/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecord.java index 5270609..c849618 100644 --- a/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecord.java +++ b/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecord.java @@ -20,7 +20,7 @@ public class WrongProblemRecord { private Long id; @Temporal(TemporalType.DATE) - private LocalDate wrongDate; + private LocalDate incorrectDate; @Enumerated(EnumType.STRING) private DifficultyLevel difficulty; @@ -34,8 +34,8 @@ public class WrongProblemRecord { private MathProblem mathProblem; @Builder - public WrongProblemRecord(LocalDate wrongDate, DifficultyLevel difficulty, Student student, MathProblem mathProblem) { - this.wrongDate = wrongDate; + public WrongProblemRecord(LocalDate incorrectDate, DifficultyLevel difficulty, Student student, MathProblem mathProblem) { + this.incorrectDate = incorrectDate; this.difficulty = difficulty; this.student = student; this.mathProblem = mathProblem; diff --git a/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecordRepository.java b/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecordRepository.java index 3c9bea6..28bdf28 100644 --- a/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecordRepository.java +++ b/src/main/java/Chaeda_spring/domain/submission/assignment/entity/WrongProblemRecordRepository.java @@ -1,6 +1,13 @@ package Chaeda_spring.domain.submission.assignment.entity; import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.data.jpa.repository.Query; + +import java.time.LocalDate; +import java.util.List; public interface WrongProblemRecordRepository extends JpaRepository { + + @Query("SELECT s FROM WrongProblemRecord s WHERE s.incorrectDate BETWEEN :startDate AND :endDate AND s.student = :student") + List findAllByWrongDateBetween(LocalDate startDate, LocalDate endDate); } diff --git a/src/main/java/Chaeda_spring/domain/submission/assignment/service/AssignmentSubmissionService.java b/src/main/java/Chaeda_spring/domain/submission/assignment/service/AssignmentSubmissionService.java index db0a9bb..5750706 100644 --- a/src/main/java/Chaeda_spring/domain/submission/assignment/service/AssignmentSubmissionService.java +++ b/src/main/java/Chaeda_spring/domain/submission/assignment/service/AssignmentSubmissionService.java @@ -157,7 +157,7 @@ private void saveWrongMathProblem(MathProblem mathProblem, HashMap