Skip to content

Commit 30e740f

Browse files
authored
feature: Swagger 문서화 및 중복 문제 검증로직 추가 (#53)
* feat : 문제 생성시 중복체크 ( 제목 ) * refactor : 문제 생성시 중복체크 <2> ( 삭제된 문제인지 검증 추가 ) * feat : Swagger API 문서 작업 * feat : Swagger API 문서 작업 (2)
1 parent 6fed733 commit 30e740f

File tree

15 files changed

+97
-1
lines changed

15 files changed

+97
-1
lines changed

src/main/java/org/ezcode/codetest/application/problem/dto/request/ProblemCreateRequest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,30 +6,38 @@
66
import org.ezcode.codetest.domain.problem.model.enums.Reference;
77
import org.ezcode.codetest.domain.user.model.entity.User;
88

9+
import io.swagger.v3.oas.annotations.media.Schema;
910
import jakarta.validation.constraints.NotBlank;
1011
import jakarta.validation.constraints.NotNull;
1112

1213
public record ProblemCreateRequest(
1314

1415
@NotNull(message = "카테고리를 설정해야 합니다.")
16+
@Schema(description = "카테고리", example = "FOR_BEGINNER")
1517
Category category,
1618

1719
@NotBlank(message = "문제 제목을 입력하세요.")
20+
@Schema(description = "제목", example = "A+B")
1821
String title,
1922

2023
@NotBlank(message = "문제 설명을 입력하세요.")
24+
@Schema(description = "설명", example = "입력한 두수의 값을 더하고, 결과값을 출력하세요")
2125
String description,
2226

2327
@NotNull(message = "난이도를 설정해야 합니다.")
28+
@Schema(description = "난이도", example = "BRONZE")
2429
Difficulty difficulty,
2530

2631
@NotNull(message = "메모리 제한을 설정해야 합니다.")
32+
@Schema(description = "메모리 제한", example = "30000")
2733
Long memoryLimit,
2834

2935
@NotNull(message = "시간 제한을 설정해야 합니다.")
36+
@Schema(description = "시간 제한", example = "1000.0")
3037
Double timeLimit,
3138

3239
@NotNull(message = "출처를 명시해야 합니다.")
40+
@Schema(description = "출처", example = "ORIGINAL")
3341
Reference reference
3442

3543
) {

src/main/java/org/ezcode/codetest/application/problem/dto/request/ProblemUpdateRequest.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,20 +6,29 @@
66
import org.ezcode.codetest.domain.problem.model.enums.Reference;
77
import org.ezcode.codetest.domain.user.model.entity.User;
88

9+
import io.swagger.v3.oas.annotations.media.Schema;
10+
911
public record ProblemUpdateRequest(
1012

13+
@Schema(description = "카테고리", example = "FOR_BEGINNER")
1114
Category category,
1215

16+
@Schema(description = "제목", example = "A+B")
1317
String title,
1418

19+
@Schema(description = "카테고리", example = "입력한 두수의 값을 더하고, 결과값을 출력하세요")
1520
String description,
1621

22+
@Schema(description = "난이도", example = "BRONZE")
1723
Difficulty difficulty,
1824

25+
@Schema(description = "메모리 제한", example = "30000")
1926
Long memoryLimit,
2027

28+
@Schema(description = "시간 제한", example = "1000.0")
2129
Double timeLimit,
2230

31+
@Schema(description = "출처", example = "ORIGINAL")
2332
Reference reference
2433

2534
) {

src/main/java/org/ezcode/codetest/application/problem/dto/request/TestcaseCreateRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import org.ezcode.codetest.domain.problem.model.entity.Problem;
44
import org.ezcode.codetest.domain.problem.model.entity.Testcase;
55

6+
import io.swagger.v3.oas.annotations.media.Schema;
7+
68
public record TestcaseCreateRequest(
79

10+
@Schema(description = "입력값", example = "2 3")
811
String input,
912

13+
@Schema(description = "기댓값", example = "5")
1014
String output
1115

1216
) {

src/main/java/org/ezcode/codetest/application/problem/dto/request/TestcaseUpdateRequest.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,14 @@
33
import org.ezcode.codetest.domain.problem.model.entity.Problem;
44
import org.ezcode.codetest.domain.problem.model.entity.Testcase;
55

6+
import io.swagger.v3.oas.annotations.media.Schema;
7+
68
public record TestcaseUpdateRequest(
79

10+
@Schema(description = "입력값", example = "2 3")
811
String input,
912

13+
@Schema(description = "기댓값", example = "5")
1014
String output
1115
) {
1216

src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemDetailResponse.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,46 @@
66
import org.ezcode.codetest.domain.problem.model.enums.Category;
77
import org.ezcode.codetest.domain.problem.model.enums.Reference;
88

9+
import io.swagger.v3.oas.annotations.media.Schema;
910
import lombok.Builder;
1011

1112
@Builder
1213
public record ProblemDetailResponse(
1314

15+
@Schema(description = "PK", example = "1")
1416
Long id,
1517

18+
@Schema(description = "출제자", example = "홍길동")
1619
String creator,
1720

21+
@Schema(description = "카테고리", example = "FOR_BEGINNER")
1822
Category category,
1923

24+
@Schema(description = "제목", example = "A+B")
2025
String title,
2126

27+
@Schema(description = "설명", example = "입력한 두수의 값을 더하고, 결과값을 출력하세요")
2228
String description,
2329

30+
@Schema(description = "점수", example = "20")
2431
int score,
2532

33+
@Schema(description = "난이도", example = "BRONZE")
2634
String difficulty,
2735

36+
@Schema(description = "메모리 제한", example = "30000")
2837
Long memoryLimit,
2938

39+
@Schema(description = "시간 제한", example = "1000.0")
3040
Double timeLimit,
3141

42+
@Schema(description = "출처", example = "ORIGINAL")
3243
Reference reference,
3344

45+
@Schema(description = "생성일", example = "2025-06-10 20:19:59.730028")
3446
LocalDateTime createdAt,
3547

48+
@Schema(description = "수정일", example = "2025-06-11 08:12:43.506032")
3649
LocalDateTime modifiedAt
3750

3851
) {

src/main/java/org/ezcode/codetest/application/problem/dto/response/ProblemResponse.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,31 @@
44
import org.ezcode.codetest.domain.problem.model.enums.Category;
55
import org.ezcode.codetest.domain.problem.model.enums.Reference;
66

7+
import io.swagger.v3.oas.annotations.media.Schema;
78
import lombok.Builder;
89

910
@Builder
1011
public record ProblemResponse(
1112

13+
@Schema(description = "PK", example = "1")
1214
Long id,
1315

16+
@Schema(description = "출제자", example = "홍길동")
1417
String creator,
1518

19+
@Schema(description = "카테고리", example = "FOR_BEGINNER")
1620
Category category,
1721

22+
@Schema(description = "제목", example = "A+B")
1823
String title,
1924

25+
@Schema(description = "점수", example = "20")
2026
int score,
2127

28+
@Schema(description = "난이도", example = "BRONZE")
2229
String difficulty,
2330

31+
@Schema(description = "출처", example = "ORIGINAL")
2432
Reference reference
2533

2634
) {

src/main/java/org/ezcode/codetest/application/problem/dto/response/TestcaseResponse.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,22 @@
33
import org.ezcode.codetest.domain.problem.model.entity.Problem;
44
import org.ezcode.codetest.domain.problem.model.entity.Testcase;
55

6+
import io.swagger.v3.oas.annotations.media.Schema;
67
import lombok.Builder;
78

89
@Builder
910
public record TestcaseResponse(
1011

12+
@Schema(description = "PK", example = "1")
1113
Long id,
1214

15+
@Schema(description = "FK", example = "1")
1316
Long problemId,
1417

18+
@Schema(description = "입력값", example = "2 3")
1519
String input,
1620

21+
@Schema(description = "기댓값", example = "5")
1722
String output
1823
) {
1924

src/main/java/org/ezcode/codetest/domain/problem/exception/code/ProblemExceptionCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
public enum ProblemExceptionCode implements ResponseCode {
1212

1313
PROBLEM_NOT_FOUND(false, HttpStatus.NOT_FOUND, "삭제 되었거나, 문제를 찾을수 없습니다."),
14-
DIFFICULTY_NOT_FOUND(false, HttpStatus.NOT_FOUND, "삭제 되었거나, 난이도를 찾을수 없습니다.");
14+
DIFFICULTY_NOT_FOUND(false, HttpStatus.NOT_FOUND, "삭제 되었거나, 난이도를 찾을수 없습니다."),
15+
DUPLICATE_PROBLEM(false, HttpStatus.CONFLICT, "이미 존재하는 문제입니다.");
1516

1617
private final boolean success;
1718

src/main/java/org/ezcode/codetest/domain/problem/repository/ProblemRepository.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,6 @@ public interface ProblemRepository {
2020
void delete(Problem problem);
2121

2222
Optional<Problem> findProblemWithTestcasesById(Long problemId);
23+
24+
boolean existsByTitleAndIsDeletedIsFalse(String title);
2325
}

src/main/java/org/ezcode/codetest/domain/problem/service/ProblemDomainService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,11 @@ public class ProblemDomainService {
2424
//저장시 DB 뿐만 아니라 ElasticCache 에도 같이 저장합니다!
2525
public Problem createProblem(Problem problem) {
2626

27+
// 중복된 문제 체크
28+
if(problemRepository.existsByTitleAndIsDeletedIsFalse(problem.getTitle())) {
29+
throw new ProblemException(ProblemExceptionCode.DUPLICATE_PROBLEM);
30+
}
31+
2732
Problem savedProblem = problemRepository.save(problem);
2833

2934
searchRepository.save(ProblemSearchDocument.from(savedProblem));

0 commit comments

Comments
 (0)