Class ArticlesController
java.lang.Object
edu.ucsb.cs156.example.controllers.ApiController
edu.ucsb.cs156.example.controllers.ArticlesController
@RequestMapping("/api/articles")
@RestController
public class ArticlesController
extends ApiController
REST controller for managing articles.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionList all articles.deleteArticle
(Long id) Delete an article by ID.Get a single article by ID.postArticle
(String title, String url, String explanation, String email, LocalDateTime dateAdded) Create a new article.updateArticle
(Long id, @Valid Articles incoming) Update an existing article.Methods inherited from class edu.ucsb.cs156.example.controllers.ApiController
genericMessage, getCurrentUser, handleGenericException
-
Constructor Details
-
ArticlesController
public ArticlesController()
-
-
Method Details
-
allArticles
List all articles.- Returns:
- iterable of all articles
-
getById
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Articles getById(@RequestParam Long id) Get a single article by ID.- Parameters:
id
- ID of the article to retrieve- Returns:
- the requested article
-
postArticle
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public Articles postArticle(@RequestParam String title, @RequestParam String url, @RequestParam String explanation, @RequestParam String email, @RequestParam @DateTimeFormat(iso=DATE_TIME) LocalDateTime dateAdded) Create a new article.- Parameters:
title
- title of the articleurl
- URL of the articleexplanation
- explanation of the articleemail
- email of the article creatordateAdded
- date the article was added- Returns:
- the newly created article
-
updateArticle
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("") public Articles updateArticle(@RequestParam Long id, @RequestBody @Valid @Valid Articles incoming) Update an existing article.- Parameters:
id
- ID of the article to updateincoming
- article data to update with- Returns:
- the updated article
-
deleteArticle
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteArticle(@RequestParam Long id) Delete an article by ID.- Parameters:
id
- ID of the article to delete- Returns:
- confirmation message
-