feat(queryAsPath): implement basic logic UNTESTED

This commit is contained in:
js0ny 2025-11-21 18:43:09 +00:00
parent a6916ba5da
commit a3a5a80f74

View file

@ -6,6 +6,9 @@ import java.util.Arrays;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
@Service @Service
public class DroneInfoService { public class DroneInfoService {
@ -95,12 +98,43 @@ public class DroneInfoService {
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);
);
// TODO: Logic unimplemented if (drones == null) {
return new int[] {}; return new int[] {};
} }
public int[] dronesMatchesRequirements() // Use Jackson's ObjectMapper to convert DroneDto to JsonNode for dynamic
// querying
ObjectMapper mapper = new ObjectMapper();
return Arrays.stream(drones)
.filter(drone -> {
JsonNode node = mapper.valueToTree(drone);
JsonNode attrNode = node.findValue(attrName);
if (attrNode != null) {
return isValueMatched(attrNode, attrVal);
} else {
return false;
}
})
.mapToInt(drone -> Integer.parseInt(drone.id()))
.toArray();
}
private boolean isValueMatched(JsonNode node, String attrVal) {
if (node.isTextual()) {
return node.asText().equals(attrVal);
} else if (node.isNumber()) {
return Double.compare(node.asDouble(), Double.parseDouble(attrVal)) == 0;
} else if (node.isBoolean()) {
return node.asText().equals(attrVal);
} else {
return false;
}
}
public int[] dronesMatchesRequirements() {
return new int[] {};
};
} }