Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import java.util.Set;

public record ChildProblemUpdateRequest(
@NotNull(message = "새끼문제 ID는 필수입니다.")
Long childProblemId,
String imageUrl,
AnswerType answerType,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public ResponseEntity<IdResponse> createProblemSet(
@PutMapping("/{problemSetId}/sequence")
@Operation(summary = "세트 문항순서 변경", description = "문항세트 내의 문항 리스트의 순서를 변경합니다.")
public ResponseEntity<Void> reorderProblems(
@PathVariable Long problemSetId,
@PathVariable("problemSetId") Long problemSetId,
@RequestBody ProblemReorderRequest request) {
problemSetUpdateService.reorderProblems(problemSetId, request);
return ResponseEntity.noContent().build();
Expand All @@ -54,7 +54,7 @@ public ResponseEntity<Void> reorderProblems(
@PutMapping("/{problemSetId}")
@Operation(summary = "문항세트 수정", description = "문항세트의 이름 및 문항 리스트를 수정합니다.")
public ResponseEntity<Void> updateProblemSet(
@PathVariable Long problemSetId,
@PathVariable("problemSetId") Long problemSetId,
@RequestBody ProblemSetUpdateRequest request
) {
problemSetUpdateService.updateProblemSet(problemSetId, request);
Expand All @@ -64,7 +64,7 @@ public ResponseEntity<Void> updateProblemSet(
@DeleteMapping("/{problemSetId}")
@Operation(summary = "문항세트 삭제", description = "문항세트를 삭제합니다. (soft delete)")
public ResponseEntity<Void> deleteProblemSet(
@PathVariable Long problemSetId
@PathVariable("problemSetId") Long problemSetId
) {
problemSetDeleteService.deleteProblemSet(problemSetId);
return ResponseEntity.ok(null);
Expand All @@ -73,7 +73,7 @@ public ResponseEntity<Void> deleteProblemSet(
@PutMapping("/{problemSetId}/confirm")
@Operation(summary = "문항세트 컨펌 토글", description = "문항세트의 컨펌 상태를 토글합니다.")
public ResponseEntity<ProblemSetConfirmStatus> toggleConfirmProblemSet(
@PathVariable Long problemSetId
@PathVariable("problemSetId") Long problemSetId
) {
return ResponseEntity.ok(problemSetUpdateService.toggleConfirmProblemSet(problemSetId));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,4 +95,20 @@ public void updateProblemSet(String title, List<Long> newProblems) {
this.title = new Title(title);
this.problemIds = newProblems;
}

public boolean isConfirmed() {
return this.confirmStatus == ProblemSetConfirmStatus.CONFIRMED;
}

public boolean isProblemsChanged(List<Long> newProblems) {
if (this.problemIds.size() != newProblems.size()) {
return true;
}
for (int i = 0; i < this.problemIds.size(); i++) {
if (!this.problemIds.get(i).equals(newProblems.get(i))) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class ProblemSetUpdateService {
@Transactional
public void reorderProblems(Long problemSetId, ProblemReorderRequest request) {
ProblemSet problemSet = problemSetRepository.findByIdElseThrow(problemSetId);
if (problemSet.isConfirmed()) {
throw new InvalidValueException(ErrorCode.CONFIRMED_PROBLEM_SET_REORDER_ERROR);
}

problemSet.updateProblemOrder(request.newProblems());
}
Expand All @@ -39,7 +42,11 @@ public void updateProblemSet(Long problemSetId, ProblemSetUpdateRequest request)
if (problemSet.isDeleted()) {
throw new BusinessException(ErrorCode.DELETE_PROBLEM_SET_UPDATE_ERROR);
}
// 빈 문항 유효성 검증

if (problemSet.isConfirmed() && problemSet.isProblemsChanged(request.problemIds())) {
throw new InvalidValueException(ErrorCode.CONFIRMED_PROBLEM_SET_UPDATE_ERROR);
}

if (request.problemIds().isEmpty()) {
throw new InvalidValueException(ErrorCode.EMPTY_PROBLEMS_ERROR);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ public enum ErrorCode {
DELETE_PROBLEM_SET_GET_ERROR(HttpStatus.BAD_REQUEST, "삭제된 세트 문항은 조회할 수 없습니다."),
DELETE_PROBLEM_SET_UPDATE_ERROR(HttpStatus.BAD_REQUEST, "삭제된 세트 문항은 수정할 수 없습니다."),
DELETE_PROBLEM_SET_TOGGLE_ERROR(HttpStatus.BAD_REQUEST, "삭제된 세트 문항은 컨펌을 토글할 수 없습니다."),
CONFIRMED_PROBLEM_SET_REORDER_ERROR(HttpStatus.BAD_REQUEST, "컨펌된 세트 문항은 문항 순서를 변경할 수 없습니다."),
CONFIRMED_PROBLEM_SET_UPDATE_ERROR(HttpStatus.BAD_REQUEST, "컨펌된 세트 문항은 수정할 수 없습니다."),

// 발행
INVALID_MONTH_ERROR(HttpStatus.BAD_REQUEST, "유효하지 않은 월입니다."),
Expand Down