Class UCSBArticlesController

java.lang.Object
edu.ucsb.cs156.example.controllers.ApiController
edu.ucsb.cs156.example.controllers.UCSBArticlesController

@RequestMapping("/api/ucsbarticles") @RestController public class UCSBArticlesController extends ApiController
This is a REST controller for UCSBArticles
  • Constructor Details

    • UCSBArticlesController

      public UCSBArticlesController()
  • Method Details

    • allUCSBArticles

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("/all") public Iterable<UCSBArticles> allUCSBArticles()
      List all UCSB articles
      Returns:
      an iterable of UCSBArticles
    • postUCSBArticles

      @PreAuthorize("hasRole(\'ROLE_ADMIN\')") @PostMapping("/post") public UCSBArticles postUCSBArticles(@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 - a summary of the article
      email - an email address
      dateAdded - the date
      Returns:
      the saved ucsbarticle
      Throws:
      com.fasterxml.jackson.core.JsonProcessingException
    • getById

      @PreAuthorize("hasRole(\'ROLE_USER\')") @GetMapping("") public UCSBArticles getById(@RequestParam Long id)
      Get a single article by id
      Parameters:
      id - the id of the article
      Returns:
      a UCSBArticles
    • deleteUCSBArticles

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

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