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..39a00f0 100644 --- a/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java +++ b/src/main/java/com/example/PLADIALMArchiving/archiving/controller/ArchivingController.java @@ -1,13 +1,17 @@ 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.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.*; @Api(tags = "아카이빙 API") @@ -40,10 +44,19 @@ public ResponseCustom uploadMaterial( archivingService.uploadMaterial(uploadMaterialReq, projectId, user); return ResponseCustom.OK(); } + /** * 자료목록을 조회 및 검색한다. */ - + @PostMapping("/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..2c8828e 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,15 @@ 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 { + 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 c2b93dd..feec7a1 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.findByProjectAndExtensionInAndNameContaining(project, extension, searchMaterialReq.getCond(), 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;