diff --git a/src/lib/backends/opentripplannerbackend.cpp b/src/lib/backends/opentripplannerbackend.cpp index da9bb86..7610cc3 100644 --- a/src/lib/backends/opentripplannerbackend.cpp +++ b/src/lib/backends/opentripplannerbackend.cpp @@ -1,113 +1,115 @@ /* Copyright (C) 2020 Volker Krause This program is free software; you can redistribute it and/or modify it under the terms of the GNU Library General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ #include "opentripplannerbackend.h" #include #include #include #include #include #include #include #include #include #include using namespace KPublicTransport; OpenTripPlannerBackend::OpenTripPlannerBackend() = default; OpenTripPlannerBackend::~OpenTripPlannerBackend() = default; AbstractBackend::Capabilities OpenTripPlannerBackend::capabilities() const { return m_endpoint.startsWith(QLatin1String("https://")) ? Secure : NoCapability; } bool OpenTripPlannerBackend::needsLocationQuery(const Location &loc, AbstractBackend::QueryType type) const { Q_UNUSED(type); return !loc.hasCoordinate(); } bool OpenTripPlannerBackend::queryLocation(const LocationRequest &req, LocationReply *reply, QNetworkAccessManager *nam) const { KGraphQLRequest gqlReq(QUrl(m_endpoint + QLatin1String("index/graphql"))); if (req.hasCoordinate()) { gqlReq.setQueryFromFile(QStringLiteral(":/org.kde.kpublictransport/otp/stationByCoordinate.graphql")); gqlReq.setVariable(QStringLiteral("lat"), req.latitude()); gqlReq.setVariable(QStringLiteral("lon"), req.longitude()); } else { gqlReq.setQueryFromFile(QStringLiteral(":/org.kde.kpublictransport/otp/stationByName.graphql")); gqlReq.setVariable(QStringLiteral("name"), req.name()); } if (isLoggingEnabled()) { logRequest(req, gqlReq.networkRequest(), gqlReq.rawData()); } KGraphQL::query(gqlReq, nam, [this, reply](const KGraphQLReply &gqlReply) { logReply(reply, gqlReply.networkReply(), gqlReply.rawData()); if (gqlReply.error() != KGraphQLReply::NoError) { addError(reply, this, Reply::NetworkError, gqlReply.errorString()); return; } // TODO qDebug() << backendId() << gqlReply.data(); addError(reply, this, Reply::NetworkError, {}); }); return true; } bool OpenTripPlannerBackend::queryDeparture(const DepartureRequest &req, DepartureReply *reply, QNetworkAccessManager *nam) const { KGraphQLRequest gqlReq(QUrl(m_endpoint + QLatin1String("index/graphql"))); gqlReq.setQueryFromFile(QStringLiteral(":/org.kde.kpublictransport/otp/departure.graphql")); // TODO return false; } bool OpenTripPlannerBackend::queryJourney(const JourneyRequest &req, JourneyReply *reply, QNetworkAccessManager *nam) const { KGraphQLRequest gqlReq(QUrl(m_endpoint + QLatin1String("index/graphql"))); gqlReq.setQueryFromFile(QStringLiteral(":/org.kde.kpublictransport/otp/journey.graphql")); gqlReq.setVariable(QStringLiteral("fromLat"), req.from().latitude()); gqlReq.setVariable(QStringLiteral("fromLon"), req.from().longitude()); gqlReq.setVariable(QStringLiteral("toLat"), req.to().latitude()); gqlReq.setVariable(QStringLiteral("toLon"), req.to().longitude()); - // TODO time, arrival/departure + gqlReq.setVariable(QStringLiteral("date"), req.dateTime().date().toString(QStringLiteral("yyyy-MM-dd"))); + gqlReq.setVariable(QStringLiteral("time"), req.dateTime().time().toString(QStringLiteral("hh:mm:ss"))); // TODO timezone conversion? + gqlReq.setVariable(QStringLiteral("arriveBy"), req.dateTimeMode() == JourneyRequest::Arrival); if (isLoggingEnabled()) { logRequest(req, gqlReq.networkRequest(), gqlReq.rawData()); } KGraphQL::query(gqlReq, nam, [this, reply](const KGraphQLReply &gqlReply) { logReply(reply, gqlReply.networkReply(), gqlReply.rawData()); if (gqlReply.error() != KGraphQLReply::NoError) { addError(reply, this, Reply::NetworkError, gqlReply.errorString()); return; } // TODO qDebug() << backendId() << gqlReply.data(); addError(reply, this, Reply::NetworkError, {}); }); return true; } diff --git a/src/lib/backends/otp/journey.graphql b/src/lib/backends/otp/journey.graphql index 7a8b9a0..ffd4d51 100644 --- a/src/lib/backends/otp/journey.graphql +++ b/src/lib/backends/otp/journey.graphql @@ -1,67 +1,77 @@ -query journeys($fromLat: Float!, $fromLon: Float!, $toLat: Float!, $toLon: Float!) { - plan ( +query journeys( + $fromLat: Float!, + $fromLon: Float!, + $toLat: Float!, + $toLon: Float!, + $date: String!, + $time: String!, + $arriveBy: Boolean! +) { + plan ( from: { lat: $fromLat, lon: $fromLon } to: { lat: $toLat, lon: $toLon } + date: $date + time: $time + arriveBy: $arriveBy numItineraries: 3 ) { itineraries { legs { startTime endTime departureDelay arrivalDelay realTime distance mode transitLeg from { name lat lon stop { gtfsId platformCode timezone } } to { name lat lon stop { gtfsId platformCode timezone } } trip { route { - mode type desc shortName longName color textColor #bikesAllowed alerts { alertHeaderTextTranslations { language text } alertDescriptionTextTranslations { language text } alertEffect alertCause alertSeverityLevel } } tripHeadsign tripShortName } } } } }