From dcfa3f993c9e7a103085254b3dc2b66ab80947a8 Mon Sep 17 00:00:00 2001 From: junpakPark Date: Tue, 1 Aug 2023 15:26:46 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20topicId=20=EB=B0=B0=EC=97=B4=EB=A1=9C?= =?UTF-8?q?=20get=20=EC=9A=94=EC=B2=AD=20=EC=8B=9C,=20=ED=95=B4=EB=8B=B9?= =?UTF-8?q?=20=ED=86=A0=ED=94=BD=EB=93=A4=20=EC=83=81=EC=84=B8=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapbefine/mapbefine/controller/TopicController.java | 8 ++++++++ .../mapbefine/mapbefine/repository/TopicRepository.java | 3 +++ .../mapbefine/mapbefine/service/TopicQueryService.java | 7 ++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/backend/src/main/java/com/mapbefine/mapbefine/controller/TopicController.java b/backend/src/main/java/com/mapbefine/mapbefine/controller/TopicController.java index c28d5bce0..5e640f61b 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/controller/TopicController.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/controller/TopicController.java @@ -18,6 +18,7 @@ import org.springframework.web.bind.annotation.PutMapping; import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.RestController; @RestController @@ -69,6 +70,13 @@ public ResponseEntity> findAll() { return ResponseEntity.ok(topics); } + @GetMapping("/ids") + public ResponseEntity> findByIds(@RequestParam List ids) { + List responses = topicQueryService.findAllByIds(ids); + + return ResponseEntity.ok(responses); + } + @GetMapping("/{id}") public ResponseEntity findById(@PathVariable Long id) { TopicDetailResponse response = topicQueryService.findById(id); diff --git a/backend/src/main/java/com/mapbefine/mapbefine/repository/TopicRepository.java b/backend/src/main/java/com/mapbefine/mapbefine/repository/TopicRepository.java index da74629f0..4709328d5 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/repository/TopicRepository.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/repository/TopicRepository.java @@ -1,6 +1,7 @@ package com.mapbefine.mapbefine.repository; import com.mapbefine.mapbefine.entity.Topic; +import java.util.List; import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.Modifying; import org.springframework.data.jpa.repository.Query; @@ -10,6 +11,8 @@ @Repository public interface TopicRepository extends JpaRepository { + List findByIdIn(List ids); + @Modifying(clearAutomatically = true) @Query("update Topic t set t.isDeleted = true where t.id = :topicId") void deleteById(@Param("topicId") Long topicId); diff --git a/backend/src/main/java/com/mapbefine/mapbefine/service/TopicQueryService.java b/backend/src/main/java/com/mapbefine/mapbefine/service/TopicQueryService.java index d1723e023..3a08ccd27 100644 --- a/backend/src/main/java/com/mapbefine/mapbefine/service/TopicQueryService.java +++ b/backend/src/main/java/com/mapbefine/mapbefine/service/TopicQueryService.java @@ -38,6 +38,12 @@ public List findAll() { .collect(Collectors.toList()); } + public List findAllByIds(List ids) { + return topicRepository.findByIdIn(ids).stream() + .map(TopicDetailResponse::from) + .collect(Collectors.toList()); + } + public TopicDetailResponse findById(Long id) { Topic topic = topicRepository.findById(id) .orElseThrow(() -> new IllegalArgumentException("해당하는 Topic이 존재하지 않습니다.")); @@ -74,5 +80,4 @@ private List sortTopicsByCounts(Map topicCounts) { .map(TopicResponse::from) .collect(Collectors.toList()); } - }