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 @@ -3,6 +3,7 @@
import com.moplus.moplus_server.domain.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.domain.problem.dto.request.ProblemUpdateRequest;
import com.moplus.moplus_server.domain.problem.dto.response.ProblemGetResponse;
import com.moplus.moplus_server.domain.problem.dto.response.ProblemPostResponse;
import com.moplus.moplus_server.domain.problem.service.ChildProblemService;
import com.moplus.moplus_server.domain.problem.service.ProblemDeleteService;
import com.moplus.moplus_server.domain.problem.service.ProblemGetService;
Expand Down Expand Up @@ -45,10 +46,10 @@ public ResponseEntity<ProblemGetResponse> getProblem(

@PostMapping("")
@Operation(summary = "λ¬Έν•­ 생성", description = "문제λ₯Ό μƒμ„±ν•©λ‹ˆλ‹€. 기좜/λ³€ν˜• λ¬Έμ œλŠ” λͺ¨λ“  값이 ν•„μˆ˜μ΄λ©° μ°½μž‘ λ¬Έμ œλŠ” λ¬Έν•­ νƒ€μž…λ§Œ ν•„μˆ˜ μž…λ‹ˆλ‹€.")
public ResponseEntity<IdResponse> createProblem(
public ResponseEntity<ProblemPostResponse> createProblem(
@Valid @RequestBody ProblemPostRequest request
) {
return ResponseEntity.ok(new IdResponse(problemSaveService.createProblem(request)));
return ResponseEntity.ok(problemSaveService.createProblem(request));
}

@PutMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,14 @@ public class Difficulty {
private Integer difficulty;

public Difficulty(Integer difficulty) {
if (difficulty == null) {
return;
}
validate(difficulty);
this.difficulty = difficulty;
}

private void validate(int difficulty) {
private void validate(Integer difficulty) {
if (difficulty == null) {
return;
}
if (difficulty < 1 || difficulty > 10) {
throw new InvalidValueException(ErrorCode.INVALID_DIFFICULTY);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void updateChildProblem(List<ChildProblem> inputChildProblems) {
if (isConfirmed && this.childProblems.size() != inputChildProblems.size()) {
throw new InvalidValueException(ErrorCode.INVALID_CHILD_PROBLEM_SIZE);
}

for (int i = 0; i < inputChildProblems.size(); i++) {
this.childProblems.get(i).update(inputChildProblems.get(i));
}
Expand All @@ -160,10 +160,10 @@ public boolean isValid() {
}

public String getTitle() {
return title.getTitle();
return title != null ? title.getTitle() : "제λͺ© μ—†μŒ";
}

public Integer getDifficulty() {
return difficulty.getDifficulty();
return difficulty != null ? difficulty.getDifficulty() : null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.moplus.moplus_server.domain.problem.dto.response;

import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
import jakarta.validation.constraints.NotNull;

public record ProblemPostResponse(
@NotNull(message = "λ¬Έν•­ IDλŠ” ν•„μˆ˜μž…λ‹ˆλ‹€")
Long id,
@NotNull(message = "λ¬Έν•­ custom IDλŠ” ν•„μˆ˜μž…λ‹ˆλ‹€")
Long problemCustomId
) {
public static ProblemPostResponse of(Problem problem) {
return new ProblemPostResponse(problem.getId(), problem.getPracticeTestId());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemAdminIdService;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemCustomId;
import com.moplus.moplus_server.domain.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.domain.problem.dto.response.ProblemPostResponse;
import com.moplus.moplus_server.domain.problem.repository.PracticeTestTagRepository;
import com.moplus.moplus_server.domain.problem.repository.ProblemRepository;
import com.moplus.moplus_server.domain.problem.service.mapper.ProblemMapper;
Expand All @@ -22,13 +23,12 @@ public class ProblemSaveService {
private final ProblemMapper problemMapper;

@Transactional
public Long createProblem(ProblemPostRequest request) {
public ProblemPostResponse createProblem(ProblemPostRequest request) {
PracticeTestTag practiceTestTag = practiceTestRepository.findByIdElseThrow(request.practiceTestId());
ProblemCustomId problemCustomId = problemAdminIdService.nextId(request.number(), practiceTestTag,
request.problemType());

Problem problem = problemMapper.from(request, problemCustomId, practiceTestTag);

return problemRepository.save(problem).getId();
return ProblemPostResponse.of(problemRepository.save(problem));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.moplus.moplus_server.domain.problem.domain.problem.Problem;
import com.moplus.moplus_server.domain.problem.domain.problem.ProblemType;
import com.moplus.moplus_server.domain.problem.dto.request.ProblemPostRequest;
import com.moplus.moplus_server.domain.problem.dto.response.ProblemPostResponse;
import com.moplus.moplus_server.domain.problem.repository.ProblemRepository;
import com.moplus.moplus_server.global.error.exception.NotFoundException;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -46,12 +47,12 @@ class 문항생성 {
@Test
void 성곡() {
// when
Long createdProblemId = problemSaveService.createProblem(problemPostRequest);
ProblemPostResponse problemResponse = problemSaveService.createProblem(problemPostRequest);

// then
assertThat(createdProblemId).isNotNull();
assertThat(problemResponse).isNotNull();

Problem savedProblem = problemRepository.findByIdElseThrow(createdProblemId);
Problem savedProblem = problemRepository.findByIdElseThrow(problemResponse.id());
assertThat(savedProblem).isNotNull();
assertThat(savedProblem.getProblemType()).isEqualTo(ProblemType.GICHUL_PROBLEM);
}
Expand Down