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 @@ -53,10 +53,14 @@ public record ProblemDetailResponse(
@Schema(description = "문제 이미지 URL", example = "https://bucket.s3.ap-northeast-2.amazonaws.com/problem/example.jpg")
String imageUrl,

@Schema(description = "문제 이미지 파일명", example = "example.jpg")
String imageName,

List<TestcaseResponse> testcases
) {

public static ProblemDetailResponse from(Problem problem, List<Category> categories) {
String imageUrl = problem.getImageUrl().isEmpty() ? null : problem.getImageUrl().get(0);

return ProblemDetailResponse.builder()
.id(problem.getId())
Expand All @@ -71,8 +75,17 @@ public static ProblemDetailResponse from(Problem problem, List<Category> categor
.reference(problem.getReference())
.createdAt(problem.getCreatedAt())
.modifiedAt(problem.getModifiedAt())
.imageUrl(problem.getImageUrl().isEmpty() ? null : problem.getImageUrl().get(0))
.imageUrl(imageUrl)
.imageName(extractFileName(imageUrl))
.testcases(problem.top2Testcases().stream().map(TestcaseResponse::from).toList())
.build();
}

private static String extractFileName(String url) {
if (url == null || url.isBlank()) {
return null;
}
int lastSlashIndex = url.lastIndexOf('/');
return lastSlashIndex >= 0 ? url.substring(lastSlashIndex + 1) : url;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -196,13 +196,21 @@ public void addImageToExistingProblem(Long problemId, MultipartFile imageFile) {

Problem problem = problemDomainService.getProblem(problemId);

// 1. S3 업로드
// 1. 기존 이미지가 있으면 S3에서 삭제
if (!problem.getImageUrl().isEmpty()) {
for (String fileUrl : problem.getImageUrl()) {
s3Uploader.delete(fileUrl, "problem");
}
problem.clearImages();
}

// 2. S3 업로드
String key = s3Uploader.upload(imageFile, "problem");

// 2. 문제에 이미지 연결
problem.addImage(key); // 또는 setImageUrl(List.of(key))
// 3. 문제에 이미지 연결
problem.addImage(key);

// 3. 저장
// 4. 저장
problemDomainService.saveProblem(problem);
}

Expand Down