63 lines
2.0 KiB
Java
63 lines
2.0 KiB
Java
package id.luxic.mai_queue.controller;
|
|
|
|
import id.luxic.mai_queue.model.Location;
|
|
import id.luxic.mai_queue.request.location.NewLocationRequest;
|
|
import id.luxic.mai_queue.response.ResponseMessage;
|
|
import id.luxic.mai_queue.service.LocationService;
|
|
import jakarta.validation.Valid;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import org.springframework.http.HttpStatus;
|
|
import org.springframework.http.ResponseEntity;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
import java.util.List;
|
|
|
|
@RestController
|
|
@RequestMapping("/api/v1/location")
|
|
@Slf4j
|
|
public class LocationController {
|
|
|
|
private final LocationService locationService;
|
|
|
|
public LocationController(LocationService locationService) {
|
|
this.locationService = locationService;
|
|
}
|
|
|
|
@GetMapping("/getAll")
|
|
public ResponseEntity<ResponseMessage> getAllLocation() {
|
|
return ResponseMessage.of(HttpStatus.OK, locationService.getAllLocation());
|
|
}
|
|
|
|
@PostMapping("/save")
|
|
public ResponseEntity<Location> saveLocation(@Valid @RequestBody NewLocationRequest newLocationRequest) {
|
|
log.info("saveLocation: {}", newLocationRequest);
|
|
return ResponseEntity.ok(locationService.saveLocation(newLocationRequest));
|
|
}
|
|
|
|
|
|
@GetMapping("/get/{id}")
|
|
public ResponseEntity<ResponseMessage> getLocationById(@PathVariable String id) {
|
|
|
|
Location location = locationService.getLocationById(id);
|
|
if (location == null) {
|
|
return ResponseMessage.of(HttpStatus.NOT_FOUND, null, "Location with id " + id + " not found");
|
|
}
|
|
|
|
return ResponseMessage.of(HttpStatus.OK, location);
|
|
}
|
|
|
|
@DeleteMapping("/delete/{id}")
|
|
public ResponseEntity<Void> deleteLocation(@PathVariable String id) {
|
|
locationService.deleteLocation(id);
|
|
return ResponseEntity.ok().build();
|
|
}
|
|
|
|
@GetMapping("/nextQueue/{locationId}")
|
|
public ResponseEntity<ResponseMessage> nextQueue(@PathVariable String locationId) {
|
|
|
|
locationService.nextQueue(locationId);
|
|
return ResponseMessage.of(HttpStatus.OK, null, "Next Queue");
|
|
}
|
|
|
|
}
|