feat(logging): Add logging for REST Controller
This commit is contained in:
parent
49646d97ed
commit
326c31c149
4 changed files with 37 additions and 3 deletions
|
|
@ -8,6 +8,8 @@ import io.github.js0ny.ilp_coursework.data.request.MovementRequest;
|
|||
import io.github.js0ny.ilp_coursework.data.request.RegionCheckRequest;
|
||||
import io.github.js0ny.ilp_coursework.service.GpsCalculationService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
|
|
@ -25,6 +27,8 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
@RequestMapping("/api/v1")
|
||||
public class ApiController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(ApiController.class);
|
||||
|
||||
private final GpsCalculationService gpsService;
|
||||
|
||||
/**
|
||||
|
|
@ -45,6 +49,7 @@ public class ApiController {
|
|||
*/
|
||||
@GetMapping("/uid")
|
||||
public String getUid() {
|
||||
log.info("GET /api/v1/uid");
|
||||
return "s2522255";
|
||||
}
|
||||
|
||||
|
|
@ -58,6 +63,7 @@ public class ApiController {
|
|||
public double getDistance(@RequestBody DistanceRequest request) {
|
||||
LngLat position1 = request.position1();
|
||||
LngLat position2 = request.position2();
|
||||
log.info("POST /api/v1/distanceTo position1={} position2={}", position1, position2);
|
||||
return gpsService.calculateDistance(position1, position2);
|
||||
}
|
||||
|
||||
|
|
@ -72,6 +78,7 @@ public class ApiController {
|
|||
public boolean getIsCloseTo(@RequestBody DistanceRequest request) {
|
||||
LngLat position1 = request.position1();
|
||||
LngLat position2 = request.position2();
|
||||
log.info("POST /api/v1/isCloseTo position1={} position2={}", position1, position2);
|
||||
return gpsService.isCloseTo(position1, position2);
|
||||
}
|
||||
|
||||
|
|
@ -86,6 +93,7 @@ public class ApiController {
|
|||
public LngLat getNextPosition(@RequestBody MovementRequest request) {
|
||||
LngLat start = request.start();
|
||||
Angle angle = new Angle(request.angle());
|
||||
log.info("POST /api/v1/nextPosition start={} angle={}", start, angle);
|
||||
return gpsService.nextPosition(start, angle);
|
||||
}
|
||||
|
||||
|
|
@ -99,6 +107,7 @@ public class ApiController {
|
|||
public boolean getIsInRegion(@RequestBody RegionCheckRequest request) {
|
||||
LngLat position = request.position();
|
||||
Region region = request.region();
|
||||
log.info("POST /api/v1/isInRegion position={} region={}", position, region);
|
||||
return gpsService.checkIsInRegion(position, region);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,6 +8,8 @@ import io.github.js0ny.ilp_coursework.service.DroneAttrComparatorService;
|
|||
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
||||
import io.github.js0ny.ilp_coursework.service.PathFinderService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
|
|
@ -23,6 +25,8 @@ import java.util.List;
|
|||
@RequestMapping("/api/v1")
|
||||
public class DroneController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(DroneController.class);
|
||||
|
||||
private final DroneInfoService droneInfoService;
|
||||
private final DroneAttrComparatorService droneAttrComparatorService;
|
||||
private final PathFinderService pathFinderService;
|
||||
|
|
@ -55,6 +59,7 @@ public class DroneController {
|
|||
*/
|
||||
@GetMapping("/dronesWithCooling/{state}")
|
||||
public List<String> getDronesWithCoolingCapability(@PathVariable boolean state) {
|
||||
log.info("GET /api/v1/dronesWithCooling/{}", state);
|
||||
return droneInfoService.dronesWithCooling(state);
|
||||
}
|
||||
|
||||
|
|
@ -68,9 +73,11 @@ public class DroneController {
|
|||
@GetMapping("/droneDetails/{id}")
|
||||
public ResponseEntity<Drone> getDroneDetail(@PathVariable String id) {
|
||||
try {
|
||||
log.info("GET /api/v1/droneDetails/{}", id);
|
||||
Drone drone = droneInfoService.droneDetail(id);
|
||||
return ResponseEntity.ok(drone);
|
||||
} catch (IllegalArgumentException ex) {
|
||||
log.warn("GET /api/v1/droneDetails/{} not found", id);
|
||||
return ResponseEntity.notFound().build();
|
||||
}
|
||||
}
|
||||
|
|
@ -86,26 +93,35 @@ public class DroneController {
|
|||
@GetMapping("/queryAsPath/{attrName}/{attrVal}")
|
||||
public List<String> getIdByAttrMap(
|
||||
@PathVariable String attrName, @PathVariable String attrVal) {
|
||||
log.info("GET /api/v1/queryAsPath/{}/{}", attrName, attrVal);
|
||||
return droneAttrComparatorService.dronesWithAttribute(attrName, attrVal);
|
||||
}
|
||||
|
||||
@PostMapping("/query")
|
||||
public List<String> getIdByAttrMapPost(@RequestBody AttrQueryRequest[] attrComparators) {
|
||||
int count = attrComparators == null ? 0 : attrComparators.length;
|
||||
log.info("POST /api/v1/query comparators={}", count);
|
||||
return droneAttrComparatorService.dronesSatisfyingAttributes(attrComparators);
|
||||
}
|
||||
|
||||
@PostMapping("/queryAvailableDrones")
|
||||
public List<String> queryAvailableDrones(@RequestBody MedDispatchRecRequest[] records) {
|
||||
int count = records == null ? 0 : records.length;
|
||||
log.info("POST /api/v1/queryAvailableDrones records={}", count);
|
||||
return droneInfoService.dronesMatchesRequirements(records);
|
||||
}
|
||||
|
||||
@PostMapping("/calcDeliveryPath")
|
||||
public DeliveryPathResponse calculateDeliveryPath(@RequestBody MedDispatchRecRequest[] record) {
|
||||
int count = record == null ? 0 : record.length;
|
||||
log.info("POST /api/v1/calcDeliveryPath records={}", count);
|
||||
return pathFinderService.calculateDeliveryPath(record);
|
||||
}
|
||||
|
||||
@PostMapping("/calcDeliveryPathAsGeoJson")
|
||||
public String calculateDeliveryPathAsGeoJson(@RequestBody MedDispatchRecRequest[] record) {
|
||||
int count = record == null ? 0 : record.length;
|
||||
log.info("POST /api/v1/calcDeliveryPathAsGeoJson records={}", count);
|
||||
return pathFinderService.calculateDeliveryPathAsGeoJson(record);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ import io.github.js0ny.ilp_coursework.data.external.RestrictedArea;
|
|||
import io.github.js0ny.ilp_coursework.data.external.ServicePoint;
|
||||
import io.github.js0ny.ilp_coursework.service.DroneInfoService;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
|
@ -14,6 +16,8 @@ import java.util.List;
|
|||
@RequestMapping("/api/v1")
|
||||
public class MapMetaController {
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MapMetaController.class);
|
||||
|
||||
private final DroneInfoService droneInfoService;
|
||||
|
||||
public MapMetaController(DroneInfoService droneInfoService) {
|
||||
|
|
@ -22,11 +26,13 @@ public class MapMetaController {
|
|||
|
||||
@GetMapping("/restrictedAreas")
|
||||
public List<RestrictedArea> getRestrictedAreas() {
|
||||
log.info("GET /api/v1/restrictedAreas");
|
||||
return droneInfoService.fetchRestrictedAreas();
|
||||
}
|
||||
|
||||
@GetMapping("/servicePoints")
|
||||
public List<ServicePoint> getServicePoints() {
|
||||
log.info("GET /api/v1/servicePoints");
|
||||
return droneInfoService.fetchServicePoints();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import io.github.js0ny.ilp_coursework.data.common.DroneEvent;
|
||||
import io.github.js0ny.ilp_coursework.data.response.DeliveryPathResponse;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
|
|
@ -15,6 +17,8 @@ import java.util.concurrent.CompletableFuture;
|
|||
|
||||
@Service
|
||||
public class TelemetryService {
|
||||
private static final Logger log = LoggerFactory.getLogger(TelemetryService.class);
|
||||
|
||||
private final HttpClient client;
|
||||
private final ObjectMapper mapper;
|
||||
|
||||
|
|
@ -56,7 +60,7 @@ public class TelemetryService {
|
|||
() -> {
|
||||
try {
|
||||
String json = mapper.writeValueAsString(event);
|
||||
System.out.println("[INFO] Sending telemetry event: " + json);
|
||||
log.debug("Sending telemetry event: {}", json);
|
||||
var request =
|
||||
java.net.http.HttpRequest.newBuilder()
|
||||
.uri(java.net.URI.create(BLACKBOX_URL + "/ingest"))
|
||||
|
|
@ -68,8 +72,7 @@ public class TelemetryService {
|
|||
|
||||
client.send(request, java.net.http.HttpResponse.BodyHandlers.ofString());
|
||||
} catch (Exception e) {
|
||||
System.err.println(
|
||||
"[ERROR] Failed to send telemetry event: " + e.getMessage());
|
||||
log.error("Failed to send telemetry event: {}", e.getMessage());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue