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
@@ -1,6 +1,6 @@
package org.ezcode.codetest.application.problem.dto.request;

import java.util.List;
import java.util.Map;

import org.ezcode.codetest.domain.problem.model.entity.Problem;
import org.ezcode.codetest.domain.problem.model.enums.Difficulty;
Expand All @@ -11,9 +11,9 @@

public record ProblemUpdateRequest(

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

@Schema(description = "제목", example = "A+B")
String title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ private void updateProblemImage(Problem problem, MultipartFile newImage) {

@Transactional
public void addImageToExistingProblem(Long problemId, MultipartFile imageFile) {
if (imageFile == null || imageFile.isEmpty()) {
throw new S3Exception(S3ExceptionCode.S3_FILE_EMPTY);
}

Problem problem = problemDomainService.getProblem(problemId);

// 1. S3 업로드
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,12 @@ public List<ProblemCategory> getProblemsCategoryList(List<Problem> problem) {
return problemCategoryRepository.findByProblemIdsIn(problemIds);
}

public void updateCategoryAndSearchEngine(Problem problem, List<String> categories) {
public void updateCategoryAndSearchEngine(Problem problem, Map<String, String> categories) {

problemCategoryRepository.deleteAllByProblemId(problem.getId());

List<Category> categoryList = categoryRepository.findAllByCategoryCodeIn(categories);
List<String> codes = new ArrayList<>(categories.keySet());
List<Category> categoryList = categoryRepository.findAllByCategoryCodeIn(codes);

List<ProblemCategory> problemCategories = categoryList.stream()
.map(cat -> ProblemCategory.from(problem, cat))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ public enum S3ExceptionCode implements ResponseCode {
S3_UPLOAD_FAILED(false, HttpStatus.INTERNAL_SERVER_ERROR, "S3 이미지 업로드 중 오류가 발생 했습니다."),
S3_INVALID_FILE_TYPE(false, HttpStatus.BAD_REQUEST, "이미지 파일만 업로드할 수 있습니다."),
S3_DELETE_FAILED(false, HttpStatus.INTERNAL_SERVER_ERROR, "S3 이미지 삭제 중 오류가 발생 했습니다."),
S3_FILE_TOO_LARGE(false, HttpStatus.BAD_REQUEST, "파일 크기가 허용 범위를 초과했습니다.");
S3_FILE_TOO_LARGE(false, HttpStatus.BAD_REQUEST, "파일 크기가 허용 범위를 초과했습니다."),
S3_FILE_EMPTY(false, HttpStatus.BAD_REQUEST, "업로드할 이미지 파일이 없습니다.");

private final boolean success;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,13 @@ void modifyProblem() {

when(problemDomainService.getProblem(1L)).thenReturn(problem);
when(updateRequest.title()).thenReturn("새 제목");
when(updateRequest.categories()).thenReturn(List.of("MATH"));
when(updateRequest.categories()).thenReturn(Map.of("MATH", "수학"));
// when
problemService.modifyProblem(1L, updateRequest, null);

// then
verify(problem).update(any(), any(), any(), any(), any(), any(), any());
verify(problemDomainService).updateCategoryAndSearchEngine(problem, List.of("MATH"));
verify(problemDomainService).updateCategoryAndSearchEngine(problem, Map.of("MATH", "수학"));
}

@Test
Expand Down