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
This is a REST controller for Articles.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList all articles.deleteArticles(Long id) Delete a single article.Get a single article by id.postArticles(String title, String url, String explanation, String email, LocalDateTime dateAdded) Create a new article.updateArticles(Long id, @Valid Articles incoming) Update a single article.Methods inherited from class ApiController
genericMessage, getCurrentUser, handleGenericException
-
Constructor Details
-
ArticlesController
public ArticlesController()
-
-
Method Details
-
allArticles
-
getById
@PreAuthorize("hasRole('ROLE_USER')") @GetMapping("") public Articles getById(@RequestParam Long id) Get a single article by id.- Parameters:
id- the id of the article- Returns:
- the article with the given id
- Throws:
EntityNotFoundException- if no article has the given id
-
postArticles
@PreAuthorize("hasRole('ROLE_ADMIN')") @PostMapping("/post") public Articles postArticles(@RequestParam String title, @RequestParam String url, @RequestParam String explanation, @RequestParam String email, @RequestParam("dateAdded") @DateTimeFormat(iso=DATE_TIME) LocalDateTime dateAdded) Create a new article. Accessible only to administrators.- Parameters:
title- the article titleurl- the URL of the articleexplanation- a description of the articleemail- the email of the person who submitted the articledateAdded- the date and time the article was added- Returns:
- the saved article
-
deleteArticles
@PreAuthorize("hasRole('ROLE_ADMIN')") @DeleteMapping("") public Object deleteArticles(@RequestParam Long id) Delete a single article. Accessible only to administrators.- Parameters:
id- the id of the article to delete- Returns:
- a message indicating the record was deleted
- Throws:
EntityNotFoundException- if no article has the given id
-
updateArticles
@PreAuthorize("hasRole('ROLE_ADMIN')") @PutMapping("") public Articles updateArticles(@RequestParam Long id, @RequestBody @Valid @Valid Articles incoming) Update a single article. Accessible only to administrators.- Parameters:
id- the id of the article to updateincoming- the new values for the article fields- Returns:
- the updated article
- Throws:
EntityNotFoundException- if no article has the given id
-