ganeshdipdumbare / scootin-aboot-journey

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Go

Scootin Aboot Journey Service

The Scootin Aboot Journey API micro-service allows user to fetch nearby scooters and allow them to start and end trips.

Contents

Prerequisite

  1. go v1.18 (for running tests only)

  2. docker

Getting started

  1. To run tests on the service
make test
  1. To start the service
make start  
  1. visit swagger doc in the browser and test APIs. Please refer scooter and user collections to get scooter id and user id for test.

  2. To stop the service

make stop 

Description

The microservice is used to fetch nearby available scooters and start and end trip with particular scooter.

Use cases

  1. User is able to fetch nearby available scooters within the given radius. Please note that this works with real data only.
  2. User is able to start a trip with available scooter by passing scooter id and user id. If the scooter is already in use, then the api returns error.
  3. User is able to stop his/her trip which he/she has started already.
  4. 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.

API Operation

  1. 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'
  1. 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"
}'
  1. 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
  }
}'
  1. 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"
}'

Technical details

  • 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.

About


Languages

Language:Go 99.4%Language:Dockerfile 0.5%Language:Makefile 0.2%