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 ArticlesdeleteArticles
(Long id) Delete an ArticleGet a single article by idpostArticles
(String title, String url, String explanation, String email, LocalDateTime dateAdded) Create a new articleupdateArticles
(Long id, @Valid Articles incoming) Update a single articleMethods inherited from class edu.ucsb.cs156.example.controllers.ApiController
genericMessage, getCurrentUser, handleGenericException
-
Constructor Details
-
ArticlesController
public ArticlesController()
-
-
Method Details
-
allArticles
List all Articles- Returns:
- an iterable of Articles
-
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) throws com.fasterxml.jackson.core.JsonProcessingException Create a new article- Parameters:
title
- title of articleurl
- url to the articleexplanation
- description of articleemail
- email of submitterdateAdded
- the date the article was added- Returns:
- the saved article
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getById
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Articles getById(@RequestParam Long id) Get a single article by id- Parameters:
id
- the id of the articles- Returns:
- a Articles
-
deleteArticles
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteArticles(@RequestParam Long id) Delete an Article- Parameters:
id
- the id of the article to delete- Returns:
- a message indicating the article was deleted
-
updateArticles
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("") public Articles updateArticles(@RequestParam Long id, @RequestBody @Valid @Valid Articles incoming) Update a single article- Parameters:
id
- id of the article to updateincoming
- the new article- Returns:
- the updated article object
-