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
  • Constructor Details

    • ArticlesController

      public ArticlesController()
  • Method Details

    • allArticle

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/all") public Iterable<Article> allArticle()
    • 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
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • deleteArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteArticle(@RequestParam String id)
      Delete an Article
      Parameters:
      id - the id of the article to delete
      Returns:
      a message indicating the article was deleted
    • getById

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Article getById(@RequestParam String id)
      Get a single article by id
      Parameters:
      id - the id of the article
      Returns:
      an article
    • updateArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("") public Article updateArticle(@RequestParam String id, @RequestBody @Valid @Valid Article incoming)
      Update a single article
      Parameters:
      id - id of the article to update
      incoming - the new article
      Returns:
      the updated article object