|
@@ -1,6 +1,5 @@
|
|
|
package eu.fibane.parkingtoll.api;
|
|
package eu.fibane.parkingtoll.api;
|
|
|
|
|
|
|
|
-import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
|
|
import eu.fibane.parkingtoll.core.PersistenceManager;
|
|
import eu.fibane.parkingtoll.core.PersistenceManager;
|
|
|
import eu.fibane.parkingtoll.model.CarSlot;
|
|
import eu.fibane.parkingtoll.model.CarSlot;
|
|
|
import eu.fibane.parkingtoll.model.ParkingLot;
|
|
import eu.fibane.parkingtoll.model.ParkingLot;
|
|
@@ -8,12 +7,8 @@ import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.http.ResponseEntity;
|
|
|
-import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestBody;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RequestParam;
|
|
|
|
|
-import org.springframework.web.bind.annotation.RestController;
|
|
|
|
|
|
|
+import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
-import javax.servlet.http.HttpServletRequest;
|
|
|
|
|
import javax.validation.Valid;
|
|
import javax.validation.Valid;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.net.URI;
|
|
import java.net.URI;
|
|
@@ -21,37 +16,43 @@ import java.util.Collection;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
|
|
@RestController
|
|
@RestController
|
|
|
-public class ParkingLotApiController implements ParkingLotApi {
|
|
|
|
|
|
|
+public class ParkingLotApiController {
|
|
|
|
|
|
|
|
private static final Logger log = LoggerFactory.getLogger(ParkingLotApiController.class);
|
|
private static final Logger log = LoggerFactory.getLogger(ParkingLotApiController.class);
|
|
|
|
|
|
|
|
- private final ObjectMapper objectMapper;
|
|
|
|
|
- private final HttpServletRequest request;
|
|
|
|
|
private PersistenceManager persistenceManager;
|
|
private PersistenceManager persistenceManager;
|
|
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
|
- public ParkingLotApiController(ObjectMapper objectMapper, HttpServletRequest request, PersistenceManager persistenceManager) {
|
|
|
|
|
- this.objectMapper = objectMapper;
|
|
|
|
|
- this.request = request;
|
|
|
|
|
|
|
+ public ParkingLotApiController(PersistenceManager persistenceManager) {
|
|
|
this.persistenceManager = persistenceManager;
|
|
this.persistenceManager = persistenceManager;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ResponseEntity<ParkingLot> addParkingLot(@Valid @RequestBody ParkingLot parkingLotItem) {
|
|
|
|
|
|
|
+ @PostMapping(value = "/parking_lot",
|
|
|
|
|
+ produces = { "application/json" },
|
|
|
|
|
+ consumes = { "application/json" })
|
|
|
|
|
+ public ResponseEntity<ParkingLot> createParkingLot(@Valid @RequestBody ParkingLot parkingLotItem) {
|
|
|
|
|
|
|
|
parkingLotItem = persistenceManager.addParkingLot(parkingLotItem);
|
|
parkingLotItem = persistenceManager.addParkingLot(parkingLotItem);
|
|
|
return ResponseEntity.created(URI.create("/parking_lot/" + parkingLotItem.getId())).body(parkingLotItem);
|
|
return ResponseEntity.created(URI.create("/parking_lot/" + parkingLotItem.getId())).body(parkingLotItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ResponseEntity<ParkingLot> parkingLotDeleteById(@PathVariable("parkingLotId") Long parkingLotId) {
|
|
|
|
|
|
|
+ @DeleteMapping(value = "/parking_lot/{parkingLotId}",
|
|
|
|
|
+ produces = { "application/json" },
|
|
|
|
|
+ consumes = { "application/json" })
|
|
|
|
|
+ public ResponseEntity<ParkingLot> deleteParkingLotById(@PathVariable("parkingLotId") Long parkingLotId) {
|
|
|
ParkingLot parkingLot = persistenceManager.deleteParkingLotById(parkingLotId);
|
|
ParkingLot parkingLot = persistenceManager.deleteParkingLotById(parkingLotId);
|
|
|
return ResponseEntity.ok(parkingLot);
|
|
return ResponseEntity.ok(parkingLot);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ResponseEntity<ParkingLot> parkingLotGetById(@PathVariable("parkingLotId") Long parkingLotId) {
|
|
|
|
|
|
|
+ @GetMapping(value = "/parking_lot/{parkingLotId}",
|
|
|
|
|
+ produces = { "application/json" })
|
|
|
|
|
+ public ResponseEntity<ParkingLot> getParkingById(@PathVariable("parkingLotId") Long parkingLotId) {
|
|
|
ParkingLot parkingLot = persistenceManager.getParkingLotById(parkingLotId);
|
|
ParkingLot parkingLot = persistenceManager.getParkingLotById(parkingLotId);
|
|
|
return ResponseEntity.ok(parkingLot);
|
|
return ResponseEntity.ok(parkingLot);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @DeleteMapping(value = "/parking_lot/{parkingLotId}/park",
|
|
|
|
|
+ produces = { "application/json" })
|
|
|
public ResponseEntity<CarSlot> leaveParkingLot(@PathVariable("parkingLotId") Long parkingLotId, @Valid @RequestBody CarSlot carSlotItem) {
|
|
public ResponseEntity<CarSlot> leaveParkingLot(@PathVariable("parkingLotId") Long parkingLotId, @Valid @RequestBody CarSlot carSlotItem) {
|
|
|
|
|
|
|
|
ParkingLot parkingLot = persistenceManager.getParkingLotById(parkingLotId);
|
|
ParkingLot parkingLot = persistenceManager.getParkingLotById(parkingLotId);
|
|
@@ -61,7 +62,10 @@ public class ParkingLotApiController implements ParkingLotApi {
|
|
|
return ResponseEntity.ok(oldCarSlot);
|
|
return ResponseEntity.ok(oldCarSlot);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- public ResponseEntity<CarSlot> parkParkingLot(@PathVariable("parkingLotId") Long parkingLotId, @Valid @RequestBody CarSlot carSlotItem) {
|
|
|
|
|
|
|
+ @PostMapping(value = "/parking_lot/{parkingLotId}/park",
|
|
|
|
|
+ produces = { "application/json" },
|
|
|
|
|
+ consumes = { "application/json" })
|
|
|
|
|
+ public ResponseEntity<CarSlot> parkAtParkingLot(@PathVariable("parkingLotId") Long parkingLotId, @Valid @RequestBody CarSlot carSlotItem) {
|
|
|
//check if the asked parking exists
|
|
//check if the asked parking exists
|
|
|
ParkingLot parkingLot = persistenceManager.getParkingLotById(parkingLotId);
|
|
ParkingLot parkingLot = persistenceManager.getParkingLotById(parkingLotId);
|
|
|
carSlotItem.setParkingLotId(parkingLotId);
|
|
carSlotItem.setParkingLotId(parkingLotId);
|
|
@@ -70,11 +74,14 @@ public class ParkingLotApiController implements ParkingLotApi {
|
|
|
return ResponseEntity.ok(carSlotItem);
|
|
return ResponseEntity.ok(carSlotItem);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @PutMapping(value = "/parking_lot/{parkingLotId}",
|
|
|
|
|
+ produces = { "application/json" },
|
|
|
|
|
+ consumes = { "application/json" })
|
|
|
public ResponseEntity<ParkingLot> updateParkingLot(@PathVariable("parkingLotId") Long parkingLotId, @Valid @RequestBody ParkingLot parkingLotItem) {
|
|
public ResponseEntity<ParkingLot> updateParkingLot(@PathVariable("parkingLotId") Long parkingLotId, @Valid @RequestBody ParkingLot parkingLotItem) {
|
|
|
Long oldID = parkingLotItem.getId();
|
|
Long oldID = parkingLotItem.getId();
|
|
|
parkingLotItem.setId(parkingLotId);
|
|
parkingLotItem.setId(parkingLotId);
|
|
|
- persistenceManager.updateParkingLot(parkingLotId, parkingLotItem);
|
|
|
|
|
- if(!parkingLotItem.getId().equals(oldID)){
|
|
|
|
|
|
|
+ boolean newItem = persistenceManager.updateParkingLot(parkingLotId, parkingLotItem);
|
|
|
|
|
+ if(newItem){
|
|
|
//it's a creation - 201
|
|
//it's a creation - 201
|
|
|
return ResponseEntity.created(URI.create("/parking_lot/" + parkingLotItem.getId())).build();
|
|
return ResponseEntity.created(URI.create("/parking_lot/" + parkingLotItem.getId())).build();
|
|
|
}
|
|
}
|
|
@@ -82,6 +89,8 @@ public class ParkingLotApiController implements ParkingLotApi {
|
|
|
return ResponseEntity.noContent().build();
|
|
return ResponseEntity.noContent().build();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ @GetMapping(value = "/parking_lot",
|
|
|
|
|
+ produces = { "application/json" })
|
|
|
public ResponseEntity<Collection<ParkingLot>> searchParkingLot(@Valid @RequestParam(value = "searchString", required = false) String searchString) {
|
|
public ResponseEntity<Collection<ParkingLot>> searchParkingLot(@Valid @RequestParam(value = "searchString", required = false) String searchString) {
|
|
|
Collection<ParkingLot> parkingLots = persistenceManager.getAllParkingLots();
|
|
Collection<ParkingLot> parkingLots = persistenceManager.getAllParkingLots();
|
|
|
if(searchString != null && !searchString.isBlank()) {
|
|
if(searchString != null && !searchString.isBlank()) {
|