From a4aadd6ac0562c108a6dbcfc4314c51263be3f9a Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 16 Apr 2024 02:00:49 +0900 Subject: [PATCH 1/3] =?UTF-8?q?feat=20:=20=EB=AA=A8=EB=93=A0=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=EA=B8=80=EC=97=90=EC=84=9C=20=EA=B2=80=EC=83=89?= =?UTF-8?q?=ED=95=A0=20=EC=88=98=20=EC=9E=88=EB=8A=94=20=EC=84=9C=EB=B9=84?= =?UTF-8?q?=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/service/post/PostSearchService.java | 75 +++++++++++++++++++ 1 file changed, 75 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/post/service/post/PostSearchService.java diff --git a/src/main/java/com/dku/council/domain/post/service/post/PostSearchService.java b/src/main/java/com/dku/council/domain/post/service/post/PostSearchService.java new file mode 100644 index 00000000..bd6f46ad --- /dev/null +++ b/src/main/java/com/dku/council/domain/post/service/post/PostSearchService.java @@ -0,0 +1,75 @@ +package com.dku.council.domain.post.service.post; + +import com.dku.council.domain.post.model.dto.response.ResponseSingleSearchPost; +import com.dku.council.domain.post.model.entity.posttype.*; +import com.dku.council.domain.post.repository.post.*; +import com.dku.council.domain.post.repository.spec.PostSpec; +import lombok.RequiredArgsConstructor; +import lombok.extern.slf4j.Slf4j; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.stereotype.Service; + +import java.util.List; +import java.util.stream.Collectors; + +@Service +@RequiredArgsConstructor +@Slf4j +public class PostSearchService { + + private final PetitionRepository petitionRepository; + private final NoticeRepository noticeRepository; + private final CoalitionRepository coalitionRepository; + private final ConferenceRepository conferenceRepository; + private final RuleRepository ruleRepository; + + /** + * 모든 게시글 검색 + */ + public SummarizedPostSearchDto searchPost(String keyword, Pageable pageable) { + Page notices = getNoticeLists(keyword, pageable); + Page coalitions = getCoalitionLists(keyword, pageable); + Page petitions = getPetitionLists(keyword, pageable); + Page conferences = getConferencesLists(keyword, pageable); + Page rules = getRulesLists(keyword, pageable); + return new SummarizedPostSearchDto( + notices.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()), + coalitions.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()), + petitions.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()), + conferences.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()), + rules.stream().map(ResponseSingleSearchPost::new).collect(Collectors.toList()) + ); + } + + private Page getNoticeLists(String keyword, Pageable pageable) { + Specification spec = PostSpec.withTitleOrBody(keyword); + spec = spec.and(PostSpec.withActive()); + return noticeRepository.findAll(spec, pageable); + } + + private Page getCoalitionLists(String keyword, Pageable pageable) { + Specification spec = PostSpec.withTitleOrBody(keyword); + spec = spec.and(PostSpec.withActive()); + return coalitionRepository.findAll(spec,pageable); + } + + private Page getPetitionLists(String keyword, Pageable pageable) { + Specification spec = PostSpec.withTitleOrBody(keyword); + spec = spec.and(PostSpec.withActive()); + return petitionRepository.findAll(spec,pageable); + } + + private Page getConferencesLists(String keyword, Pageable pageable) { + Specification spec = PostSpec.withTitleOrBody(keyword); + spec = spec.and(PostSpec.withActive()); + return conferenceRepository.findAll(spec,pageable); + } + + private Page getRulesLists(String keyword, Pageable pageable) { + Specification spec = PostSpec.withTitleOrBody(keyword); + spec = spec.and(PostSpec.withActive()); + return ruleRepository.findAll(spec,pageable); + } +} From 2c489d07d4b47e70e94535be1bc94562570a76d4 Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 16 Apr 2024 02:01:26 +0900 Subject: [PATCH 2/3] =?UTF-8?q?feat=20:=20List=EB=A1=9C=20=EA=B2=8C?= =?UTF-8?q?=EC=8B=9C=ED=8C=90=EC=9D=84=20=EB=AC=B6=EA=B3=A0=20SingleSearch?= =?UTF-8?q?=20dto=EB=A1=9C=20=EA=B2=8C=EC=8B=9C=ED=8C=90=20=EC=A0=95?= =?UTF-8?q?=EB=B3=B4=EB=A5=BC=20=EB=82=98=ED=83=80=EB=82=B4=EA=B2=8C?= =?UTF-8?q?=EB=81=94=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../response/ResponseSingleSearchPost.java | 17 ++++++++++++++ .../service/post/SummarizedPostSearchDto.java | 23 +++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/post/model/dto/response/ResponseSingleSearchPost.java create mode 100644 src/main/java/com/dku/council/domain/post/service/post/SummarizedPostSearchDto.java diff --git a/src/main/java/com/dku/council/domain/post/model/dto/response/ResponseSingleSearchPost.java b/src/main/java/com/dku/council/domain/post/model/dto/response/ResponseSingleSearchPost.java new file mode 100644 index 00000000..3e829f27 --- /dev/null +++ b/src/main/java/com/dku/council/domain/post/model/dto/response/ResponseSingleSearchPost.java @@ -0,0 +1,17 @@ +package com.dku.council.domain.post.model.dto.response; + +import com.dku.council.domain.post.model.entity.Post; +import lombok.Getter; + +@Getter +public class ResponseSingleSearchPost { + + private final Long id; + + private final String title; + + public ResponseSingleSearchPost(Post post) { + this.id = post.getId(); + this.title = post.getTitle(); + } +} diff --git a/src/main/java/com/dku/council/domain/post/service/post/SummarizedPostSearchDto.java b/src/main/java/com/dku/council/domain/post/service/post/SummarizedPostSearchDto.java new file mode 100644 index 00000000..9534256c --- /dev/null +++ b/src/main/java/com/dku/council/domain/post/service/post/SummarizedPostSearchDto.java @@ -0,0 +1,23 @@ +package com.dku.council.domain.post.service.post; + +import com.dku.council.domain.post.model.dto.response.ResponseSingleSearchPost; +import lombok.Getter; +import lombok.RequiredArgsConstructor; + +import java.util.List; + +@Getter +@RequiredArgsConstructor +public class SummarizedPostSearchDto { + + private final List notices; + + private final List coalitions; + + private final List petitions; + + private final List conferences; + + private final List rules; + +} From 9bb0d69c1771fdfe76d70dfe45811da988cb43bb Mon Sep 17 00:00:00 2001 From: ChaHyeonMin Date: Tue, 16 Apr 2024 02:01:39 +0900 Subject: [PATCH 3/3] =?UTF-8?q?feat=20:=20=EA=B2=80=EC=83=89=20=EA=B8=B0?= =?UTF-8?q?=EB=8A=A5=20Controller=20=EB=94=B0=EB=A1=9C=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../post/controller/PostSearchController.java | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/main/java/com/dku/council/domain/post/controller/PostSearchController.java diff --git a/src/main/java/com/dku/council/domain/post/controller/PostSearchController.java b/src/main/java/com/dku/council/domain/post/controller/PostSearchController.java new file mode 100644 index 00000000..058e9693 --- /dev/null +++ b/src/main/java/com/dku/council/domain/post/controller/PostSearchController.java @@ -0,0 +1,32 @@ +package com.dku.council.domain.post.controller; + +import com.dku.council.domain.post.service.post.PostSearchService; +import com.dku.council.domain.post.service.post.SummarizedPostSearchDto; +import io.swagger.v3.oas.annotations.tags.Tag; +import lombok.RequiredArgsConstructor; +import org.springdoc.api.annotations.ParameterObject; +import org.springframework.data.domain.Pageable; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@Tag(name = "게시글 검색", description = "게시글 검색 관련 api") +@RequestMapping("/post/search") +public class PostSearchController { + + private final PostSearchService postSearchService; + + /** + * 모든 게시글 검색 + * + * @param keyword 검색어 + **/ + @GetMapping + public SummarizedPostSearchDto searchPost(@RequestParam(required = false) String keyword, + @ParameterObject Pageable pageable) { + return postSearchService.searchPost(keyword, pageable); + } +}