PlantManagementController.java 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package com.example.plantsforyou.plant;
  2. import org.springframework.beans.factory.annotation.Autowired;
  3. import org.springframework.http.HttpStatus;
  4. import org.springframework.http.ResponseEntity;
  5. import org.springframework.web.bind.annotation.*;
  6. import java.util.List;
  7. @RestController
  8. @RequestMapping(path = "management/api/v1/plants")
  9. public class PlantManagementController {
  10. private final PlantService plantService;
  11. @Autowired
  12. public PlantManagementController(PlantService plantService) {
  13. this.plantService = plantService;
  14. }
  15. @GetMapping
  16. public List<Plant> getAllPlants(){
  17. return plantService.getAllPlants();
  18. }
  19. @PostMapping
  20. public ResponseEntity addNewPlant(@RequestBody Plant plant){
  21. plantService.addPlant(plant);
  22. return new ResponseEntity(HttpStatus.OK);
  23. }
  24. @DeleteMapping(path = "{plantID}")
  25. public ResponseEntity deletePlant(@PathVariable("plantID") Long plantID){
  26. plantService.delete(plantID);
  27. return new ResponseEntity(HttpStatus.OK);
  28. }
  29. @PutMapping(path = "{plantID}/inStock")
  30. public void updatePlantInStock(@PathVariable("plantID") Long plantID, @RequestParam() boolean inStock){
  31. plantService.updateInStock(plantID, inStock);
  32. }
  33. @PutMapping(path = "{plantID}/price")
  34. public void updatePlantPrice(@PathVariable("plantID") Long plantID, @RequestParam() Double price){
  35. plantService.updatePrice(plantID, price);
  36. }
  37. }