Skip to content

Commit

Permalink
틀린 문제 기반 오답 저장소로 불러오기
Browse files Browse the repository at this point in the history
  • Loading branch information
sejoon00 committed Jun 10, 2024
1 parent 9478d15 commit b29d8bf
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -46,4 +48,12 @@ public ResponseEntity<Long> deleteProblemFromStorage(
reviewNoteProblemService.deleteProblemFromStorage(member, reviewNoteProblemIds);
return ResponseEntity.ok().body(null);
}

@PostMapping("/byDateRange")
@Operation(summary = "특정 날짜 범위 내의 틀린 문제 기록 조회")
public ResponseEntity<List<IncorrectProblemForReviewNoteRequest>> getWrongProblemsByDateRange(
@RequestBody IncorrectProblemRecordRequest request) {
List<IncorrectProblemForReviewNoteRequest> response = reviewNoteProblemService.findWrongProblemsByDateRange(request);
return ResponseEntity.ok(response);
}
}
Original file line number Diff line number Diff line change
@@ -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<Chapter> chapters
) {
public static IncorrectProblemForReviewNoteRequest from(WrongProblemRecord record) {
MathProblem mathProblem = record.getMathProblem();
List<Chapter> 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();
}
}
Original file line number Diff line number Diff line change
@@ -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
) {
}

Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -30,7 +34,7 @@ public class ReviewNoteProblemService {
private final ImageService imageService;
private final ImageRepository imageRepository;
private final S3Utils s3Utils;

private final WrongProblemRecordRepository wrongProblemRecordRepository;

/**
* 사용자로부터 수신된 정보를 사용하여 ReviewNoteProblem을 생성하고 저장합니다.
Expand Down Expand Up @@ -95,4 +99,18 @@ public void deleteProblemFromStorage(Member member, List<Long> reviewNoteProblem
s3Utils.deleteS3Object(image.getFilename());
});
}


/**
* 주어진 날짜 범위 내에서 틀린 문제 기록을 찾습니다.
*
* @param request 날짜 범위 요청 데이터를 포함하는 WrongProblemRecordRequest 객체.
* @return WrongProblemRecordResponse 객체 목록으로, 각 틀린 문제의 기록을 포함합니다.
*/
public List<IncorrectProblemForReviewNoteRequest> findWrongProblemsByDateRange(IncorrectProblemRecordRequest request) {
List<WrongProblemRecord> records = wrongProblemRecordRepository.findAllByWrongDateBetween(request.startDate(), request.endDate());
return records.stream()
.map(record -> IncorrectProblemForReviewNoteRequest.from(record))
.collect(Collectors.toList());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<WrongProblemRecord, Long> {

@Query("SELECT s FROM WrongProblemRecord s WHERE s.incorrectDate BETWEEN :startDate AND :endDate AND s.student = :student")
List<WrongProblemRecord> findAllByWrongDateBetween(LocalDate startDate, LocalDate endDate);
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private void saveWrongMathProblem(MathProblem mathProblem, HashMap<String, Diffi
DifficultyLevel difficultyLevel = wrongProblemRecordMap.get(mathProblem.getProblemNumber());

WrongProblemRecord record = WrongProblemRecord.builder()
.wrongDate(selfAssignment.getTargetDate())
.incorrectDate(selfAssignment.getTargetDate())
.difficulty(difficultyLevel)
.mathProblem(mathProblem)
.student(student)
Expand Down

0 comments on commit b29d8bf

Please sign in to comment.