All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.ext.legacygraphqlapi.datafetchers.LegacyGraphQLfareComponentImpl Maven / Gradle / Ivy

package org.opentripplanner.ext.legacygraphqlapi.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.model.Route;
import org.opentripplanner.routing.RoutingService;
import org.opentripplanner.routing.core.FareComponent;

import java.util.stream.Collectors;

public class LegacyGraphQLfareComponentImpl
    implements LegacyGraphQLDataFetchers.LegacyGraphQLFareComponent {

  @Override
  public DataFetcher fareId() {
    return environment -> getSource(environment).fareId.toString();
  }

  @Override
  public DataFetcher currency() {
    return environment -> getSource(environment).price.getCurrency().getCurrencyCode();
  }

  @Override
  public DataFetcher cents() {
    return environment -> getSource(environment).price.getCents();
  }

  @Override
  public DataFetcher> routes() {
    return environment -> {
      RoutingService routingService = getRoutingService(environment);
      return getSource(environment).routes
          .stream()
          .map(routingService::getRouteForId)
          .collect(Collectors.toList());
    };
  }

  private RoutingService getRoutingService(DataFetchingEnvironment environment) {
    return environment.getContext().getRoutingService();
  }

  private FareComponent getSource(DataFetchingEnvironment environment) {
    return environment.getSource();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy