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 c28d5bce..5e640f61 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 da74629f..4709328d 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 d1723e02..3a08ccd2 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()); } - }