Package com.unosquare.carmigo.service
Class JourneyService
java.lang.Object
com.unosquare.carmigo.service.JourneyService
Handles requests regarding the
Journey
entity.-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPassengerToJourney
(int journeyId, int passengerId) Enables the user to be a passenger of a journey.calculateDistance
(DistanceRequest distanceRequest) Searches for the distance between two locations.createJourney
(int driverId, JourneyRequest journeyRequest) Only drivers can create journeys.void
deleteJourneyById
(int journeyId) Deletes a journey.getJourneyById
(int journeyId) Fetches a journey.getJourneysByDriverId
(int driverId) Fetches journeys of a driver.getJourneysByPassengersId
(int passengerId) Fetches journeys of a passenger.patchJourney
(int journeyId, com.github.fge.jsonpatch.JsonPatch patch) Corrects journey information.
Pass an array of aJsonPatch
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:void
removePassengerFromJourney
(int journeyId, int passengerId) Enables the user to no longer be a passenger of a journey.searchJourneys
(SearchJourneysRequest searchJourneysRequest) Searches for journeys.
-
Constructor Details
-
JourneyService
public JourneyService()
-
-
Method Details
-
getJourneyById
Fetches a journey.- Parameters:
journeyId
- the journey id to search for.- Returns:
- a
JourneyResponse
.
-
searchJourneys
Searches for journeys.- Parameters:
searchJourneysRequest
- the search criteria asSearchJourneysRequest
.- Returns:
- a List of
JourneyResponse
.
-
getJourneysByDriverId
Fetches journeys of a driver.- Parameters:
driverId
- the driver id to fetch their journeys.- Returns:
- a List of
JourneyResponse
.
-
getJourneysByPassengersId
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 asJourneyRequest
.- 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 aJsonPatch
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
- aJsonPatch
.- 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
Searches for the distance between two locations.- Parameters:
distanceRequest
- the search criteria asDistanceRequest
.- Returns:
- a
DistanceResponse
.
-