Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] 토픽 다건 상세조회 API 구현 #142

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

p4; toList() 는 어떠신가용

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

다음 리팩터링때 다 같이 얘기해보죵!

}

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());
}

}
Loading