Skip to content

Adityagaddhyan/leaderboard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to Leaderboard!

This is the backend implementaion of 2 player game's leader board using mongoDb as the database and node as the backend framework. The express engine is used to build the API. Go through the api details below to know more about API.

Run in Postman

  • Hosted on EC2 instance.
  • Elastic IP used.
  • Ingress open on port 3000.

to test:

  • Open link in postman
  • make request.
  • preferably create an admin and a user account to test the application.

Key Features

  • Error handling is used extensively to handle all the possible errors.
  • Hosted on AWS.

API DETAILS

AUTH API

Register

  • mobile and password necessary to register. POST /auth/register body:
{
    "name":"ayush raj",
    "location":"kolkata", //optional
    "email":"[email protected]", //required
    "phone":"8888888383",
    "password":"12345@" //required,
    "role": "admin" //to register admin account. For player, not required
}
The Phone number and the email should not be registered

LOGIN

POST 'http://localhost:3000/auth/login' \
--data-raw '{
    "phone":"9386280041", //login only through phone as email can be null
    "password":"12345@"
}'

Update Profile

PUT 'http://localhost:3000/auth/update' \
--header 'auth: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJfaWQiOiI2MDdiMmExZWViYzc0NTMzNTU2YTRkMjEiLCJpYXQiOjE2MTg2OTU3NzcsImV4cCI6MTYxODY5OTM3N30.fUylSVEH871WirLWXeX2fQDuEr9u94-Bps3VjEdguVI' \ //JWT TOKEN
--data-raw '{
    "phone":"9386280041", //phone number can not be changed and is required
    "name":"jhon", //all the other paramaters including password can be changed with this route. all the provided data is updated corresponding to the user.
    "location":"mumbai"
}'

LOGOUT

GET 'http://localhost:3000/auth/logout' \
--data-raw ''

GAME APIs

Get Game

Get the list of all the games with gameID.

 GET 'http://localhost:3000/auth/login'

Submit Score

 POST 'http://localhost:3000/game/score' \
--data-raw '{
"opponentMobile":"8888888888", //opponent mobile number is required and opponnent should be registered
"p1_score":"100", //player 1 score(self)
"p2_score":"80", //opponent score
"gameID":"3"	//get game id from last route
}'
//can be accessed only after logging in

Get Pending

  • need ADMIN rights
  • Gives the list of all the games whose result needs to be declared
 POST 'http://localhost:3000/game/pending' \

POST RESULT

  • Used by admin to post the result of games and save in database.
  • Get game id from /game/pending
 --request POST 'http://localhost:3000/game/result' \
--data-raw '{
"gameID":"607c1dd3b2561d39b861c01f",
"winner":"1"
}'

Get Leaderboard

  • returns the leader board of the game
GET 'http://localhost:3000/game/leaderboard' \
--data-raw '{
"gameID":"1" //required
}'

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published