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 - the id of the article
      Returns:
      a Articles
    • postArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public Articles 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 of the person who added the article
      dateAdded - the date added
      Returns:
      the saved article
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException