From f51b132988d42c505aab8e084178fe44d389415f Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Fri, 11 Oct 2024 17:01:07 +0900 Subject: [PATCH] =?UTF-8?q?[fix]=20:=20request=20file=20=EC=97=86=EC=9D=84?= =?UTF-8?q?=20=EB=95=8C=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/event/service/EventServiceImpl.java | 4 ++-- .../domain/meetings/service/MeetingsServiceImpl.java | 4 ++-- .../domain/rule/controller/RuleAdminController.java | 2 +- .../bigbrotherbe/domain/rule/service/RuleServiceImpl.java | 4 ++-- .../domain/transactions/service/TransactionsService.java | 2 +- .../transactions/service/TransactionsServiceImpl.java | 7 +++++-- .../example/bigbrotherbe/global/file/util/FileUtil.java | 7 +++++++ 7 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java index 707531f..74c74db 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/event/service/EventServiceImpl.java @@ -51,10 +51,10 @@ public void registerEvent(EventRegisterRequest eventRegisterRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { + fileUtil.CheckImageFiles(multipartFiles); + FileSaveDTO fileSaveDTO = FileSaveDTO.builder() .fileType(EntityType.EVENT_TYPE.getType()) .multipartFileList(multipartFiles) diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java index 23d73be..234ba50 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsServiceImpl.java @@ -50,10 +50,10 @@ public void registerMeetings(MeetingsRegisterRequest meetingsRegisterRequest, Li throw new BusinessException(NOT_COUNCIL_MEMBER); } - fileUtil.checkPdfFiles(multipartFiles); - List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { + fileUtil.checkPdfFiles(multipartFiles); + FileSaveDTO fileSaveDTO = FileSaveDTO.builder() .fileType(EntityType.MEETINGS_TYPE.getType()) .multipartFileList(multipartFiles) diff --git a/src/main/java/com/example/bigbrotherbe/domain/rule/controller/RuleAdminController.java b/src/main/java/com/example/bigbrotherbe/domain/rule/controller/RuleAdminController.java index 166ef30..4429749 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/rule/controller/RuleAdminController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/rule/controller/RuleAdminController.java @@ -31,7 +31,7 @@ public class RuleAdminController { @PostMapping public ResponseEntity> registerRule(@RequestPart(value = "ruleRegisterRequest") RuleRegisterRequest ruleRegisterRequest, - @RequestPart(value = "file", required = false) List multipartFiles) { + @RequestPart(value = "file") List multipartFiles) { ruleService.registerRule(ruleRegisterRequest, multipartFiles); return ResponseEntity.ok(ApiResponse.success(SUCCESS)); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java index 10ff85c..8855f0d 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/rule/service/RuleServiceImpl.java @@ -51,10 +51,10 @@ public void registerRule(RuleRegisterRequest ruleRegisterRequest, List files = null; if (fileService.checkExistRequestFile(multipartFiles)) { + fileUtil.checkPdfFiles(multipartFiles); + FileSaveDTO fileSaveDTO = FileSaveDTO.builder() .fileType(EntityType.RULE_TYPE.getType()) .multipartFileList(multipartFiles) diff --git a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsService.java b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsService.java index 73b5112..bdedcc4 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsService.java @@ -7,7 +7,7 @@ import java.util.List; public interface TransactionsService { - void register(MultipartFile multipartFile, Long affiliationId); + void register(MultipartFile multipartFiles, Long affiliationId); void update(Long transactionsId, TransactionsUpdateRequest transactionsUpdateRequest); diff --git a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java index c75be27..e0a3bb6 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/domain/transactions/service/TransactionsServiceImpl.java @@ -12,6 +12,7 @@ import com.example.bigbrotherbe.global.common.enums.EntityType; import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.auth.util.AuthUtil; +import com.example.bigbrotherbe.global.file.util.FileUtil; import com.example.bigbrotherbe.global.ocr.dto.OcrDto; import com.example.bigbrotherbe.global.ocr.service.OcrService; import lombok.RequiredArgsConstructor; @@ -40,6 +41,7 @@ public class TransactionsServiceImpl implements TransactionsService { private final FileService fileService; private final AuthUtil authUtil; + private final FileUtil fileUtil; @Override @Transactional(rollbackFor = Exception.class) @@ -48,7 +50,7 @@ public void register(MultipartFile multipartFile, Long affiliationId) { throw new BusinessException(NO_EXIST_AFFILIATION); } - if (multipartFile == null || multipartFile.isEmpty()) { + if (multipartFile == null) { throw new BusinessException(EMPTY_FILE); } @@ -56,8 +58,9 @@ public void register(MultipartFile multipartFile, Long affiliationId) { throw new BusinessException(NOT_COUNCIL_MEMBER); } - OcrDto ocrDTO = ocrService.extractText(multipartFile); + fileUtil.checkPdfFile(multipartFile); + OcrDto ocrDTO = ocrService.extractText(multipartFile); List parseTransactions = ocrDTO.getParseTransactions(); String parseAccountNumber = ocrDTO.getParseAccountNumber(); diff --git a/src/main/java/com/example/bigbrotherbe/global/file/util/FileUtil.java b/src/main/java/com/example/bigbrotherbe/global/file/util/FileUtil.java index dd65104..f4756de 100644 --- a/src/main/java/com/example/bigbrotherbe/global/file/util/FileUtil.java +++ b/src/main/java/com/example/bigbrotherbe/global/file/util/FileUtil.java @@ -40,4 +40,11 @@ public void checkPdfFiles(List multipartFiles) { throw new BusinessException(INVALID_PDF_TYPE); }); } + + public void checkPdfFile(MultipartFile file) { + String contentType = file.getContentType(); + if (contentType == null || !contentType.equals(MediaType.APPLICATION_PDF_VALUE)) { + throw new BusinessException(INVALID_PDF_TYPE); + } + } }