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<Articles> allArticles()
      List all articles.
      Returns:
      an iterable of articles
    • getById

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public Articles getById(@RequestParam Long id)
      Get a single article by id.
      Parameters:
      id - id of the article to get
      Returns:
      the requested article
    • 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.
      Parameters:
      title - article title
      url - article URL
      explanation - short explanation of the article
      email - submitter email
      dateAdded - the timestamp when the article was added
      Returns:
      the saved article
    • deleteArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteArticle(@RequestParam Long id)
      Delete an article by id.
      Parameters:
      id - 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 an existing article by id.
      Parameters:
      id - id of the article to update
      incoming - JSON body with updated article field values
      Returns:
      the updated article