The Scootin Aboot Journey API micro-service allows user to fetch nearby scooters and allow them to start and end trips.
-
go v1.18 (for running tests only)
-
docker
- To run tests on the service
make test
- To start the service
make start
-
visit swagger doc in the browser and test APIs. Please refer
scooter
anduser
collections to get scooter id and user id for test. -
To stop the service
make stop
The microservice is used to fetch nearby available scooters and start and end trip with particular scooter.
- User is able to fetch nearby available scooters within the given radius. Please note that this works with real data only.
- User is able to start a trip with available scooter by passing
scooter id
anduser id
. If the scooter is already in use, then the api returns error. - User is able to stop his/her trip which he/she has started already.
- The scooter is used to save the events generated during the trip. e.g. trip_start, trip_end and trip_location_update by passing the scooter id, user id, location and time.
- Fetch the nearby available scooters withing radius
curl -X 'GET' \
'http://localhost:8080/api/v1/auth/user/available-scooters?latitude=-73.856077&longitude=40.848447&radius=10&api_key=secretkey' \
-H 'accept: application/json'
- Begin trip for given user and scooter
curl -X 'PUT' \
'http://localhost:8080/api/v1/auth/user/begin-trip?api_key=secretkey' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"scooter_id": "f691fd32-9b3f-4d71-b9b7-c48213bfd232",
"user_id": "f3b9842c-182a-418b-92fd-95d4f46414c5"
}'
- End trip for given user and scooter
curl -X 'PUT' \
'http://localhost:8080/api/v1/auth/user/end-trip?api_key=secretkey' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"scooter_id": "f691fd32-9b3f-4d71-b9b7-c48213bfd232",
"user_id": "f3b9842c-182a-418b-92fd-95d4f46414c5",
"location": {
"latitude": -73.856077,
"longitude": 40.848447
}
}'
- Save trip event generated by scooter
curl -X 'POST' \
'http://localhost:8080/api/v1/auth/scooter/trip-event?api_key=secretkey' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"created_at": "2022-07-09T18:59:21+00:00",
"location": {
"latitude": -73.856077,
"longitude": 40.848447
},
"scooter_id": "f691fd32-9b3f-4d71-b9b7-c48213bfd232",
"type": "trip_start",
"user_id": "f3b9842c-182a-418b-92fd-95d4f46414c5"
}'
- The service is written using clean code architecture which makes it modular and easy to maintain and test. These are the following layers -
- domain - Inner most layer, no external dependencies
- app - consists of main business logic, dependent on domain only (must have 100% test coverage)
- db - consists of db interface which provides db functions
- URL - localhost:27017
- DB - scootin-aboot-db
- Scooter Collection -
scooter
created during migration at the start of service stores scooter records. - User Collection -
user
created during migration at the start of the service stores user records. - Trip Event Collection -
trip_event
created when the first record is created by scooter.
- config - consists of functions crucial to start the service
- migration - consists of files used in migration.
- api - the layer is used to communicate with the service. The new APIs like grpc or graphQL can be implemented in this layer by keeping other layers intact.
- The sample scooter data and user data is created with the migration when the service is started.