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
REST controller for managing articles.
  • Constructor Details

    • ArticlesController

      public ArticlesController()
  • Method Details

    • allArticles

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/all") public Iterable<Articles> allArticles()
      List all articles.
      Returns:
      iterable of all 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 retrieve
      Returns:
      the requested article
    • postArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public Articles postArticle(@RequestParam String title, @RequestParam String url, @RequestParam String explanation, @RequestParam String email, @RequestParam @DateTimeFormat(iso=DATE_TIME) LocalDateTime dateAdded)
      Create a new article.
      Parameters:
      title - title of the article
      url - URL of the article
      explanation - explanation of the article
      email - email of the article creator
      dateAdded - date the article was added
      Returns:
      the newly created article
    • updateArticle

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PutMapping("") public Articles updateArticle(@RequestParam Long id, @RequestBody @Valid @Valid Articles incoming)
      Update an existing article.
      Parameters:
      id - ID of the article to update
      incoming - article data to update with
      Returns:
      the updated 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:
      confirmation message