[ce6ad22] | 1 | package parkup.controllers;
|
---|
| 2 |
|
---|
| 3 | import org.springframework.beans.factory.annotation.Autowired;
|
---|
| 4 | import org.springframework.web.bind.annotation.*;
|
---|
| 5 | import parkup.entities.ParkingZone;
|
---|
| 6 | import parkup.services.ParkingZoneService;
|
---|
| 7 |
|
---|
| 8 | import java.util.List;
|
---|
| 9 |
|
---|
| 10 | @RestController
|
---|
| 11 | public class ParkingZoneController {
|
---|
| 12 | private final ParkingZoneService parkingZoneService;
|
---|
| 13 |
|
---|
| 14 | @Autowired
|
---|
| 15 | public ParkingZoneController(ParkingZoneService parkingZoneService) {
|
---|
| 16 | this.parkingZoneService = parkingZoneService;
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | @GetMapping({"/parkingZone"})
|
---|
| 20 | public List<ParkingZone> getAllParkingZone() {
|
---|
| 21 | return parkingZoneService.getAllParkingZones();
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | @GetMapping({"/parkingZone/{parkingZoneId}"})
|
---|
| 25 | public ParkingZone getParkingZone(@PathVariable int parkingZoneId) {
|
---|
| 26 | ParkingZone parkingZone = parkingZoneService.findById(parkingZoneId);
|
---|
| 27 | if (parkingZone != null) {
|
---|
| 28 | return parkingZone;
|
---|
| 29 | } else {
|
---|
| 30 | throw new RuntimeException("ParkingZone not found");
|
---|
| 31 | }
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | @PostMapping({"/parkingZone"})
|
---|
| 35 | public void addParkingZone(@RequestBody ParkingZone parkingZone) {
|
---|
| 36 | //System.out.println("???????");
|
---|
| 37 | parkingZoneService.addParkingZone(parkingZone);
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | @PutMapping({"/parkingZone/{parkingZoneId}"})
|
---|
| 41 | public void updateParkingZone(@PathVariable int parkingZoneId, @RequestBody ParkingZone parkingZone) {
|
---|
| 42 | parkingZoneService.updateParkingZone(parkingZoneId, parkingZone.getPzName(), parkingZone.getPrice(), parkingZone.getCapacity(), parkingZone.getWorkHours(),parkingZone.getLocation());
|
---|
| 43 | }
|
---|
| 44 |
|
---|
| 45 | @DeleteMapping({"/parkingZone/{parkingZoneId}"})
|
---|
| 46 | public void deleteParkingZone(@PathVariable int parkingZoneId) {
|
---|
| 47 | parkingZoneService.deleteParkingZone(parkingZoneId);
|
---|
| 48 | }
|
---|
| 49 | } |
---|