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 Details

    • ArticlesController

      public ArticlesController()
  • Method Details

    • allArticles

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/all") public Iterable<Article> allArticles()
      List all articles
      Returns:
      an iterable of 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 title of the article
      url - the url of the article
      explanation - the explanation of the article
      email - the email associated with the article
      dateAdded - the date
      Returns:
      the saved article
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • deleteArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteArticle(@RequestParam Long id)
      Delete a Article
      Parameters:
      id - the id of the article to delete
      Returns:
      a message indicating the article was deleted
    • 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 update
      incoming - the new article
      Returns:
      the updated article object
    • getById

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Article getById(@RequestParam Long id)
      Get a single date by id
      Parameters:
      id - the id of the date
      Returns:
      a UCSBDate