An implementation of robot_apocalypse and postgres
The project is meant to run on local machine. Docker is not implemented yet.
Steps to run and test the service.
- Connect PostgresSQL or run PgAdmin in your machine.
- Create database 'robo', script given below- CREATE DATABASE robo;
- All the database details are hardcoded in db_connect.go file (robot_apocalypse/pkg/dbg/db_connect.go) Update the below database configurations in db_connect.go file according to your database- Name = "robo" User = "postgres" Password = "******" Host = "localhost" Port = "5432"
- Clone the repository.
- Go inside the robot_apocalypse folder (Run 'cd robot_apocalypse').
- Go inside the cmd folder (Run cd cmd)
- Run 'go run main.go' command.
- The server will be up in the local machine.
NOTE: All the request and response id captured in api.md file (robot_apocalypse/documention/api.md)
- The endpoints can be accessed on http://localhost:8080/
- POST call on /survivors endpoint will insert data in survivors table.
- UPDATE call on /survivors endpoint will update the location and survivor infected flag in survivors table. Pass the reporter field(assumptions: reporter field stores the number of survivors reporting contamination) as query param when need to update the infected flag.
- GET call on /survivors endpoint will return all the infected and non-infected survivors based on infected flag. Pass query param 'infect=true' to fetch all the infected survivors and 'infect=false' for non-infected survivors.
- GET call on /survivor_percentage will return the percentage of infected and non-infected survivors based on infected flag. Pass query param 'infect=true' to fetch the percentage of infected survivors and 'infect=false' to fetch the percentage of non-infected survivors.
- GET call on /robo will return all the robo information.