From aacbf7214848d6f9354b2f86368b6a7212fdd861 Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Sun, 4 Aug 2024 16:04:25 +0900 Subject: [PATCH 1/6] =?UTF-8?q?[feat]=20:=20meetings=20delete=20=EB=B6=80?= =?UTF-8?q?=EB=B6=84=20s3=EB=B6=80=EB=B6=84=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../meetings/service/MeetingsServiceImpl.java | 7 +++++++ .../global/file/dto/FileDeleteDTO.java | 14 ++++++++++++++ .../global/file/dto/FileUpdateDTO.java | 1 - .../global/file/service/FileService.java | 4 +++- .../global/file/service/FileServiceImpl.java | 13 ++++++++++++- 5 files changed, 36 insertions(+), 3 deletions(-) create mode 100644 src/main/java/com/example/bigbrotherbe/global/file/dto/FileDeleteDTO.java 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 9433dd7..602d675 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 @@ -7,6 +7,7 @@ import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; +import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; @@ -91,6 +92,12 @@ public void deleteMeetings(Long meetingsId) { Meetings meetings = meetingsRepository.findById(meetingsId) .orElseThrow(() -> new BusinessException(NO_EXIST_MEETINGS)); + FileDeleteDTO fileDeleteDTO = FileDeleteDTO.builder() + .fileType(FileType.MEETINGS.getType()) + .files(meetings.getFiles()) + .build(); + + fileService.deleteFile(fileDeleteDTO); meetingsRepository.delete(meetings); } } diff --git a/src/main/java/com/example/bigbrotherbe/global/file/dto/FileDeleteDTO.java b/src/main/java/com/example/bigbrotherbe/global/file/dto/FileDeleteDTO.java new file mode 100644 index 0000000..774449d --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/global/file/dto/FileDeleteDTO.java @@ -0,0 +1,14 @@ +package com.example.bigbrotherbe.global.file.dto; + +import com.example.bigbrotherbe.global.file.entity.File; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +public class FileDeleteDTO { + private List files; + private String fileType; +} diff --git a/src/main/java/com/example/bigbrotherbe/global/file/dto/FileUpdateDTO.java b/src/main/java/com/example/bigbrotherbe/global/file/dto/FileUpdateDTO.java index 1aa52e5..32f761b 100644 --- a/src/main/java/com/example/bigbrotherbe/global/file/dto/FileUpdateDTO.java +++ b/src/main/java/com/example/bigbrotherbe/global/file/dto/FileUpdateDTO.java @@ -3,7 +3,6 @@ import com.example.bigbrotherbe.global.file.entity.File; import lombok.Builder; import lombok.Getter; -import lombok.Setter; import org.springframework.web.multipart.MultipartFile; import java.util.List; diff --git a/src/main/java/com/example/bigbrotherbe/global/file/service/FileService.java b/src/main/java/com/example/bigbrotherbe/global/file/service/FileService.java index 2cd57da..2052be3 100644 --- a/src/main/java/com/example/bigbrotherbe/global/file/service/FileService.java +++ b/src/main/java/com/example/bigbrotherbe/global/file/service/FileService.java @@ -1,5 +1,6 @@ package com.example.bigbrotherbe.global.file.service; +import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; @@ -13,5 +14,6 @@ public interface FileService { List saveFile(FileSaveDTO fileSaveDTO); List updateFile(FileUpdateDTO fileUpdateDTO); -// void deleteFile(); + + void deleteFile(FileDeleteDTO deleteDTO); } diff --git a/src/main/java/com/example/bigbrotherbe/global/file/service/FileServiceImpl.java b/src/main/java/com/example/bigbrotherbe/global/file/service/FileServiceImpl.java index 7554938..5089007 100644 --- a/src/main/java/com/example/bigbrotherbe/global/file/service/FileServiceImpl.java +++ b/src/main/java/com/example/bigbrotherbe/global/file/service/FileServiceImpl.java @@ -1,5 +1,6 @@ package com.example.bigbrotherbe.global.file.service; +import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; import com.example.bigbrotherbe.global.file.dto.FileSaveDTO; import com.example.bigbrotherbe.global.file.dto.FileUpdateDTO; import com.example.bigbrotherbe.global.file.entity.File; @@ -60,11 +61,21 @@ public List updateFile(FileUpdateDTO fileUpdateDTO) { return updatedFiles; } + public void deleteFile(FileDeleteDTO deleteDTO) { + List files = deleteDTO.getFiles(); + String fileType = deleteDTO.getFileType(); + files.forEach(file -> { + String fileName = file.getUrl().split("/")[3]; + s3Util.deleteFile(fileType + "/" + fileName); + }); + } + @Override public boolean checkExistRequestFile(List multipartFiles) { - if(multipartFiles == null){ + if (multipartFiles == null) { return false; } + for (MultipartFile file : multipartFiles) { if (file.isEmpty()) { return false; From c1994dbdea2e2fbdcbf8a71fa132c624edfcc43a Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Sun, 4 Aug 2024 16:15:17 +0900 Subject: [PATCH 2/6] [refactor] : s3 exception --- .../global/exception/enums/ErrorCode.java | 6 +++- .../bigbrotherbe/global/file/util/S3Util.java | 28 +++++++++---------- 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/global/exception/enums/ErrorCode.java b/src/main/java/com/example/bigbrotherbe/global/exception/enums/ErrorCode.java index 146519d..e176700 100644 --- a/src/main/java/com/example/bigbrotherbe/global/exception/enums/ErrorCode.java +++ b/src/main/java/com/example/bigbrotherbe/global/exception/enums/ErrorCode.java @@ -25,7 +25,11 @@ public enum ErrorCode { NO_EXIST_FAQ(HttpStatus.NOT_FOUND, "FAQ-001", "존재하지 않는 FAQ 입니다."), // AFFILIATION - NO_EXIST_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-001", "존재하지 않는 학생회 입니다."); + NO_EXIST_AFFILIATION(HttpStatus.NOT_FOUND, "AFFILIATION-001", "존재하지 않는 학생회 입니다."), + + // FILE + FAIL_TO_UPLOAD(HttpStatus.INTERNAL_SERVER_ERROR, "FILE-001","파일 업로드에 실패하였습니다."), + FAIL_TO_DELETE(HttpStatus.INTERNAL_SERVER_ERROR, "FILE-002","파일 삭제에 실패하였습니다."); private final HttpStatus httpStatus; private final String errorCode; diff --git a/src/main/java/com/example/bigbrotherbe/global/file/util/S3Util.java b/src/main/java/com/example/bigbrotherbe/global/file/util/S3Util.java index d1d01e0..6fff72b 100644 --- a/src/main/java/com/example/bigbrotherbe/global/file/util/S3Util.java +++ b/src/main/java/com/example/bigbrotherbe/global/file/util/S3Util.java @@ -1,9 +1,12 @@ package com.example.bigbrotherbe.global.file.util; +import com.amazonaws.AmazonServiceException; import com.amazonaws.services.s3.AmazonS3Client; import com.amazonaws.services.s3.model.CannedAccessControlList; import com.amazonaws.services.s3.model.ObjectMetadata; import com.amazonaws.services.s3.model.PutObjectRequest; +import com.example.bigbrotherbe.global.exception.BusinessException; +import com.example.bigbrotherbe.global.exception.enums.ErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; @@ -13,6 +16,9 @@ import java.net.URL; import java.util.UUID; +import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.FAIL_TO_DELETE; +import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.FAIL_TO_UPLOAD; + @Component @RequiredArgsConstructor @@ -42,24 +48,18 @@ public String uploadFile(MultipartFile file, String fileType) { return fileUrl.toString(); } catch (IOException e) { e.printStackTrace(); - // 예외 처리: 실패한 경우 null을 반환하거나 적절한 방식으로 처리 - return null; + throw new BusinessException(FAIL_TO_UPLOAD); + } catch (AmazonServiceException e) { + throw new BusinessException(FAIL_TO_UPLOAD); } } - // public List uploadFiles(List files) { - // List fileUrls = new ArrayList<>(); - // for (MultipartFile file : files) { - // String fileUrl = uploadFile(file); - // if (fileUrl != null) { - // fileUrls.add(fileUrl); - // } - // } - // return fileUrls; - // } - public void deleteFile(String path) { - amazonS3Client.deleteObject(bucket, path); + try { + amazonS3Client.deleteObject(bucket, path); + } catch (AmazonServiceException e) { + throw new BusinessException(FAIL_TO_DELETE); + } } } From be3a78cff2b71d9fcc60097dd4a4551f0a090438 Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Sun, 4 Aug 2024 17:20:42 +0900 Subject: [PATCH 3/6] =?UTF-8?q?[feat]=20:=20meetings=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/MeetingsController.java | 11 +++++-- .../MeetingsRegisterRequest.java | 3 +- .../{ => request}/MeetingsUpdateRequest.java | 2 +- .../dto/response/MeetingsResponse.java | 31 +++++++++++++++++++ .../meetings/service/MeetingsService.java | 7 +++-- .../meetings/service/MeetingsServiceImpl.java | 19 ++++++++++-- 6 files changed, 63 insertions(+), 10 deletions(-) rename src/main/java/com/example/bigbrotherbe/domain/meetings/dto/{ => request}/MeetingsRegisterRequest.java (85%) rename src/main/java/com/example/bigbrotherbe/domain/meetings/dto/{ => request}/MeetingsUpdateRequest.java (76%) create mode 100644 src/main/java/com/example/bigbrotherbe/domain/meetings/dto/response/MeetingsResponse.java diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java index 5ab8bf2..e8824a2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java @@ -1,7 +1,8 @@ package com.example.bigbrotherbe.domain.meetings.controller; -import com.example.bigbrotherbe.domain.meetings.dto.MeetingsRegisterRequest; -import com.example.bigbrotherbe.domain.meetings.dto.MeetingsUpdateRequest; +import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; +import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; +import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; import com.example.bigbrotherbe.domain.meetings.service.MeetingsService; import lombok.RequiredArgsConstructor; @@ -38,4 +39,10 @@ public ResponseEntity deleteMeetings(@PathVariable("meetingsId") Long meet meetingsService.deleteMeetings(meetingsId); return ResponseEntity.ok().build(); } + + @GetMapping("/{meetingsId}") + public ResponseEntity getMeetingsById(@PathVariable("meetingsId") Long MeetingsId) { + MeetingsResponse meetingsResponse = meetingsService.getMeetingsById(MeetingsId); + return ResponseEntity.ok().body(meetingsResponse); + } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/MeetingsRegisterRequest.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/request/MeetingsRegisterRequest.java similarity index 85% rename from src/main/java/com/example/bigbrotherbe/domain/meetings/dto/MeetingsRegisterRequest.java rename to src/main/java/com/example/bigbrotherbe/domain/meetings/dto/request/MeetingsRegisterRequest.java index c055203..dcda16c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/MeetingsRegisterRequest.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/request/MeetingsRegisterRequest.java @@ -1,11 +1,10 @@ -package com.example.bigbrotherbe.domain.meetings.dto; +package com.example.bigbrotherbe.domain.meetings.dto.request; import com.example.bigbrotherbe.domain.meetings.entity.Meetings; import com.example.bigbrotherbe.global.file.entity.File; import lombok.Getter; import lombok.NoArgsConstructor; -import org.springframework.web.multipart.MultipartFile; import java.util.List; diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/MeetingsUpdateRequest.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/request/MeetingsUpdateRequest.java similarity index 76% rename from src/main/java/com/example/bigbrotherbe/domain/meetings/dto/MeetingsUpdateRequest.java rename to src/main/java/com/example/bigbrotherbe/domain/meetings/dto/request/MeetingsUpdateRequest.java index 87182be..56eff3c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/MeetingsUpdateRequest.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/request/MeetingsUpdateRequest.java @@ -1,4 +1,4 @@ -package com.example.bigbrotherbe.domain.meetings.dto; +package com.example.bigbrotherbe.domain.meetings.dto.request; import lombok.Getter; import lombok.NoArgsConstructor; diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/response/MeetingsResponse.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/response/MeetingsResponse.java new file mode 100644 index 0000000..3300853 --- /dev/null +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/dto/response/MeetingsResponse.java @@ -0,0 +1,31 @@ +package com.example.bigbrotherbe.domain.meetings.dto.response; + +import com.example.bigbrotherbe.domain.meetings.entity.Meetings; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; + +import java.util.List; + +@Getter +@Builder +@AllArgsConstructor +public class MeetingsResponse { + private Long meetingsId; + private String title; + private String content; + private boolean isPublic; + private Long affiliationId; + private List urlList; + + public static MeetingsResponse fromMeetingsResponse(Meetings meetings, List urlList) { + return MeetingsResponse.builder() + .meetingsId(meetings.getId()) + .title(meetings.getTitle()) + .content(meetings.getContent()) + .isPublic(meetings.isPublic()) + .affiliationId(meetings.getAffiliationId()) + .urlList(urlList) + .build(); + } +} diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java index bfc5362..61ab6a4 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java @@ -1,7 +1,8 @@ package com.example.bigbrotherbe.domain.meetings.service; -import com.example.bigbrotherbe.domain.meetings.dto.MeetingsRegisterRequest; -import com.example.bigbrotherbe.domain.meetings.dto.MeetingsUpdateRequest; +import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; +import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; +import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -12,4 +13,6 @@ public interface MeetingsService { void updateMeetings(Long meetingsId, MeetingsUpdateRequest meetingsUpdateRequest, List multipartFiles); void deleteMeetings(Long meetingsId); + + MeetingsResponse getMeetingsById(Long meetingsId); } 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 602d675..1e940a1 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 @@ -1,10 +1,10 @@ package com.example.bigbrotherbe.domain.meetings.service; -import com.example.bigbrotherbe.domain.meetings.dto.MeetingsRegisterRequest; -import com.example.bigbrotherbe.domain.meetings.dto.MeetingsUpdateRequest; +import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; +import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; +import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; import com.example.bigbrotherbe.domain.meetings.entity.Meetings; import com.example.bigbrotherbe.domain.meetings.repository.MeetingsRepository; -import com.example.bigbrotherbe.domain.member.entity.Member; import com.example.bigbrotherbe.domain.member.service.MemberService; import com.example.bigbrotherbe.global.exception.BusinessException; import com.example.bigbrotherbe.global.file.dto.FileDeleteDTO; @@ -20,6 +20,7 @@ import org.springframework.web.multipart.MultipartFile; import java.util.List; +import java.util.stream.Collectors; import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NO_EXIST_AFFILIATION; import static com.example.bigbrotherbe.global.exception.enums.ErrorCode.NO_EXIST_MEETINGS; @@ -100,4 +101,16 @@ public void deleteMeetings(Long meetingsId) { fileService.deleteFile(fileDeleteDTO); meetingsRepository.delete(meetings); } + + @Override + public MeetingsResponse getMeetingsById(Long meetingsId) { + Meetings meetings = meetingsRepository.findById(meetingsId) + .orElseThrow(() -> new BusinessException(NO_EXIST_MEETINGS)); + + List urlList = meetings.getFiles().stream() + .map(File::getUrl) + .toList(); + + return MeetingsResponse.fromMeetingsResponse(meetings, urlList); + } } From 32376bb812451976d111a51f887ad5781ccc323a Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Mon, 5 Aug 2024 01:24:56 +0900 Subject: [PATCH 4/6] =?UTF-8?q?[feat]=20:=20meetings=20=EC=A0=84=EC=B2=B4?= =?UTF-8?q?=20=EC=A1=B0=ED=9A=8C=20paging=EC=B2=98=EB=A6=AC(=EA=B2=80?= =?UTF-8?q?=EC=83=89=20=EC=95=84=EC=A7=81)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 3 +++ .../meetings/controller/MeetingsController.java | 15 +++++++++++++++ .../domain/meetings/entity/Meetings.java | 3 +++ .../meetings/repository/MeetingsRepository.java | 5 ++++- .../domain/meetings/service/MeetingsService.java | 5 +++++ .../meetings/service/MeetingsServiceImpl.java | 9 +++++++++ src/main/resources/application.yml | 12 ++++++------ 7 files changed, 45 insertions(+), 7 deletions(-) diff --git a/build.gradle b/build.gradle index e0d098a..1420399 100644 --- a/build.gradle +++ b/build.gradle @@ -58,6 +58,9 @@ dependencies { // S3 implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.1.RELEASE' + + // Pageable + implementation 'org.springframework.boot:spring-boot-starter-hateoas' } tasks.named('test') { diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java index e8824a2..4e407a0 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java @@ -1,11 +1,18 @@ package com.example.bigbrotherbe.domain.meetings.controller; +import com.amazonaws.Response; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; +import com.example.bigbrotherbe.domain.meetings.entity.Meetings; import com.example.bigbrotherbe.domain.meetings.service.MeetingsService; import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; + +import org.springframework.data.domain.Sort; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; @@ -45,4 +52,12 @@ public ResponseEntity getMeetingsById(@PathVariable("meetingsI MeetingsResponse meetingsResponse = meetingsService.getMeetingsById(MeetingsId); return ResponseEntity.ok().body(meetingsResponse); } + + @GetMapping() + public ResponseEntity> getMeetingsList(@RequestParam(name = "page", defaultValue = "0") int page, + @RequestParam(name = "size", defaultValue = "10") int size) { + Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "id")); + Page meetingsPage = meetingsService.getMeetings(pageable); + return ResponseEntity.ok().body(meetingsPage); + } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/entity/Meetings.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/entity/Meetings.java index 72a33da..f70f8db 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/entity/Meetings.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/entity/Meetings.java @@ -2,6 +2,8 @@ import com.example.bigbrotherbe.domain.BaseTimeEntity; import com.example.bigbrotherbe.global.file.entity.File; +import com.fasterxml.jackson.annotation.JsonBackReference; +import com.fasterxml.jackson.annotation.JsonIgnore; import jakarta.persistence.*; import lombok.*; @@ -32,6 +34,7 @@ public class Meetings extends BaseTimeEntity { @Column(name = "affiliation_id") private Long affiliationId; + @JsonIgnore @OneToMany(mappedBy = "meetings", cascade = CascadeType.ALL, orphanRemoval = true) private List files = new ArrayList<>(); diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java index 0cfb1e5..4f14507 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java @@ -1,7 +1,10 @@ package com.example.bigbrotherbe.domain.meetings.repository; import com.example.bigbrotherbe.domain.meetings.entity.Meetings; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.data.jpa.repository.JpaRepository; -public interface MeetingsRepository extends JpaRepository { +public interface MeetingsRepository extends JpaRepository { + Page findAll(Pageable pageable); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java index 61ab6a4..7a85aec 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java @@ -3,6 +3,9 @@ import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; +import com.example.bigbrotherbe.domain.meetings.entity.Meetings; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; import org.springframework.web.multipart.MultipartFile; import java.util.List; @@ -15,4 +18,6 @@ public interface MeetingsService { void deleteMeetings(Long meetingsId); MeetingsResponse getMeetingsById(Long meetingsId); + + Page getMeetings(Pageable pageable); } 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 1e940a1..21a9308 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 @@ -15,6 +15,8 @@ import com.example.bigbrotherbe.global.file.service.FileService; import com.example.bigbrotherbe.global.jwt.AuthUtil; 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 org.springframework.web.multipart.MultipartFile; @@ -103,6 +105,7 @@ public void deleteMeetings(Long meetingsId) { } @Override + @Transactional(readOnly = true) public MeetingsResponse getMeetingsById(Long meetingsId) { Meetings meetings = meetingsRepository.findById(meetingsId) .orElseThrow(() -> new BusinessException(NO_EXIST_MEETINGS)); @@ -113,4 +116,10 @@ public MeetingsResponse getMeetingsById(Long meetingsId) { return MeetingsResponse.fromMeetingsResponse(meetings, urlList); } + + @Override + @Transactional(readOnly = true) + public Page getMeetings(Pageable pageable) { + return meetingsRepository.findAll(pageable); + } } diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b833b4f..46c39bd 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -25,11 +25,11 @@ spring: # driver-class-name: com.mysql.cj.jdbc.Driver # 태태 로컬 데이터베이스 설정 -# datasource: -# url: jdbc:mysql://localhost:3306/bigbrother?serverTimezone=UTC -# driver-class-name: com.mysql.cj.jdbc.Driver -# username: root -# password: 1234 + datasource: + url: jdbc:mysql://localhost:3306/bigbrother + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 1234 mail: host: smtp.gmail.com @@ -82,4 +82,4 @@ cloud: region: static: ap-northeast-2 stack: - auto: false + auto: false \ No newline at end of file From b6fe33ce4e4a814730b94431ccf5062b7c9c07b4 Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Mon, 5 Aug 2024 02:35:08 +0900 Subject: [PATCH 5/6] =?UTF-8?q?[refactor]=20:=20meetings=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=ED=95=99=EC=83=9D=ED=9A=8C=20?= =?UTF-8?q?id=EB=A1=9C=20paging=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/meetings/controller/MeetingsController.java | 8 ++++---- .../domain/meetings/repository/MeetingsRepository.java | 2 +- .../domain/meetings/service/MeetingsService.java | 2 +- .../domain/meetings/service/MeetingsServiceImpl.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java index 4e407a0..c3d6df2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java @@ -1,6 +1,5 @@ package com.example.bigbrotherbe.domain.meetings.controller; -import com.amazonaws.Response; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsRegisterRequest; import com.example.bigbrotherbe.domain.meetings.dto.request.MeetingsUpdateRequest; import com.example.bigbrotherbe.domain.meetings.dto.response.MeetingsResponse; @@ -53,11 +52,12 @@ public ResponseEntity getMeetingsById(@PathVariable("meetingsI return ResponseEntity.ok().body(meetingsResponse); } - @GetMapping() - public ResponseEntity> getMeetingsList(@RequestParam(name = "page", defaultValue = "0") int page, + @GetMapping("all/{affiliationId}") + public ResponseEntity> getMeetingsList(@PathVariable("affiliationId") Long affiliationId, + @RequestParam(name = "page", defaultValue = "0") int page, @RequestParam(name = "size", defaultValue = "10") int size) { Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "id")); - Page meetingsPage = meetingsService.getMeetings(pageable); + Page meetingsPage = meetingsService.getMeetings(affiliationId, pageable); return ResponseEntity.ok().body(meetingsPage); } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java index 4f14507..c01f7a2 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java @@ -6,5 +6,5 @@ import org.springframework.data.jpa.repository.JpaRepository; public interface MeetingsRepository extends JpaRepository { - Page findAll(Pageable pageable); + Page findByAffiliationId(Long affiliationId, Pageable pageable); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java index 7a85aec..838e208 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java @@ -19,5 +19,5 @@ public interface MeetingsService { MeetingsResponse getMeetingsById(Long meetingsId); - Page getMeetings(Pageable pageable); + Page getMeetings(Long affiliationId, Pageable pageable); } 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 21a9308..3cbd369 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 @@ -119,7 +119,7 @@ public MeetingsResponse getMeetingsById(Long meetingsId) { @Override @Transactional(readOnly = true) - public Page getMeetings(Pageable pageable) { - return meetingsRepository.findAll(pageable); + public Page getMeetings(Long affiliationId, Pageable pageable) { + return meetingsRepository.findByAffiliationId(affiliationId, pageable); } } From be329616a20fded6a28ef61e8ca0b7a03cb819ac Mon Sep 17 00:00:00 2001 From: TaetaetaE01 Date: Mon, 5 Aug 2024 02:49:38 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[refactor]=20:=20meetings=20=EC=A0=84?= =?UTF-8?q?=EC=B2=B4=20=EC=A1=B0=ED=9A=8C=20=EC=A0=9C=EB=AA=A9=20=EA=B2=80?= =?UTF-8?q?=EC=83=89=EA=B8=B0=EB=8A=A5=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/meetings/controller/MeetingsController.java | 10 ++++++++-- .../domain/meetings/repository/MeetingsRepository.java | 2 ++ .../domain/meetings/service/MeetingsService.java | 2 ++ .../domain/meetings/service/MeetingsServiceImpl.java | 7 +++++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java index c3d6df2..fa9290a 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/controller/MeetingsController.java @@ -55,9 +55,15 @@ public ResponseEntity getMeetingsById(@PathVariable("meetingsI @GetMapping("all/{affiliationId}") public ResponseEntity> getMeetingsList(@PathVariable("affiliationId") Long affiliationId, @RequestParam(name = "page", defaultValue = "0") int page, - @RequestParam(name = "size", defaultValue = "10") int size) { + @RequestParam(name = "size", defaultValue = "10") int size, + @RequestParam(name = "search", required = false) String search) { + Page meetingsPage; Pageable pageable = PageRequest.of(page, size, Sort.by(Sort.Direction.DESC, "id")); - Page meetingsPage = meetingsService.getMeetings(affiliationId, pageable); + if (search != null && !search.isEmpty()) { + meetingsPage = meetingsService.searchMeetings(affiliationId, search, pageable); + } else { + meetingsPage = meetingsService.getMeetings(affiliationId, pageable); + } return ResponseEntity.ok().body(meetingsPage); } } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java index c01f7a2..dd0813c 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/repository/MeetingsRepository.java @@ -7,4 +7,6 @@ public interface MeetingsRepository extends JpaRepository { Page findByAffiliationId(Long affiliationId, Pageable pageable); + + Page findByAffiliationIdAndTitleContaining(Long affiliationId, String title, Pageable pageable); } diff --git a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java index 838e208..38e2c8b 100644 --- a/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java +++ b/src/main/java/com/example/bigbrotherbe/domain/meetings/service/MeetingsService.java @@ -20,4 +20,6 @@ public interface MeetingsService { MeetingsResponse getMeetingsById(Long meetingsId); Page getMeetings(Long affiliationId, Pageable pageable); + + Page searchMeetings(Long affiliationId, String title, Pageable pageable); } 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 3cbd369..a608106 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 @@ -122,4 +122,11 @@ public MeetingsResponse getMeetingsById(Long meetingsId) { public Page getMeetings(Long affiliationId, Pageable pageable) { return meetingsRepository.findByAffiliationId(affiliationId, pageable); } + + @Override + @Transactional(readOnly = true) + public Page searchMeetings(Long affiliationId, String title, Pageable pageable) { + return meetingsRepository.findByAffiliationIdAndTitleContaining(affiliationId, title, pageable); + } + }