Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new-api-ligue-1-football-teams #282

Merged
merged 2 commits into from
Oct 26, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/modules/sports/api/sports-routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { getRandomSubArray } from '../../../utils/arrays';
import PremierLeagueData2022 from '../data/football-premier-league-2022';
import LaLigaLeagueData2022 from '../data/football-laliga-league-2022';
import SerieALeagueData2022 from '../data/football-serie-a-league-2022';
import BasketballNbaLeague2022 from '../data/basketball-nba-league-2022'
import BasketballNbaLeague2022 from '../data/basketball-nba-league-2022';
import Ligue1LeagueData2022 from '../data/football-ligue-1-league-2022';

module.exports = function (app: core.Express) {

Expand Down Expand Up @@ -114,4 +115,31 @@ module.exports = function (app: core.Express) {
const qty = getQtyFromRequest(req);
res.json(getRandomSubArray(SerieALeagueData2022, qty));
});

/**
* @openapi
* '/sports/football/leagues/ligue1/teams/{qty}':
* get:
* tags:
* - Sports
* summary: Get a list of teams in the Ligue 1 (France) football league from 2022
* parameters:
* - in: path
* name: qty
* description: The amount of results you would like returned
* default: 10
* type: number
* responses:
* '200':
* description: OK
* schema:
* type: array
* items:
* type: object
* example: { teamName: '', location: '', stadium: '', capacity: ''}
*/
app.get('/sports/football/leagues/ligue1/teams/:qty?', (req: Request, res: Response) => {
const qty = getQtyFromRequest(req);
res.json(getRandomSubArray(Ligue1LeagueData2022, qty));
});
};
125 changes: 125 additions & 0 deletions src/modules/sports/data/football-ligue-1-league-2022.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
const Ligue1LeagueData2022 = [
{
"teamName": "Ajaccio",
"location": "Ajaccio",
"stadium": "Stade François Coty",
"capacity": "10,446"
},
{
"teamName": "Angers",
"location": "Angers",
"stadium": "Stade Raymond Kopa",
"capacity": "18,752"
},
{
"teamName": "Auxerre",
"location": "Auxerre",
"stadium": "Stade de l'Abbé-Deschamps",
"capacity": "21,379"
},
{
"teamName": "Brest",
"location": "Brest",
"stadium": "Stade Francis-Le Blé",
"capacity": "15,931"
},
{
"teamName": "Clermont",
"location": "Clermont-Ferrand",
"stadium": "Stade Gabriel Montpied",
"capacity": "11,980"
},
{
"teamName": "Lens",
"location": "Lens",
"stadium": "Stade Bollaert-Delelis",
"capacity": "37,705"
},
{
"teamName": "Lille",
"location": "Lille",
"stadium": "Decathlon Arena Pierre Mauroy Stadium",
"capacity": "50,186"
},
{
"teamName": "Lorient",
"location": "Lorient",
"stadium": "Stade du Moustoir",
"capacity": "18,890"
},
{
"teamName": "Lyon",
"location": "Lyon",
"stadium": "Groupama Stadium",
"capacity": "59,186"
},
{
"teamName": "Marseille",
"location": "Marseille",
"stadium": "Orange Vélodrome",
"capacity": "67,394"
},
{
"teamName": "Monaco",
"location": " Monaco",
"stadium": "Stade Louis II",
"capacity": "18,523"
},
{
"teamName": "Montpellier",
"location": "Montpellier",
"stadium": "Stade de la Mosson",
"capacity": "32,900"
},
{
"teamName": "Nantes",
"location": "Nantes",
"stadium": "Stade de la Beaujoire",
"capacity": "35,322"
},
{
"teamName": "Nice",
"location": "Nice",
"stadium": "Allianz Riviera",
"capacity": "35,624"
},
{
"teamName": "Paris Saint-Germain",
"location": "Paris",
"stadium": "Parc des Princes",
"capacity": "48,583"
},
{
"teamName": "Reims",
"location": "Reims",
"stadium": "Stade Auguste Delaune",
"capacity": "21,684"
},
{
"teamName": "Rennes",
"location": "Rennes",
"stadium": "Roazhon Park",
"capacity": "29,778"
},
{
"teamName": "Strasbourg",
"location": "Strasbourg",
"stadium": "Stade de la Meinau",
"capacity": "29,230"
},
{
"teamName": "Toulouse",
"location": "Toulouse",
"stadium": "Stadium Municipal",
"capacity": "33,150"
},
{
"teamName": "Troyes",
"location": "Troyes",
"stadium": "Stade de l'Aube",
"capacity": "21,684"
}
]
;

export default Ligue1LeagueData2022;
16 changes: 16 additions & 0 deletions src/modules/sports/tests/api/sports-routes.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,20 @@ describe('sports api endpoints', () => {
expect(response.body.length).toBe(qty);
});
});

describe('GET /sports/football/leagues/ligue1/teams', () => {
it('should return a list of ligue 1 teams', async () => {
const qty = 5;
const response = await request(app).get(`/sports/football/leagues/ligue1/teams/${qty}`);

expect(response.body.length).toBe(qty);
});

it('no quantity specified should return a list of 10 ligue 1 teams', async () => {
const defaultNumber = 10;
const response = await request(app).get(`/sports/football/leagues/ligue1/teams`);

expect(response.body.length).toBe(defaultNumber);
});
});
});