diff --git a/backend/src/main/java/wooteco/prolog/roadmap/ui/RecommendedController.java b/backend/src/main/java/wooteco/prolog/roadmap/ui/RecommendedController.java new file mode 100644 index 000000000..6838624d3 --- /dev/null +++ b/backend/src/main/java/wooteco/prolog/roadmap/ui/RecommendedController.java @@ -0,0 +1,43 @@ +package wooteco.prolog.roadmap.ui; + +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; +import wooteco.prolog.roadmap.application.RecommendedService; +import wooteco.prolog.roadmap.application.dto.RecommendedRequest; +import wooteco.prolog.roadmap.application.dto.RecommendedUpdateRequest; + +import java.net.URI; + +@RestController +@RequestMapping("/keywords/{keywordId}/recommended-posts") +public class RecommendedController { + + private final RecommendedService recommendedService; + + public RecommendedController(final RecommendedService recommendedService) { + this.recommendedService = recommendedService; + } + + @PostMapping + public ResponseEntity createRecommendedPost(@PathVariable("keywordId") Long keywordId, + @RequestBody RecommendedRequest request) { + final Long id = recommendedService.create(keywordId, request); + return ResponseEntity.created( + URI.create("/keywords/" + keywordId + "/recommended-posts/" + id)).build(); + } + + @PutMapping("/{recommendedId}") + public ResponseEntity updateRecommendedPost(@PathVariable("keywordId") Long keywordId, + @PathVariable("recommendedId") Long recommendedId, + @RequestBody RecommendedUpdateRequest request) { + recommendedService.update(recommendedId, request); + return ResponseEntity.ok().build(); + } + + @DeleteMapping("/{recommendedId}") + public ResponseEntity deleteRecommendedPost(@PathVariable("keywordId") Long keywordId, + @PathVariable("recommendedId") Long recommendedId) { + recommendedService.delete(recommendedId); + return ResponseEntity.noContent().build(); + } +}