From f6c2d49d474c121c2c071c0379bc6d76860b2e05 Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Sat, 26 Aug 2023 20:01:10 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[ADD]=20=EC=97=85=EB=AC=B4=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=20=EC=83=9D=EC=84=B1=20=EC=8B=9C,=20=EC=83=9D?= =?UTF-8?q?=EC=84=B1=EB=90=9C=20=EC=97=85=EB=AC=B4=20=EC=B9=B4=EB=93=9C=20?= =?UTF-8?q?id=EB=A5=BC=20response=20header=EB=A1=9C=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../katchupserver/api/card/controller/CardController.java | 6 ++++-- .../katchup/katchupserver/api/card/service/CardService.java | 2 +- .../api/card/service/Impl/CardServiceImpl.java | 4 +++- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/java/site/katchup/katchupserver/api/card/controller/CardController.java b/src/main/java/site/katchup/katchupserver/api/card/controller/CardController.java index 5dc3afa..534cb95 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/controller/CardController.java +++ b/src/main/java/site/katchup/katchupserver/api/card/controller/CardController.java @@ -5,6 +5,7 @@ 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 jakarta.servlet.http.HttpServletResponse; import jakarta.validation.Valid; import lombok.RequiredArgsConstructor; import org.springframework.http.HttpStatus; @@ -35,9 +36,10 @@ public class CardController { @PostMapping @ResponseStatus(HttpStatus.CREATED) public ApiResponseDto createCard(Principal principal, - @Valid @RequestBody CardCreateRequestDto cardCreateRequestDto ) { + @Valid @RequestBody CardCreateRequestDto cardCreateRequestDto, HttpServletResponse response) { Long memberId = MemberUtil.getMemberId(principal); - cardService.createCard(memberId, cardCreateRequestDto); + Long cardId = cardService.createCard(memberId, cardCreateRequestDto); + response.addHeader("Location", String.valueOf(cardId)); return ApiResponseDto.success(); } diff --git a/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java b/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java index 51aff62..de0f50b 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java +++ b/src/main/java/site/katchup/katchupserver/api/card/service/CardService.java @@ -15,7 +15,7 @@ public interface CardService { List getCardList(Long taskId); CardGetResponseDto getCard(Long cardId); void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto); - void createCard(Long memberId, CardCreateRequestDto cardCreateRequestDto); + Long createCard(Long memberId, CardCreateRequestDto cardCreateRequestDto); void updateCard(Long memberId, Long cardId, CardUpdateRequestDto cardUpdateRequestDto); } diff --git a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java index 5b72ba5..cb332fa 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java @@ -95,7 +95,7 @@ public void deleteCardList(CardDeleteRequestDto cardDeleteRequestDto) { @Override @Transactional - public void createCard(Long memberId, CardCreateRequestDto requestDto) { + public Long createCard(Long memberId, CardCreateRequestDto requestDto) { SubTask subTask; if (requestDto.getSubTaskId() == SUB_TASK_ETC_ID) { @@ -154,6 +154,8 @@ public void createCard(Long memberId, CardCreateRequestDto requestDto) { fileRepository.save(newFile); } + + return savedCard.getId(); } @Override From 149edaf20b6f3bbd52691ef285ca934c195c64ce Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Sat, 26 Aug 2023 22:06:57 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[FIX]=20=EC=97=85=EB=AC=B4=20=EC=B9=B4?= =?UTF-8?q?=EB=93=9C=20=EC=83=9D=EC=84=B1=20=EC=A0=84=20=ED=8C=8C=EC=9D=BC?= =?UTF-8?q?=20=EB=B0=8F=20=EC=8A=A4=ED=81=AC=EB=A6=B0=EC=83=B7=20=EC=82=AD?= =?UTF-8?q?=EC=A0=9C=20=EB=A1=9C=EC=A7=81=20=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../card/service/Impl/CardServiceImpl.java | 20 ++++++++++++------- .../api/file/controller/FileController.java | 8 +++++--- .../katchupserver/api/file/domain/File.java | 10 +++++++--- .../dto/request/FileCreateRequestDto.java | 8 ++++++-- .../file/dto/response/FileGetResponseDto.java | 7 +++++-- .../api/file/repository/FileRepository.java | 1 + .../api/file/service/FileService.java | 4 ++-- .../file/service/Impl/FileServiceImpl.java | 15 +++++++------- .../controller/ScreenshotController.java | 8 +++++--- .../screenshot/service/ScreenshotService.java | 5 ++--- .../service/impl/ScreenshotServiceImpl.java | 18 +++++++++-------- 11 files changed, 64 insertions(+), 40 deletions(-) diff --git a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java index cb332fa..0e40035 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/card/service/Impl/CardServiceImpl.java @@ -125,7 +125,8 @@ public Long createCard(Long memberId, CardCreateRequestDto requestDto) { for (ScreenshotCreateRequestDto screenshotInfo : requestDto.getScreenshotList()) { Screenshot newScreenshot = Screenshot.builder() .id(screenshotInfo.getScreenshotUUID()) - .screenshotKey(screenshotService.createKey(memberId, screenshotInfo)) + .screenshotKey(screenshotService.createKey(memberId, screenshotInfo.getScreenshotUploadDate(), screenshotInfo.getScreenshotUUID().toString(), + screenshotInfo.getScreenshotName())) .url(screenshotService.findUrl(memberId, screenshotInfo)) .card(savedCard) .build(); @@ -146,8 +147,10 @@ public Long createCard(Long memberId, CardCreateRequestDto requestDto) { for (FileCreateRequestDto fileInfo : requestDto.getFileList()) { File newFile = File.builder() .id(fileInfo.getFileUUID()) - .fileKey(fileService.createKey(memberId, fileInfo)) - .name(fileInfo.getFileName()) + .fileKey(fileService.createKey(memberId, fileInfo.getFileUploadDate(), fileInfo.getFileUUID().toString() + , fileInfo.getFileOriginalName())) + .originalName(fileInfo.getFileOriginalName()) + .changedName(fileInfo.getFileChangedName()) .size(fileInfo.getSize()) .card(savedCard) .build(); @@ -187,7 +190,8 @@ public void updateCard(Long memberId, Long cardId, CardUpdateRequestDto requestD for (ScreenshotCreateRequestDto screenshotInfo : requestDto.getScreenshotList()) { Screenshot newScreenshot = Screenshot.builder() .id(screenshotInfo.getScreenshotUUID()) - .screenshotKey(screenshotService.createKey(memberId, screenshotInfo)) + .screenshotKey(screenshotService.createKey(memberId, screenshotInfo.getScreenshotUploadDate(), screenshotInfo.getScreenshotUUID().toString(), + screenshotInfo.getScreenshotName())) .url(screenshotService.findUrl(memberId, screenshotInfo)) .card(card) .build(); @@ -198,8 +202,10 @@ public void updateCard(Long memberId, Long cardId, CardUpdateRequestDto requestD for (FileCreateRequestDto fileInfo : requestDto.getFileList()) { File newFile = File.builder() .id(fileInfo.getFileUUID()) - .fileKey(fileService.createKey(memberId, fileInfo)) - .name(fileInfo.getFileName()) + .fileKey(fileService.createKey(memberId, fileInfo.getFileUploadDate(), fileInfo.getFileUUID().toString() + , fileInfo.getFileOriginalName())) + .originalName(fileInfo.getFileOriginalName()) + .changedName(fileInfo.getFileChangedName()) .size(fileInfo.getSize()) .card(card) .build(); @@ -262,7 +268,7 @@ private List getScreenshotDtoList(Long cardId) { private List getFileDtoList(Long cardId) { return cardRepository.findByIdOrThrow(cardId).getFiles().stream() - .map(file -> FileGetResponseDto.of(file.getId(), file.getName(), file.getSize())) + .map(file -> FileGetResponseDto.of(file.getId(), file.getOriginalName(), file.getChangedName(), file.getSize())) .collect(Collectors.toList()); } diff --git a/src/main/java/site/katchup/katchupserver/api/file/controller/FileController.java b/src/main/java/site/katchup/katchupserver/api/file/controller/FileController.java index 7b05535..4b668fe 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/controller/FileController.java +++ b/src/main/java/site/katchup/katchupserver/api/file/controller/FileController.java @@ -46,10 +46,12 @@ public ApiResponseDto upload(Principal princi @ApiResponse(responseCode = "400", description = "파일 삭제 실패", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) - @DeleteMapping("/files/{fileId}") + @DeleteMapping("/files") @ResponseStatus(HttpStatus.OK) - public ApiResponseDto delete(@PathVariable String fileId) { - fileService.deleteFile(fileId); + public ApiResponseDto delete(Principal principal, @RequestParam(value = "fileOriginalName") String fileOriginalName + , @RequestParam(value = "fileUploadDate") String fileUploadDate, @RequestParam(value = "fileUUID") String fileUUID) { + Long memberId = MemberUtil.getMemberId(principal); + fileService.deleteFile(memberId, fileOriginalName, fileUploadDate, fileUUID); return success(); } diff --git a/src/main/java/site/katchup/katchupserver/api/file/domain/File.java b/src/main/java/site/katchup/katchupserver/api/file/domain/File.java index 16d5650..97c2a63 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/domain/File.java +++ b/src/main/java/site/katchup/katchupserver/api/file/domain/File.java @@ -21,7 +21,10 @@ public class File extends BaseEntity { private UUID id; @Column(nullable = false) - private String name; + private String originalName; + + @Column(nullable = false) + private String changedName; @Column(nullable = false, name = "file_key") private String fileKey; @@ -34,9 +37,10 @@ public class File extends BaseEntity { private Card card; @Builder - public File(UUID id, String name, String fileKey, int size, Card card) { + public File(UUID id, String originalName, String changedName, String fileKey, int size, Card card) { this.id = id; - this.name = name; + this.originalName = originalName; + this.changedName = changedName; this.fileKey = fileKey; this.card = card; this.size = size; diff --git a/src/main/java/site/katchup/katchupserver/api/file/dto/request/FileCreateRequestDto.java b/src/main/java/site/katchup/katchupserver/api/file/dto/request/FileCreateRequestDto.java index 10147a2..c081553 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/dto/request/FileCreateRequestDto.java +++ b/src/main/java/site/katchup/katchupserver/api/file/dto/request/FileCreateRequestDto.java @@ -16,9 +16,13 @@ public class FileCreateRequestDto { @NotNull private UUID fileUUID; - @Schema(description = "파일 이름", example = "와이어프레임 및 드라이브 사용법.pdf") + @Schema(description = "파일 원본 이름", example = "와이어프레임 및 드라이브 사용법.pdf") @NotNull - private String fileName; + private String fileOriginalName; + + @Schema(description = "파일 변경된 이름", example = "카테고리_업무_세부업무_와이어프레임 사용법.pdf") + @NotNull + private String fileChangedName; @Schema(description = "파일 업로드 일자", example = "2023/08/23") @NotNull diff --git a/src/main/java/site/katchup/katchupserver/api/file/dto/response/FileGetResponseDto.java b/src/main/java/site/katchup/katchupserver/api/file/dto/response/FileGetResponseDto.java index 4a8158c..62abc28 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/dto/response/FileGetResponseDto.java +++ b/src/main/java/site/katchup/katchupserver/api/file/dto/response/FileGetResponseDto.java @@ -13,8 +13,11 @@ public class FileGetResponseDto { @Schema(description = "파일 고유 id", example = "ddwd-wdwd-wdwd-wdwdwdwd") private UUID id; - @Schema(description = "파일 이름", example = "와이어프레임 및 드라이브 사용법.pdf") - private String name; + @Schema(description = "파일 원본 이름", example = "와이어프레임 및 드라이브 사용법.pdf") + private String originalName; + + @Schema(description = "파일 변경된 이름", example = "카테고리_업무_세부업무_와이어프레임 사용법.pdf") + private String changedName; @Schema(description = "파일 사이즈 (KB 단위로 저장)", example = "189277") private int size; diff --git a/src/main/java/site/katchup/katchupserver/api/file/repository/FileRepository.java b/src/main/java/site/katchup/katchupserver/api/file/repository/FileRepository.java index ca98082..d1c6bb1 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/repository/FileRepository.java +++ b/src/main/java/site/katchup/katchupserver/api/file/repository/FileRepository.java @@ -17,4 +17,5 @@ default File findByIdOrThrow(UUID uuid) { return findById(uuid).orElseThrow( () -> new NotFoundException(ErrorCode.NOT_FOUND_FILE)); } + } diff --git a/src/main/java/site/katchup/katchupserver/api/file/service/FileService.java b/src/main/java/site/katchup/katchupserver/api/file/service/FileService.java index 46d9780..c01b8d5 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/service/FileService.java +++ b/src/main/java/site/katchup/katchupserver/api/file/service/FileService.java @@ -9,9 +9,9 @@ public interface FileService { FileGetDownloadPreSignedResponseDto getDownloadPreSignedUrl(String filePath, String fileName); - String createKey(Long memberId, FileCreateRequestDto requestDto); + String createKey(Long memberId, String fileDate, String fileUUID, String fileName); - void deleteFile(String fileId); + void deleteFile(Long memberId, String fileOriginalName, String fileUploadDate, String fileUUID); FileGetUploadPreSignedResponseDto getUploadPreSignedUrl(Long memberId, String fileName); diff --git a/src/main/java/site/katchup/katchupserver/api/file/service/Impl/FileServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/file/service/Impl/FileServiceImpl.java index e7b7f18..a28c4ce 100644 --- a/src/main/java/site/katchup/katchupserver/api/file/service/Impl/FileServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/file/service/Impl/FileServiceImpl.java @@ -14,6 +14,7 @@ import site.katchup.katchupserver.common.util.S3Util; import java.util.HashMap; +import java.util.Optional; import java.util.UUID; @Service @@ -47,18 +48,18 @@ public FileGetDownloadPreSignedResponseDto getDownloadPreSignedUrl(String fileUU @Override @Transactional - public String createKey(Long memberId, FileCreateRequestDto requestDto) { + public String createKey(Long memberId, String fileDate, String fileUUID, String fileName) { String fileUploadPrefix = makeUploadPrefix(memberId); - return fileUploadPrefix + "/" + requestDto.getFileUploadDate() + "/" + requestDto.getFileUUID() + requestDto.getFileName(); + return fileUploadPrefix + "/" + fileDate + "/" + fileUUID + fileName; } @Override @Transactional - public void deleteFile(String fileId) { - File file = fileRepository.findByIdOrThrow(UUID.fromString(fileId)); - String fileKey = file.getFileKey(); - s3Util.deleteFile(fileKey); - fileRepository.deleteById(UUID.fromString(fileId)); + public void deleteFile(Long memberId, String fileOriginalName, String fileUploadDate, String fileUUID) { + Optional file = fileRepository.findById(UUID.fromString(fileUUID)); + if (file.isPresent()) { + fileRepository.delete(file.get()); + } s3Util.deleteFile(createKey(memberId, fileUploadDate, fileUUID, fileOriginalName)); } private String makeUploadPrefix(Long memberId) { diff --git a/src/main/java/site/katchup/katchupserver/api/screenshot/controller/ScreenshotController.java b/src/main/java/site/katchup/katchupserver/api/screenshot/controller/ScreenshotController.java index 02443b8..a9c3e2c 100644 --- a/src/main/java/site/katchup/katchupserver/api/screenshot/controller/ScreenshotController.java +++ b/src/main/java/site/katchup/katchupserver/api/screenshot/controller/ScreenshotController.java @@ -46,10 +46,12 @@ public ApiResponseDto createPresigned(Princip @ApiResponse(responseCode = "400", description = "스크린샷 삭제 실패", content = @Content), @ApiResponse(responseCode = "500", description = "서버 오류", content = @Content) }) - @DeleteMapping("/screenshots/{screenshotId}") + @DeleteMapping("/screenshots") @ResponseStatus(HttpStatus.OK) - public ApiResponseDto deleteScreenshot(@PathVariable String screenshotId) { - screenshotService.delete(screenshotId); + public ApiResponseDto delete(Principal principal, @RequestParam(value = "screenshotName") String screenshotName + , @RequestParam(value = "screenshotUploadDate") String screenshotUploadDate, @RequestParam(value = "screenshotUUID") String screenshotUUID) { + Long memberId = MemberUtil.getMemberId(principal); + screenshotService.deleteFile(memberId, screenshotName, screenshotUploadDate, screenshotUUID); return success(); } diff --git a/src/main/java/site/katchup/katchupserver/api/screenshot/service/ScreenshotService.java b/src/main/java/site/katchup/katchupserver/api/screenshot/service/ScreenshotService.java index cb7f7b8..ece4378 100644 --- a/src/main/java/site/katchup/katchupserver/api/screenshot/service/ScreenshotService.java +++ b/src/main/java/site/katchup/katchupserver/api/screenshot/service/ScreenshotService.java @@ -8,10 +8,9 @@ public interface ScreenshotService { ScreenshotGetPreSignedResponseDto getPreSignedUrl(Long memberId, String screenshotName); - @Transactional - String createKey(Long memberId, ScreenshotCreateRequestDto requestDto); + String createKey(Long memberId, String screenshotDate, String screenshotUUID, String screenshotName); - void delete(String screenshotId); + void deleteFile(Long memberId, String screenshotName, String screenshotUploadDate, String screenshotUUID); String findUrl(Long memberId, ScreenshotCreateRequestDto requestDto); } diff --git a/src/main/java/site/katchup/katchupserver/api/screenshot/service/impl/ScreenshotServiceImpl.java b/src/main/java/site/katchup/katchupserver/api/screenshot/service/impl/ScreenshotServiceImpl.java index 99912a7..8cde29d 100644 --- a/src/main/java/site/katchup/katchupserver/api/screenshot/service/impl/ScreenshotServiceImpl.java +++ b/src/main/java/site/katchup/katchupserver/api/screenshot/service/impl/ScreenshotServiceImpl.java @@ -14,6 +14,7 @@ import site.katchup.katchupserver.common.util.S3Util; import java.util.HashMap; +import java.util.Optional; import java.util.UUID; @Service @@ -40,23 +41,24 @@ public ScreenshotGetPreSignedResponseDto getPreSignedUrl(Long memberId, String s @Override @Transactional public String findUrl(Long memberId, ScreenshotCreateRequestDto requestDto) { - return s3Util.findUrlByName(createKey(memberId, requestDto)); + return s3Util.findUrlByName(createKey(memberId, requestDto.getScreenshotUploadDate(), requestDto.getScreenshotUUID().toString() + , requestDto.getScreenshotName())); } @Override @Transactional - public String createKey(Long memberId, ScreenshotCreateRequestDto requestDto) { + public String createKey(Long memberId, String screenshotDate, String screenshotUUID, String screenshotName) { String screenshotUploadPrefix = makeUploadPrefix(memberId); - return screenshotUploadPrefix + "/" + requestDto.getScreenshotUploadDate() + "/" + requestDto.getScreenshotUUID() + requestDto.getScreenshotName(); + return screenshotUploadPrefix + "/" + screenshotDate + "/" + screenshotUUID + screenshotName; } @Override @Transactional - public void delete(String screenshotId) { - Screenshot screenshot = screenshotRepository.findByIdOrThrow(UUID.fromString(screenshotId)); - String screenshotKey = screenshot.getScreenshotKey(); - s3Util.deleteFile(screenshotKey); - screenshotRepository.deleteById(UUID.fromString(screenshotId)); + public void deleteFile(Long memberId, String screenshotName, String screenshotUploadDate, String screenshotUUID) { + Optional screenshot = screenshotRepository.findById(UUID.fromString(screenshotUUID)); + if (screenshot.isPresent()) { + screenshotRepository.delete(screenshot.get()); + } s3Util.deleteFile(createKey(memberId, screenshotUploadDate, screenshotUUID, screenshotName)); } private String makeUploadPrefix(Long memberId) { From 3789d822d70cd6cb832e460545e0614afad112bc Mon Sep 17 00:00:00 2001 From: yeseul106 <20191037@sungshin.ac.kr> Date: Sat, 26 Aug 2023 22:10:39 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[ADD]=20=EC=97=85=EB=AC=B4=20=EB=82=B4=20?= =?UTF-8?q?=EC=97=85=EB=AC=B4=20=EC=B9=B4=EB=93=9C=20=EB=AA=A9=EB=A1=9D=20?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EC=8B=9C,=20=EC=8A=A4=ED=81=AC=EB=A6=B0?= =?UTF-8?q?=EC=83=B7=20=EC=9C=A0=EB=AC=B4=EA=B0=92=EB=8F=84=20=EA=B0=99?= =?UTF-8?q?=EC=9D=B4=20=EB=82=B4=EB=A0=A4=EC=A3=BC=EB=8F=84=EB=A1=9D=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/card/dto/response/CardListGetResponseDto.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/main/java/site/katchup/katchupserver/api/card/dto/response/CardListGetResponseDto.java b/src/main/java/site/katchup/katchupserver/api/card/dto/response/CardListGetResponseDto.java index df710a2..ad7a0a3 100644 --- a/src/main/java/site/katchup/katchupserver/api/card/dto/response/CardListGetResponseDto.java +++ b/src/main/java/site/katchup/katchupserver/api/card/dto/response/CardListGetResponseDto.java @@ -22,9 +22,11 @@ public class CardListGetResponseDto { private List keywordList = new ArrayList<>(); private String content; private Boolean existFile; + private Boolean existScreenshot; public static CardListGetResponseDto of (Card card, SubTask subTask, List keywordList) { Boolean existFile = card.getFiles().isEmpty() ? false : true; + Boolean existScreenshot = card.getScreenshots().isEmpty() ? false : true; return CardListGetResponseDto.builder() .cardId(card.getId()) .subTaskId(subTask.getId()) @@ -33,6 +35,7 @@ public static CardListGetResponseDto of (Card card, SubTask subTask, List