From 3bcaa16361141cdf3cf24602ff2d759f11919ce4 Mon Sep 17 00:00:00 2001 From: dangnak2 <80161984+dangnak2@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:21:21 +0900 Subject: [PATCH 1/3] =?UTF-8?q?[PDS-32]=20feat:=20=EC=95=84=EC=B9=B4?= =?UTF-8?q?=EC=9D=B4=EB=B9=99=20=EC=9E=90=EB=A3=8C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?API=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/ArchivingController.java | 13 ++++++- .../dto/request/SearchMaterialReq.java | 9 +++++ .../dto/request/UploadMaterialReq.java | 1 + .../dto/response/SearchMaterialRes.java | 29 ++++++++++++++++ .../archiving/entity/Category.java | 26 ++++++++++++++ .../archiving/entity/Material.java | 6 +++- .../repository/MaterialRepository.java | 10 ++++++ .../archiving/service/ArchivingService.java | 34 +++++++++++++++++-- .../PLADIALMArchiving/global/Constants.java | 6 ++++ .../global/exception/BaseResponseCode.java | 16 ++------- 10 files changed, 132 insertions(+), 18 deletions(-) create mode 100644 src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/SearchMaterialReq.java create mode 100644 src/main/java/com/example/PLADIALMArchiving/archiving/dto/response/SearchMaterialRes.java create mode 100644 src/main/java/com/example/PLADIALMArchiving/archiving/entity/Category.java diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java b/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java index 7727696..19e67b6 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java @@ -1,6 +1,7 @@ package com.example.PLADIALMArchiving.archiving.controller; import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq; +import com.example.PLADIALMArchiving.archiving.dto.request.SearchMaterialReq; import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq; import com.example.PLADIALMArchiving.archiving.service.ArchivingService; import com.example.PLADIALMArchiving.global.resolver.Account; @@ -8,6 +9,7 @@ import com.example.PLADIALMArchiving.user.entity.User; import io.swagger.annotations.Api; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.*; @Api(tags = "아카이빙 API") @@ -40,10 +42,19 @@ public ResponseCustom uploadMaterial( archivingService.uploadMaterial(uploadMaterialReq, projectId, user); return ResponseCustom.OK(); } + /** * 자료목록을 조회 및 검색한다. */ - + @GetMapping("/projects/{projectId}") + public ResponseCustom searchMaterial( + @PathVariable Long projectId, + @RequestBody SearchMaterialReq searchMaterialReq, + Pageable pageable + ) + { + return ResponseCustom.OK(archivingService.searchMaterial(projectId, searchMaterialReq, pageable)); + } /** * 자료를 삭제한다. */ diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/SearchMaterialReq.java b/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/SearchMaterialReq.java new file mode 100644 index 0000000..3c26868 --- /dev/null +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/SearchMaterialReq.java @@ -0,0 +1,9 @@ +package com.example.PLADIALMArchiving.archiving.dto.request; + +import lombok.Getter; + +@Getter +public class SearchMaterialReq { + private String cond; + private String category; +} diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/UploadMaterialReq.java b/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/UploadMaterialReq.java index b4032db..0d7027c 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/UploadMaterialReq.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/dto/request/UploadMaterialReq.java @@ -6,5 +6,6 @@ public class UploadMaterialReq { private String fileKey; private String name; + private Long size; private String extension; } diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/dto/response/SearchMaterialRes.java b/src/main/java/com/example/PLADIALMArchiving/archiving/dto/response/SearchMaterialRes.java new file mode 100644 index 0000000..17579e2 --- /dev/null +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/dto/response/SearchMaterialRes.java @@ -0,0 +1,29 @@ +package com.example.PLADIALMArchiving.archiving.dto.response; + +import com.example.PLADIALMArchiving.archiving.entity.Material; +import com.example.PLADIALMArchiving.global.Constants; +import lombok.Builder; +import lombok.Data; + +import java.time.format.DateTimeFormatter; + +@Data +@Builder +public class SearchMaterialRes { + private Long materialId; + private String fileName; + private String createdAt; + private String publisher; + private Long size; + + public static SearchMaterialRes toDto(Material material) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(Constants.DATE_PATTERN); + return SearchMaterialRes.builder() + .materialId(material.getMaterialId()) + .fileName(material.getName()) + .publisher(material.getUser().getName()) + .createdAt(material.getCreatedAt().format(dateTimeFormatter)) + .size(material.getSize()) + .build(); + } +} diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Category.java b/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Category.java new file mode 100644 index 0000000..124ad54 --- /dev/null +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Category.java @@ -0,0 +1,26 @@ +package com.example.PLADIALMArchiving.archiving.entity; + +import com.example.PLADIALMArchiving.global.exception.BaseException; +import com.example.PLADIALMArchiving.global.exception.BaseResponseCode; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.Arrays; + +@Getter +@RequiredArgsConstructor +public enum Category { + + GENERAL("전체"), + IMAGE("이미지"), + VIDEO("비디오"), + DOCS("문서"); + + private final String value; + + public static Category getCategoryByValue(String value) { + return Arrays.stream(Category.values()) + .filter(r -> r.getValue().equals(value)) + .findAny().orElseThrow(() -> new BaseException(BaseResponseCode.CATEGORY_NOT_FOUND)); + } +} diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Material.java b/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Material.java index ae0e4ca..14d4ef0 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Material.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/entity/Material.java @@ -29,6 +29,8 @@ public class Material extends BaseEntity { private String extension; + private Long size; + private String fileKey; @ManyToOne(fetch = FetchType.LAZY) @@ -40,9 +42,10 @@ public class Material extends BaseEntity { private User user; @Builder - public Material(String name, String extension, String fileKey, Project project, User user) { + public Material(String name, String extension, Long size, String fileKey, Project project, User user) { this.name = name; this.extension = extension; + this.size = size; this.fileKey = fileKey; this.project = project; this.user = user; @@ -52,6 +55,7 @@ public static Material toEntity(UploadMaterialReq uploadMaterialReq, Project pro return Material.builder() .name(uploadMaterialReq.getName()) .extension(uploadMaterialReq.getExtension()) + .size(uploadMaterialReq.getSize()) .fileKey(uploadMaterialReq.getFileKey()) .project(project) .user(user) diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java b/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java index 301dcc8..ec931b3 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java @@ -1,9 +1,19 @@ package com.example.PLADIALMArchiving.archiving.repository; import com.example.PLADIALMArchiving.archiving.entity.Material; +import com.example.PLADIALMArchiving.archiving.entity.Project; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.stereotype.Repository; +import java.util.List; + @Repository public interface MaterialRepository extends JpaRepository { + +// @Query("SELECT mt FROM Material mt WHERE :extension LIKE CONCAT('%', mt.extension, '%') ") +// List findByProject(Project project, @Param("extension") String extension); + + Page findByProjectAndExtensionIn(Project project, List extensions, Pageable pageable); } diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java b/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java index c2b93dd..9df642e 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java @@ -1,20 +1,26 @@ package com.example.PLADIALMArchiving.archiving.service; import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq; +import com.example.PLADIALMArchiving.archiving.dto.request.SearchMaterialReq; import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq; +import com.example.PLADIALMArchiving.archiving.dto.response.SearchMaterialRes; +import com.example.PLADIALMArchiving.archiving.entity.Category; import com.example.PLADIALMArchiving.archiving.entity.Material; import com.example.PLADIALMArchiving.archiving.entity.Project; import com.example.PLADIALMArchiving.archiving.repository.MaterialRepository; import com.example.PLADIALMArchiving.archiving.repository.ProjectRepository; +import com.example.PLADIALMArchiving.global.Constants; import com.example.PLADIALMArchiving.global.exception.BaseException; import com.example.PLADIALMArchiving.global.exception.BaseResponseCode; import com.example.PLADIALMArchiving.user.entity.User; import com.example.PLADIALMArchiving.user.repository.UserRepository; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; - -import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; @Service @Transactional(readOnly = true) @@ -38,4 +44,28 @@ public void uploadMaterial(UploadMaterialReq uploadMaterialReq, Long projectId, Project project = projectRepository.findById(projectId).orElseThrow(() -> new BaseException(BaseResponseCode.PROJECT_NOT_FOUND)); materialRepository.save(Material.toEntity(uploadMaterialReq, project, user)); } + + public Page searchMaterial(Long projectId, SearchMaterialReq searchMaterialReq, Pageable pageable) { + Project project = projectRepository.findById(projectId).orElseThrow(() -> new BaseException(BaseResponseCode.PROJECT_NOT_FOUND)); + Category category = Category.getCategoryByValue(searchMaterialReq.getCategory()); + + Page filteredMaterials; + + if (category != Category.GENERAL) { + List extension = new ArrayList<>(); + if (category == Category.IMAGE) { + extension = List.of(Constants.EXTENSION.IMAGE.split(" ")); + } else if (category == Category.VIDEO) { + extension = List.of(Constants.EXTENSION.VIDEO.split(" ")); + } else if (category == Category.DOCS) { + extension = List.of(Constants.EXTENSION.DOCS.split(" ")); + } + filteredMaterials = materialRepository.findByProjectAndExtensionIn(project, extension, pageable); + } else { + filteredMaterials = materialRepository.findAll(pageable); + } + + return filteredMaterials.map(SearchMaterialRes::toDto); + } + } diff --git a/src/main/java/com/example/PLADIALMArchiving/global/Constants.java b/src/main/java/com/example/PLADIALMArchiving/global/Constants.java index 1ef83e3..22a95dd 100644 --- a/src/main/java/com/example/PLADIALMArchiving/global/Constants.java +++ b/src/main/java/com/example/PLADIALMArchiving/global/Constants.java @@ -16,4 +16,10 @@ public static class JWT{ public static final String LOGOUT = "logout"; public static final String SIGNOUT = "signout"; } + + public static class EXTENSION{ + public static final String IMAGE = "jpeg jpg png gif"; + public static final String VIDEO = "mp4 mov avi webm html5"; + public static final String DOCS = "doc docx txt ppt pptx xls pdf ai psd hwp"; + } } diff --git a/src/main/java/com/example/PLADIALMArchiving/global/exception/BaseResponseCode.java b/src/main/java/com/example/PLADIALMArchiving/global/exception/BaseResponseCode.java index aad5783..5802ba1 100644 --- a/src/main/java/com/example/PLADIALMArchiving/global/exception/BaseResponseCode.java +++ b/src/main/java/com/example/PLADIALMArchiving/global/exception/BaseResponseCode.java @@ -12,9 +12,9 @@ public enum BaseResponseCode { SUCCESS("S0001", HttpStatus.OK, "요청에 성공했습니다."), - BAD_REQUEST("G0001", HttpStatus.BAD_REQUEST, "잘못된 요청입니다."), NO_ATUTHENTIFICATION("G0002", HttpStatus.FORBIDDEN, "접근 권한이 없습니다."), + // User USER_NOT_FOUND("U0001", HttpStatus.NOT_FOUND, "사용자를 찾을 수 없습니다."), @@ -27,22 +27,10 @@ public enum BaseResponseCode { NOT_ACCESS_HEADER("T0006", HttpStatus.INTERNAL_SERVER_ERROR, "헤더에 접근할 수 없습니다."), BLACKLIST_TOKEN("T0007", HttpStatus.FORBIDDEN, "로그아웃 혹은 회원 탈퇴된 토큰입니다."), - // Booking - DATE_OR_TIME_IS_NULL("B0001", HttpStatus.BAD_REQUEST, "날짜와 시간을 모두 입력해주세요."), - MEMO_SIZE_OVER("B0002", HttpStatus.BAD_REQUEST, "요청사항은 30자 이하로 작성해주세요."), - START_TIME_MUST_BE_IN_FRONT("B0003", HttpStatus.BAD_REQUEST, "시작시간보다 끝나는 시간이 더 앞에 있습니다."), - DATE_MUST_BE_THE_FUTURE("B0004", HttpStatus.BAD_REQUEST, "미래의 날짜를 선택해주세요."), - ALREADY_BOOKED_TIME("B0005", HttpStatus.CONFLICT, "이미 예약되어 있는 시간입니다."), - BOOKING_NOT_FOUND("B0006", HttpStatus.NOT_FOUND, "존재하지 않는 예약입니다."), - ALREADY_CANCELED_BOOKING("B0007", HttpStatus.CONFLICT, "이미 취소된 예약입니다."), - ALREADY_FINISHED_BOOKING("B0008", HttpStatus.CONFLICT, "이미 사용이 완료된 예약입니다."), - - // Office - OFFICE_NOT_FOUND("O0001", HttpStatus.NOT_FOUND, "존재하지 않는 회의실입니다."), - // Archiving ALREADY_REGISTERED_PROJECT("P0001", HttpStatus.BAD_REQUEST, "이미 등록된 프로젝트입니다."), PROJECT_NOT_FOUND("P0002", HttpStatus.NOT_FOUND, "존재하지 않는 프로젝트입니다."), + CATEGORY_NOT_FOUND("P0003", HttpStatus.NOT_FOUND, "존재하지 않는 카테고리입니다."), ; public final String code; From 766d63c0dff830df99000227fe8b81c867d46137 Mon Sep 17 00:00:00 2001 From: dangnak2 <80161984+dangnak2@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:30:07 +0900 Subject: [PATCH 2/3] =?UTF-8?q?[PDS-32]=20feat:=20=EC=95=84=EC=B9=B4?= =?UTF-8?q?=EC=9D=B4=EB=B9=99=20=EC=9E=90=EB=A3=8C=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=EC=96=B4=20API=20=EA=B8=B0=EB=8A=A5=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../archiving/repository/MaterialRepository.java | 6 +----- .../archiving/service/ArchivingService.java | 2 +- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java b/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java index ec931b3..2c8828e 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/repository/MaterialRepository.java @@ -11,9 +11,5 @@ @Repository public interface MaterialRepository extends JpaRepository { - -// @Query("SELECT mt FROM Material mt WHERE :extension LIKE CONCAT('%', mt.extension, '%') ") -// List findByProject(Project project, @Param("extension") String extension); - - Page findByProjectAndExtensionIn(Project project, List extensions, Pageable pageable); + Page findByProjectAndExtensionInAndNameContaining(Project project, List extensions, String cond, Pageable pageable); } diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java b/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java index 9df642e..feec7a1 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/service/ArchivingService.java @@ -60,7 +60,7 @@ public Page searchMaterial(Long projectId, SearchMaterialReq } else if (category == Category.DOCS) { extension = List.of(Constants.EXTENSION.DOCS.split(" ")); } - filteredMaterials = materialRepository.findByProjectAndExtensionIn(project, extension, pageable); + filteredMaterials = materialRepository.findByProjectAndExtensionInAndNameContaining(project, extension, searchMaterialReq.getCond(), pageable); } else { filteredMaterials = materialRepository.findAll(pageable); } From 18d2d1068e21ccede64370e956c506e2e1a19f8b Mon Sep 17 00:00:00 2001 From: dangnak2 <80161984+dangnak2@users.noreply.github.com> Date: Sun, 15 Oct 2023 03:36:46 +0900 Subject: [PATCH 3/3] =?UTF-8?q?[PDS-32]=20feat:=20=EC=95=84=EC=B9=B4?= =?UTF-8?q?=EC=9D=B4=EB=B9=99=20=EC=9E=90=EB=A3=8C=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?http=20=EB=A9=94=EC=84=9C=EB=93=9C=20post=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../archiving/controller/ArchivingController.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java b/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java index 19e67b6..39a00f0 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java @@ -3,12 +3,14 @@ import com.example.PLADIALMArchiving.archiving.dto.request.RegisterProjectReq; import com.example.PLADIALMArchiving.archiving.dto.request.SearchMaterialReq; import com.example.PLADIALMArchiving.archiving.dto.request.UploadMaterialReq; +import com.example.PLADIALMArchiving.archiving.dto.response.SearchMaterialRes; import com.example.PLADIALMArchiving.archiving.service.ArchivingService; import com.example.PLADIALMArchiving.global.resolver.Account; import com.example.PLADIALMArchiving.global.response.ResponseCustom; import com.example.PLADIALMArchiving.user.entity.User; import io.swagger.annotations.Api; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.web.bind.annotation.*; @@ -46,8 +48,8 @@ public ResponseCustom uploadMaterial( /** * 자료목록을 조회 및 검색한다. */ - @GetMapping("/projects/{projectId}") - public ResponseCustom searchMaterial( + @PostMapping("/projects/{projectId}") + public ResponseCustom> searchMaterial( @PathVariable Long projectId, @RequestBody SearchMaterialReq searchMaterialReq, Pageable pageable