fix(drones): Change return type of [] ids to String

This commit is contained in:
js0ny 2025-11-21 18:45:13 +00:00
parent a3a5a80f74
commit 2016f35dcb
2 changed files with 10 additions and 10 deletions

View file

@ -47,7 +47,7 @@ public class DroneController {
* @return An array of drone id with cooling capability. * @return An array of drone id with cooling capability.
*/ */
@GetMapping("/dronesWithCooling/{state}") @GetMapping("/dronesWithCooling/{state}")
public int[] getDronesWithCoolingCapability(@PathVariable boolean state) { public String[] getDronesWithCoolingCapability(@PathVariable boolean state) {
return droneService.dronesWithCooling(state); return droneService.dronesWithCooling(state);
} }
@ -69,7 +69,7 @@ public class DroneController {
} }
@GetMapping("/queryAsPath/{attrName}/{attrVal}") @GetMapping("/queryAsPath/{attrName}/{attrVal}")
public int[] getIdByAttrMap( public String[] getIdByAttrMap(
@PathVariable String attrName, @PathVariable String attrName,
@PathVariable String attrVal) { @PathVariable String attrVal) {
return droneService.dronesWithAttribute(attrName, attrVal); return droneService.dronesWithAttribute(attrName, attrVal);

View file

@ -40,20 +40,20 @@ public class DroneInfoService {
* @return if {@code state} is true, return ids of drones with cooling * @return if {@code state} is true, return ids of drones with cooling
* capability, else without cooling * capability, else without cooling
*/ */
public int[] dronesWithCooling(boolean state) { public String[] dronesWithCooling(boolean state) {
URI droneUrl = URI.create(baseUrl).resolve(dronesEndpoint); URI droneUrl = URI.create(baseUrl).resolve(dronesEndpoint);
DroneDto[] drones = restTemplate.getForObject( DroneDto[] drones = restTemplate.getForObject(
droneUrl, droneUrl,
DroneDto[].class); DroneDto[].class);
if (drones == null) { if (drones == null) {
return new int[] {}; return new String[] {};
} }
return Arrays.stream(drones) return Arrays.stream(drones)
.filter(drone -> drone.capability().cooling() == state) .filter(drone -> drone.capability().cooling() == state)
.mapToInt(drone -> Integer.parseInt(drone.id())) .map(DroneDto::id)
.toArray(); .toArray(String[]::new);
} }
/** /**
@ -94,14 +94,14 @@ public class DroneInfoService {
* @param attrVal the attribute value to filter on * @param attrVal the attribute value to filter on
* @return array of drone ids matching the attribute name and value * @return array of drone ids matching the attribute name and value
*/ */
public int[] dronesWithAttribute(String attrName, String attrVal) { public String[] dronesWithAttribute(String attrName, String attrVal) {
URI droneUrl = URI.create(baseUrl).resolve(dronesEndpoint); URI droneUrl = URI.create(baseUrl).resolve(dronesEndpoint);
DroneDto[] drones = restTemplate.getForObject( DroneDto[] drones = restTemplate.getForObject(
droneUrl, droneUrl,
DroneDto[].class); DroneDto[].class);
if (drones == null) { if (drones == null) {
return new int[] {}; return new String[] {};
} }
// Use Jackson's ObjectMapper to convert DroneDto to JsonNode for dynamic // Use Jackson's ObjectMapper to convert DroneDto to JsonNode for dynamic
@ -118,8 +118,8 @@ public class DroneInfoService {
return false; return false;
} }
}) })
.mapToInt(drone -> Integer.parseInt(drone.id())) .map(DroneDto::id)
.toArray(); .toArray(String[]::new);
} }
private boolean isValueMatched(JsonNode node, String attrVal) { private boolean isValueMatched(JsonNode node, String attrVal) {