Skip to content

Commit 0d632c6

Browse files
authored
Refactor/문제 이미지 등록 오류 및 문제 전체 수정 API 수정 (#203)
* refactor : 어드민 문제 추가 수정 * refactor : 문제 등록오류 수정
1 parent c991519 commit 0d632c6

File tree

5 files changed

+15
-9
lines changed

5 files changed

+15
-9
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package org.ezcode.codetest.application.problem.dto.request;
22

3-
import java.util.List;
3+
import java.util.Map;
44

55
import org.ezcode.codetest.domain.problem.model.entity.Problem;
66
import org.ezcode.codetest.domain.problem.model.enums.Difficulty;
@@ -11,9 +11,9 @@
1111

1212
public record ProblemUpdateRequest(
1313

14-
// 리스트 이므로, [] 대괄호 사용
15-
@Schema(description = "카테고리", example = "FOR_BEGINNER")
16-
List<String> categories,
14+
// Map으로 묶여있으니 {} 중괄호 사용
15+
@Schema(description = "카테고리 코드 식별자(영어) / 한글 이름", example = "FOR_BEGINNER : 입문자용")
16+
Map<String, String> categories,
1717

1818
@Schema(description = "제목", example = "A+B")
1919
String title,

src/main/java/org/ezcode/codetest/application/problem/service/ProblemService.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ private void updateProblemImage(Problem problem, MultipartFile newImage) {
190190

191191
@Transactional
192192
public void addImageToExistingProblem(Long problemId, MultipartFile imageFile) {
193+
if (imageFile == null || imageFile.isEmpty()) {
194+
throw new S3Exception(S3ExceptionCode.S3_FILE_EMPTY);
195+
}
196+
193197
Problem problem = problemDomainService.getProblem(problemId);
194198

195199
// 1. S3 업로드

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ public List<ProblemCategory> getProblemsCategoryList(List<Problem> problem) {
4848
return problemCategoryRepository.findByProblemIdsIn(problemIds);
4949
}
5050

51-
public void updateCategoryAndSearchEngine(Problem problem, List<String> categories) {
51+
public void updateCategoryAndSearchEngine(Problem problem, Map<String, String> categories) {
5252

5353
problemCategoryRepository.deleteAllByProblemId(problem.getId());
5454

55-
List<Category> categoryList = categoryRepository.findAllByCategoryCodeIn(categories);
55+
List<String> codes = new ArrayList<>(categories.keySet());
56+
List<Category> categoryList = categoryRepository.findAllByCategoryCodeIn(codes);
5657

5758
List<ProblemCategory> problemCategories = categoryList.stream()
5859
.map(cat -> ProblemCategory.from(problem, cat))

src/main/java/org/ezcode/codetest/infrastructure/s3/exception/code/S3ExceptionCode.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ public enum S3ExceptionCode implements ResponseCode {
1313
S3_UPLOAD_FAILED(false, HttpStatus.INTERNAL_SERVER_ERROR, "S3 이미지 업로드 중 오류가 발생 했습니다."),
1414
S3_INVALID_FILE_TYPE(false, HttpStatus.BAD_REQUEST, "이미지 파일만 업로드할 수 있습니다."),
1515
S3_DELETE_FAILED(false, HttpStatus.INTERNAL_SERVER_ERROR, "S3 이미지 삭제 중 오류가 발생 했습니다."),
16-
S3_FILE_TOO_LARGE(false, HttpStatus.BAD_REQUEST, "파일 크기가 허용 범위를 초과했습니다.");
16+
S3_FILE_TOO_LARGE(false, HttpStatus.BAD_REQUEST, "파일 크기가 허용 범위를 초과했습니다."),
17+
S3_FILE_EMPTY(false, HttpStatus.BAD_REQUEST, "업로드할 이미지 파일이 없습니다.");
1718

1819
private final boolean success;
1920

src/test/java/org/ezcode/codetest/application/problem/service/ProblemServiceTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,13 @@ void modifyProblem() {
163163

164164
when(problemDomainService.getProblem(1L)).thenReturn(problem);
165165
when(updateRequest.title()).thenReturn("새 제목");
166-
when(updateRequest.categories()).thenReturn(List.of("MATH"));
166+
when(updateRequest.categories()).thenReturn(Map.of("MATH", "수학"));
167167
// when
168168
problemService.modifyProblem(1L, updateRequest, null);
169169

170170
// then
171171
verify(problem).update(any(), any(), any(), any(), any(), any(), any());
172-
verify(problemDomainService).updateCategoryAndSearchEngine(problem, List.of("MATH"));
172+
verify(problemDomainService).updateCategoryAndSearchEngine(problem, Map.of("MATH", "수학"));
173173
}
174174

175175
@Test

0 commit comments

Comments
 (0)