Skip to content

MafaSoft-dev/Dice-game

Repository files navigation

Dice-game

github repo size github last commit

Application built with hexagonal architecture and TDD.

For more information about the game rules and requirements click here

Dashboard

Dashboard page ranking list

To start the server side navigate to the server folder and create a .env file with the following content:

MONGO_URI="yourMongodbUri"
MONGO_URI_TEST="mongodbUriForTest"
NODE_ENV="development"
DATABASE_ENV='mongo'
TEST_DATABASE='test'
DATABASE="dicegame"
PORT="5002"

SQL_URI='mysql://127.0.0.1'
MYSQL_USER='root'
MYSQL_PASSWORD='password'
HOST='127.0.0.1'

JWT_SECRET='yoursecret'

Then run the following commands:

npm install

if you want to run the app with a mongodb database run:

npm run devmongo

if you wish to run the app with a mysql database run:

npm run devmysql

API DOCUMENTATION

if you .env is set with port 8012 if not just adjust the port. You can access the api documentation with the following commands:

first create a player with email and password, name is optional, if name is not provided the default will be "anonim":

curl -X POST -d "name=John&email=john@example.com&password=secretpassword" http://localhost:8012/api/players

then login with the email and password to get the token:

curl -X POST -d "email=john@example.com&password=secretpassword" http://localhost:8012/api/login

Now you can access the api documentation with the following command always adding the token as bearer:

to change name:

curl -X PUT -H "Authorization: Bearer <YOUR_TOKEN>" -d "name=Ronaldinho" http://localhost:8012/api/players/<your_player_id>

to get player list:

curl -X GET -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/players/

to play game:

curl -X POST -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/games/<your_player_id>

to get games:

curl -X GET -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/games/<your_player_id>

to delete all games from a player:

curl -X DELETE -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/games/<your_player_id>

to get Ranking list:

curl -X GET -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/ranking

to get Looser:

curl -X GET -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/ranking/loser

to get Winner:

curl -X GET -H "Authorization: Bearer <YOUR_TOKEN>" http://localhost:8012/api/ranking/winner

RUN WITH DOCKER

To run databases, backend and frontend with docker, type in root directory:

docker compose --profile mongo up -d

or

docker compose --profile sql up -d

With --profile option you can choose which database you want to use by server.

Now you can use Dice-game interface by going to:

http://localhost:8000/login

To stop all docker containers type:

docker compose --profile <profile_name> down