Class JourneyService

java.lang.Object
com.unosquare.carmigo.service.JourneyService

@Service public class JourneyService extends Object
Handles requests regarding the Journey entity.
  • Constructor Details

    • JourneyService

      public JourneyService()
  • Method Details

    • getJourneyById

      @Cacheable(value="journey", key="#journeyId") public JourneyResponse getJourneyById(int journeyId)
      Fetches a journey.
      Parameters:
      journeyId - the journey id to search for.
      Returns:
      a JourneyResponse.
    • searchJourneys

      public List<JourneyResponse> searchJourneys(SearchJourneysRequest searchJourneysRequest)
      Searches for journeys.
      Parameters:
      searchJourneysRequest - the search criteria as SearchJourneysRequest.
      Returns:
      a List of JourneyResponse.
    • getJourneysByDriverId

      public List<JourneyResponse> getJourneysByDriverId(int driverId)
      Fetches journeys of a driver.
      Parameters:
      driverId - the driver id to fetch their journeys.
      Returns:
      a List of JourneyResponse.
    • getJourneysByPassengersId

      public List<JourneyResponse> getJourneysByPassengersId(int passengerId)
      Fetches journeys of a passenger.
      Parameters:
      passengerId - the passenger id to fetch their journeys.
      Returns:
      a List of JourneyResponse.
    • createJourney

      @CachePut(value="journey", key="#result.id") public JourneyResponse createJourney(int driverId, JourneyRequest journeyRequest)
      Only drivers can create journeys.
      Parameters:
      driverId - the driver id to create a journey for.
      journeyRequest - the requirements as JourneyRequest.
      Returns:
      a JourneyResponse.
    • addPassengerToJourney

      @CacheEvict(value="journey", key="#journeyId") public void addPassengerToJourney(int journeyId, int passengerId)
      Enables the user to be a passenger of a journey.
      Parameters:
      journeyId - the journey id to add this passenger.
      passengerId - the passenger id.
    • patchJourney

      @CachePut(value="journey", key="#journeyId") public JourneyResponse patchJourney(int journeyId, com.github.fge.jsonpatch.JsonPatch patch)
      Corrects journey information.
      Pass an array of a JsonPatch body with operation, the path and the value.
      Accepted operation values are “add”, "remove", "replace", "move", "copy" and "test".
      Here is an example which updates a journey to take up to 3 passengers, and it is going to destination id 5:
         [
           {
             "op": "replace",
             "path": "/maxPassengers",
             "value": "3"
           },
           {
             "op": "replace",
             "path": "/locationTo/id",
             "value": "5"
           }
         ]
       
      Parameters:
      journeyId - the journey id to be updated.
      patch - a JsonPatch.
      Returns:
      a JourneyResponse.
    • deleteJourneyById

      @CacheEvict(value="journey", key="#journeyId") public void deleteJourneyById(int journeyId)
      Deletes a journey.
      Parameters:
      journeyId - the journey id to be deleted.
    • removePassengerFromJourney

      @Transactional @CacheEvict(value="journey", key="#journeyId") public void removePassengerFromJourney(int journeyId, int passengerId)
      Enables the user to no longer be a passenger of a journey.
      Parameters:
      journeyId - the journey id to remove this passenger.
      passengerId - the passenger id.
    • calculateDistance

      public DistanceResponse calculateDistance(DistanceRequest distanceRequest)
      Searches for the distance between two locations.
      Parameters:
      distanceRequest - the search criteria as DistanceRequest.
      Returns:
      a DistanceResponse.