alaahatem / Arqam

Backend using Sails js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

match-api

a Node js with Sails v1 application that manipulates match data.

Links

Installation & Configuration

Clone the code using the following command :

git clone https://github.com/alaahatem/Arqam.git

Using docker

  • Prerequisite : Install Docker Check if installed using :
    docker --version

Direct into the project

cd Arqam

Run docker compose server( exposed at same default port 1337 to avoid confusion)

docker-compose up

OR using npm manually

Direct into the project :

cd Arqam

Install dependencies :

npm install

Start the project :

npm start

The postgres database is deployed on heroku (response speed not as locally) to avoid the hassle of configuring it and the connection url should be in env but is embedded to start testing the api immediately

API USAGE

  • Create a new Team (at least two to create a match) All CRUD available
POST http://localhost:1337/team

{
    "name" :"Chelsea"
}
  • Create a new Competition All CRUD available
POST http://localhost:1337/competition

{
    "name" :"Premier League"
}

OPTIONALLY You can also do the following :

  • Create a new Player : All CRUD available
POST http://localhost:1337/player

{
    "name" :"Eden Hazard",
    "number": 10 ,
    "team_id": 3

}
  • Get players with of a specific team with team_id=1
GET http://localhost:1337/player?team_id=1


  • Create a new Referee : All CRUD available
POST http://localhost:1337/referee

{
    "name" :"Howard Webb"
}

Create a new Stadium : All CRUD available

POST http://localhost:1337/stadium

{
    "name" :"Stamford Bridge"
}

MATCH API

  • Create a new Match
  • Make sure to enter the date and time in the same format
  • Matches in the future date or time won't be assigned as they are not played yet.
POST http://localhost:1337/match


{
   "date": "2020-09-25 ",
   "home_team_id":3,
   "away_team_id":1,
   "stadium_id":2,
   "referee_id":2,
   "competition_id":1,
   "kickoff_time":"15:45:00"

}
  • GET All Matches
GET http://localhost:1337/match
  • GET Match by id
GET http://localhost:1337/match/{match_id}
  • GET Matches of a specific team
GET http://localhost:1337/match/team/{team_id}
  • edit a specific match
PATCH http://localhost:1337/match/{match_id}
{
    "home_team_id": 2
}
  • delete a specific match
DELETE http://localhost:1337/match/{match_id}

Collector Api

  • create a new collector
  POST http://localhost:1337/collector
  • edit a collector
  PATCH http://localhost:1337/collector/{collector_id}
  • delete a collector
    DELETE http://localhost:1337/collector/{collector_id}

We have created a match and a collector now we can assign a collector a match

  • Assign collector with id 2 a match with id 1
POST http://localhost:1337/match/1/assign
{
    "collector_id":2
}

Note : Assigning a collector with more than 2 matches won't be accepted and assigning a collector a match that is yet to be played won't be accepted

  • GET history of assignments of a specific collector with id 2
GET http://localhost:1337/collector/2/assignments
  • We can also do any CRUD operation on table matches collector which contains records of match assignments with every record containing a match id and a collector id assigned to that match.
GET http://localhost:1337/matchescollector
DELETE http://localhost:1337/matchescollector/1
  • for example editing a match assignment
PATCH http://localhost:1337/matchescollector/1

{
    collector_id : 1
}
  • Collect a match
PATCH http://localhost:1337/match/{match_id}/collect

About

Backend using Sails js


Languages

Language:JavaScript 51.6%Language:HTML 48.2%Language:Less 0.2%Language:Dockerfile 0.0%