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

    • allUCSBDates

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/all") public Iterable<Articles> allUCSBDates()
      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 article
    • postUCSBDate

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public Articles postUCSBDate(@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 - title of article
      url - url of artucle
      explanation - brief explanation of the article
      email - email of author
      dateAdded - date of the article added
      Returns:
      the saved article
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • deleteUCSBDate

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @DeleteMapping("") public Object deleteUCSBDate(@RequestParam Long id)
      Delete a article
      Parameters:
      id - the id of the article to delete
      Returns:
      a message indicating the article was deleted
    • updateUCSBDate

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