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

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

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.ext.legacygraphqlapi.datafetchers;

import graphql.schema.DataFetcher;
import graphql.schema.DataFetchingEnvironment;
import java.util.stream.Collectors;
import org.opentripplanner.ext.legacygraphqlapi.LegacyGraphQLRequestContext;
import org.opentripplanner.ext.legacygraphqlapi.generated.LegacyGraphQLDataFetchers;
import org.opentripplanner.routing.core.FareComponent;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.service.TransitService;

public class LegacyGraphQLfareComponentImpl
  implements LegacyGraphQLDataFetchers.LegacyGraphQLFareComponent {

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

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

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

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

  private TransitService getTransitService(DataFetchingEnvironment environment) {
    return environment.getContext().getTransitService();
  }

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




© 2015 - 2025 Weber Informatics LLC | Privacy Policy