From 8a889c71af19cca4f8b58d78a2c4abb7e711c7fd Mon Sep 17 00:00:00 2001 From: kric_jspark Date: Wed, 1 Apr 2026 15:08:19 +0900 Subject: [PATCH] =?UTF-8?q?260401=5F01=5FENH:=20=EC=BD=94=EB=93=9C=20?= =?UTF-8?q?=EC=9D=BC=EB=B6=80=20=EB=A6=AC=ED=8C=A9=ED=86=A0=EB=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UploadController.java | 42 +++++++++---------- 1 file changed, 20 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/kri/lge/penetration/controller/UploadController.java b/src/main/java/com/kri/lge/penetration/controller/UploadController.java index 77f6a36..292904f 100644 --- a/src/main/java/com/kri/lge/penetration/controller/UploadController.java +++ b/src/main/java/com/kri/lge/penetration/controller/UploadController.java @@ -9,8 +9,8 @@ import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.media.Content; import io.swagger.v3.oas.annotations.media.Schema; import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; +import java.net.URLEncoder; import java.nio.charset.StandardCharsets; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpHeaders; @@ -29,6 +29,7 @@ import org.springframework.web.multipart.MultipartFile; public class UploadController { private static final String XLSX = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; + private static final MediaType XLSX_MEDIA_TYPE = MediaType.valueOf(XLSX); private final StatisticsDbCache statisticsDbCache; private final UploadService uploadService; @@ -39,23 +40,21 @@ public class UploadController { produces = {MediaType.APPLICATION_JSON_VALUE, XLSX} ) @Operation(summary = "파일 업로드", description = "성공이면 JSON, 실패가 있으면 실패 내역 엑셀(xlsx) 반환") - @ApiResponses({ - @ApiResponse( - responseCode = "200", - description = "성공(JSON) 또는 실패 엑셀(xlsx)", - content = { - @Content( - mediaType = MediaType.APPLICATION_JSON_VALUE, - schema = @Schema(implementation = ExcelUploadSuccessDto.class) - ), - @Content( - mediaType = XLSX, - schema = @Schema(type = "string", format = "binary") - ) - } + @ApiResponse( + responseCode = "200", + description = "성공(JSON) 또는 실패 엑셀(xlsx)", + content = { + @Content( + mediaType = MediaType.APPLICATION_JSON_VALUE, + schema = @Schema(implementation = ExcelUploadSuccessDto.class) + ), + @Content( + mediaType = XLSX, + schema = @Schema(type = "string", format = "binary") ) - }) - public ResponseEntity importData( + } + ) + public ResponseEntity importData( @Parameter(description = "업로드 파일", required = true) @RequestPart("file") MultipartFile file ) { @@ -64,15 +63,14 @@ public class UploadController { ExcelUploadResultDto result = uploadService.uploadData(file); if (result.isHasErrorFile()) { String contentDisposition = "attachment; filename*=UTF-8''" + - java.net.URLEncoder.encode(result.getErrorFileName(), StandardCharsets.UTF_8); + URLEncoder.encode(result.getErrorFileName(), StandardCharsets.UTF_8); return ResponseEntity.ok() .header(HttpHeaders.CONTENT_DISPOSITION, contentDisposition) - .contentType(MediaType.parseMediaType(XLSX)) + .contentType(XLSX_MEDIA_TYPE) .body(result.getErrorFile()); - - } else { - return ResponseEntity.ok(ExcelUploadSuccessDto.from(result)); } + + return ResponseEntity.ok(ExcelUploadSuccessDto.from(result)); } }