- Go
- PostgreSQL
- Docker
- Makefile
- Postman
All database tables are in migrations
folder. To run them, use make
command.
make migrate-up
- to run up migrationsmake migrate-down
- to run down migrationsmake migrate-force
- to force run migrations if you have some errors likeerror: Dirty database version -1. Fix and force version.
users
- contains users datatransaction
- contains transactions data
GET /users
- to get all usersGET /users/{user_id}
- to get user by id, check his balanceGET /transactions/{user_id}
- to get all transactions by user id (check if user has any transactions)POST /process-record/{user_id}
- to process record by user id
Process record request body example:
{
"amount": 10,
"transaction_id": "64338a05-81e5-426b-b01e-927e447c9e33",
"state": "win"
}
Transaction id is unique, so you can't process the same transaction twice, provide UUID v4 format.
State can be win
or lose
.
Amount is a number should be positive but to have a negative balance you should provide a lose
state.
Source-Type: game
- available values:game
,server
,payment
Postman collection is in postman
folder to test endpoints.
- Create
.env
file in root folder and add all required variables from.env.example
file - To run migrations you should have migrate tool installed. You can install it with
brew install golang-migrate
(https://github.com/golang-migrate/migrate/tree/master/cmd/migrate) - To run any
make
command you should havemake
tool installed. You can install it withsudo apt install make
command (https://linuxhint.com/install-make-ubuntu/) - Run
make migrate-up
command to run migrations and create all tables with test user (user_id:63e83104-b9a7-4fec-929e-9d08cae3f9b9
) - Run
make run
command to run application - Take a look at
postman
folder to take collection for testing all endpoints
Test user with id 63e83104-b9a7-4fec-929e-9d08cae3f9b9
will be created automatically when you run migrations.
This user has 50 amount of his balance for testing.
- Create
.env
file in root folder and add all required variables from.env.example
file - To run docker container you should have
docker
anddocker-compose
tools installed (Tested onDocker version 26.1.3, build b72abbb
andDocker Compose version v2.27.1
) docker-compose up
- to run application in docker containerdocker-compose down
- to stop application in docker container