Skip to content

Commit

Permalink
feat: 어드민용 키워드별 추천 포스트 기능 컨트롤러 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
nuyh99 committed Jul 20, 2023
1 parent 4515f33 commit 685a972
Showing 1 changed file with 43 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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<Void> 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<Void> updateRecommendedPost(@PathVariable("keywordId") Long keywordId,
@PathVariable("recommendedId") Long recommendedId,
@RequestBody RecommendedUpdateRequest request) {
recommendedService.update(recommendedId, request);
return ResponseEntity.ok().build();
}

@DeleteMapping("/{recommendedId}")
public ResponseEntity<Void> deleteRecommendedPost(@PathVariable("keywordId") Long keywordId,
@PathVariable("recommendedId") Long recommendedId) {
recommendedService.delete(recommendedId);
return ResponseEntity.noContent().build();
}
}

0 comments on commit 685a972

Please sign in to comment.