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 UCSBDates
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionList all ArticlesdeleteArticle
(Long id) Delete an ArticleGet a single article by idpostArticle
(String title, String url, String explanation, String email, LocalDateTime dateAdded) Create a new ArticleupdateArticle
(Long id, @Valid Article 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 Article
-
getById
@PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Article getById(@RequestParam Long id) Get a single article by id- Parameters:
id
- the id of the article- Returns:
- a Article
-
postArticle
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public Article postArticle(@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
- the article's titleurl
- the article's urlexplanation
- the article's explanationemail
- the author's emaildateAdded
- date article was added, no timezone information- Returns:
- the saved Article
- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
updateArticle
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("") public Article updateArticle(@RequestParam Long id, @RequestBody @Valid @Valid Article incoming) Update a single Article- Parameters:
id
- id of the Article to updateincoming
- the new Article- Returns:
- the updated Article object
-
deleteArticle
@PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteArticle(@RequestParam Long id) Delete an Article- Parameters:
id
- the id of the Article to delete- Returns:
- a message indicating the Article was deleted
-