Skip to content

Commit

Permalink
feat: topicId 배열로 get 요청 시, 해당 토픽들 상세 조회 API 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
junpakPark committed Aug 1, 2023
1 parent c88b86e commit dcfa3f9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -69,6 +70,13 @@ public ResponseEntity<List<TopicResponse>> findAll() {
return ResponseEntity.ok(topics);
}

@GetMapping("/ids")
public ResponseEntity<List<TopicDetailResponse>> findByIds(@RequestParam List<Long> ids) {
List<TopicDetailResponse> responses = topicQueryService.findAllByIds(ids);

return ResponseEntity.ok(responses);
}

@GetMapping("/{id}")
public ResponseEntity<TopicDetailResponse> findById(@PathVariable Long id) {
TopicDetailResponse response = topicQueryService.findById(id);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -10,6 +11,8 @@
@Repository
public interface TopicRepository extends JpaRepository<Topic, Long> {

List<Topic> findByIdIn(List<Long> ids);

@Modifying(clearAutomatically = true)
@Query("update Topic t set t.isDeleted = true where t.id = :topicId")
void deleteById(@Param("topicId") Long topicId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ public List<TopicResponse> findAll() {
.collect(Collectors.toList());
}

public List<TopicDetailResponse> findAllByIds(List<Long> 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이 존재하지 않습니다."));
Expand Down Expand Up @@ -74,5 +80,4 @@ private List<TopicResponse> sortTopicsByCounts(Map<Topic, Long> topicCounts) {
.map(TopicResponse::from)
.collect(Collectors.toList());
}

}

0 comments on commit dcfa3f9

Please sign in to comment.