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

feat: add documentation of API (/w refactor of routes) #29

Open
wants to merge 66 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
bd3105e
refactor: separete routing in files
Jan 5, 2023
181573c
fix conflicts
bytelovers Jan 5, 2023
045d953
feat(routes): add new routes from new endpoints
bytelovers Jan 5, 2023
d3ed33a
feat(routes): group routes into single folder
bytelovers Jan 5, 2023
798394f
feat(routes): add documentation jsdoc
bytelovers Jan 5, 2023
124a9f7
fix(routes): typo in doc
bytelovers Jan 5, 2023
24c7d84
fix: resolve merge conflicts
bytelovers Jan 6, 2023
e52cb12
fix: typo & move test file
bytelovers Jan 6, 2023
a84e291
fix: documentation
bytelovers Jan 7, 2023
e574fd8
fix: remove useless file
bytelovers Jan 7, 2023
7319c38
fix: api docs
bytelovers Jan 7, 2023
cd0b4e2
fix: useless files
bytelovers Jan 7, 2023
ecb44f2
fix: api documentantion
bytelovers Jan 7, 2023
10d1a0e
fix: formatter & linter
bytelovers Jan 7, 2023
0819dba
[bot] Update Kings League Database
Jan 8, 2023
75af85c
fix conflicts
bytelovers Jan 8, 2023
8039cb1
[bot] Update Kings League Database
Jan 8, 2023
43bfd39
[bot] Update Kings League Database
Jan 8, 2023
9c9f83b
[bot] Update Kings League Database
Jan 8, 2023
6da5a94
Merge branch 'midudev:main' into main
bytelovers Jan 8, 2023
263e16d
fix conflicts
bytelovers Jan 8, 2023
7243fa7
chore: extract api directory to JSON
bytelovers Jan 8, 2023
7985e76
feat: add API documentation to static site
bytelovers Jan 8, 2023
0de6f98
feat: update API site
bytelovers Jan 8, 2023
4e573f9
[bot] update Kings League database
Jan 8, 2023
fd9d182
[bot] update Kings League database
Jan 8, 2023
60e6d5a
Merge branch 'midudev:main' into main
bytelovers Jan 9, 2023
54a7720
Merge branch 'midudev:main' into main
bytelovers Jan 9, 2023
4828347
fix conflicts
bytelovers Jan 9, 2023
f88d42a
Merge branch 'midudev:main' into main
bytelovers Jan 9, 2023
bb0dce2
Merge branch 'main' into feature/routing
bytelovers Jan 9, 2023
0c557e7
Merge branch 'midudev:main' into main
bytelovers Jan 10, 2023
9410ea6
Merge branch 'midudev:main' into main
bytelovers Jan 10, 2023
8771ea5
Merge branch 'main' into feature/routing
bytelovers Jan 10, 2023
da028bf
Merge branch 'midudev:main' into main
bytelovers Jan 11, 2023
9d174f8
Merge branch 'main' into feature/routing
bytelovers Jan 11, 2023
b582946
[bot] update Kings League database
Jan 11, 2023
d61d17b
[bot] update Kings League database
Jan 12, 2023
568a051
Merge branch 'midudev:main' into main
bytelovers Jan 12, 2023
d83af31
:zap: Update README with the recent activity
github-actions[bot] Jan 12, 2023
63e1c6c
[bot] update Kings League database
Jan 13, 2023
59c8aac
[bot] update Kings League database
Jan 14, 2023
667d7b9
[bot] update Kings League database
Jan 15, 2023
c28cb2f
[bot] update Kings League database
Jan 15, 2023
674e056
[bot] update Kings League database
Jan 15, 2023
99b9c84
[bot] update Kings League database
Jan 15, 2023
3f300a1
[bot] update Kings League database
Jan 15, 2023
bb77154
[bot] update Kings League database
Jan 15, 2023
09bcabe
[bot] update Kings League database
Jan 15, 2023
32e19a7
[bot] update Kings League database
Jan 15, 2023
68b9d24
[bot] update Kings League database
Jan 15, 2023
e6c2746
[bot] update Kings League database
Jan 15, 2023
0c619e3
[bot] update Kings League database
Jan 15, 2023
2ccd9b6
[bot] update Kings League database
Jan 15, 2023
7e80c6f
[bot] update Kings League database
Jan 15, 2023
00ec688
[bot] update Kings League database
Jan 15, 2023
57b34a7
[bot] update Kings League database
Jan 15, 2023
0b40136
[bot] update Kings League database
Jan 15, 2023
b8d816a
[bot] update Kings League database
Jan 15, 2023
6d03cb7
[bot] update Kings League database
Jan 15, 2023
20ba28c
[bot] update Kings League database
Jan 15, 2023
960d1d2
[bot] update Kings League database
Jan 15, 2023
b4f846a
[bot] update Kings League database
Jan 15, 2023
7881b25
[bot] update Kings League database
Jan 15, 2023
5f28a9a
[bot] update Kings League database
Jan 15, 2023
fa7742e
Merge branch 'main' into feature/routing
Jan 16, 2023
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
97 changes: 16 additions & 81 deletions api/index.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Hono } from 'hono'
import { serveStatic } from 'hono/serve-static.module'
import leaderboard from '../db/leaderboard.json'
import teams from '../db/teams.json'
import presidents from '../db/presidents.json'
import topScorers from '../db/top_scorers.json'
import coaches from '../db/coaches.json'
import mvp from '../db/mvp.json'
import topAssists from '../db/top_assists.json'

import { coachesApi } from './routes/coaches.routes'
import { mvpApi } from './routes/mvp.routes'
import { presidentApi } from './routes/presidents.routes'
import { teamsApi } from './routes/teams.routes'
import { topScorersApi } from './routes/top-scorers.routes'
import { topAssistApi } from './routes/top-assists.routes'
import { leaderboardApi } from './routes/leaderboard.routes'


const app = new Hono()

Expand Down Expand Up @@ -85,80 +87,13 @@ app.get('/', (ctx) =>
])
)

app.get('/leaderboard', (ctx) => {
return ctx.json(leaderboard)
})

app.get('/leaderboard/:teamId', (ctx) => {
const teamId = ctx.req.param('teamId')
const foundTeam = leaderboard.find((stats) => stats.team.id === teamId)

return foundTeam ? ctx.json(foundTeam) : ctx.json({ message: 'Team not found' }, 404)
})

app.get('/teams', (ctx) => {
return ctx.json(teams)
})

app.get('/presidents', (ctx) => {
return ctx.json(presidents)
})

app.get('/top-scorers', (ctx) => {
return ctx.json(topScorers)
})

app.get('/top-scorers/:rank', (ctx) => {
const ranking = ctx.req.param('rank')
const foundScorer = topScorers.find((scorer) => scorer.ranking === ranking)

return foundScorer ? ctx.json(foundScorer) : ctx.json({ message: 'Top scorer not found' }, 404)
})

app.get('/top-assists', (ctx) => {
return ctx.json(topAssists)
})

app.get('/top-assists/:rank', (ctx) => {
const ranking = ctx.req.param('rank')
const foundAssister = topAssists.find((assister) => assister.rank === ranking)

return foundAssister
? ctx.json(foundAssister)
: ctx.json({ message: 'Top assister not found' }, 404)
})

app.get('/mvp', (ctx) => {
return ctx.json(mvp)
})

app.get('/coaches', (ctx) => {
return ctx.json(coaches)
})

app.get('/coaches/:teamId', (ctx) => {
const teamId = ctx.req.param('teamId')
const teamName = teams.find((team) => team.id === teamId)
const foundedCoach = coaches.find((coach) => coach.teamName === teamName)

return foundedCoach ? ctx.json(foundedCoach) : ctx.json({ message: 'Coach not found' }, 404)
})

app.get('/presidents/:id', (ctx) => {
const id = ctx.req.param('id')
const foundPresident = presidents.find((president) => president.id === id)

return foundPresident
? ctx.json(foundPresident)
: ctx.json({ message: 'President not found' }, 404)
})

app.get('/teams/:id', (ctx) => {
const id = ctx.req.param('id')
const foundTeam = teams.find((team) => team.id === id)

return foundTeam ? ctx.json(foundTeam) : ctx.json({ message: 'Team not found' }, 404)
})
app.route('/coachs', coachesApi)
app.route('/leaderboard', leaderboardApi)
app.route('/mvp', mvpApi)
app.route('/presidents', presidentApi)
app.route('/teams', teamsApi)
app.route('/top-assists', topAssistApi)
app.route('/top-scorers', topScorersApi)

app.get('/static/*', serveStatic({ root: './' }))

Expand Down
29 changes: 29 additions & 0 deletions api/routes/coaches.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { Hono } from 'hono'

import coaches from '../../db/coaches.json'
import teams from '../../db/teams.json'

const coachesApi = new Hono()

/**
@api {GET} /coaches Get all coaches
@apiName GetCoaches
@APIGroup Coaches
@apiSuccess {Object[]} Coaches list.
@apiSuccess {String} coaches.name Name of coach.
@apiSuccess {String} coaches.teamName Name of team belongs to coach.
@apiSuccess {String} coaches.image Image o the coach.
*/
coachesApi.get('/', (ctx) => {
return ctx.json(coaches)
})

coachesApi.get('/:teamId', (ctx) => {
const teamId = ctx.req.param('teamId')
const teamName = teams.find((team) => team.id === teamId)
const foundedCoach = coaches.find((coach) => coach.teamName === teamName)

return foundedCoach ? ctx.json(foundedCoach) : ctx.json({ message: 'Coach not found' }, 404)
})

export { coachesApi }
File renamed without changes.
48 changes: 48 additions & 0 deletions api/routes/leaderboard.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
import { Hono } from 'hono'

import leaderboard from '../../db/leaderboard.json'

const leaderboardApi = new Hono()

/**
@api {GET} /teams Get all teams
@apiName GetTeams
@APIGroup Teams
@apiSuccess {Object[]} team list.
@apiSuccess {Number} teams.id Team ID.
@apiSuccess {String} teams.name Team name.
@apiSuccess {String} teams.image Team image.
@apiSuccess {String} teams.url Team URL.
@apiSuccess {Number} presindent.id ID of President belongs to team.
@apiSuccess {String} teams.channel URL of channel of the team.
@apiSuccess {Array} teams.socialNetwork List of networks of the team.
@apiSuccess {Array} teams.players List of players belongs to team.
@apiSuccess {String} teams.coach Name of the coach.
*/
leaderboardApi.get('/', (ctx) => {
return ctx.json(leaderboard)
})

/**
@api {GET} /teams/teamId Get team by ID
@apiName GetTeams
@APIGroup Teams
@apiSuccess {Number} teams.id Team ID.
@apiSuccess {String} teams.name Team name.
@apiSuccess {String} teams.image Team image.
@apiSuccess {String} teams.url Team URL.
@apiSuccess {Number} presindent.id ID of President belongs to team.
@apiSuccess {String} teams.channel URL of channel of the team.
@apiSuccess {Array} teams.socialNetwork List of networks of the team.
@apiSuccess {Array} teams.players List of players belongs to team.
@apiSuccess {String} teams.coach Name of the coach.
@apiError (404) {Object} NotFoundError Team not found.
*/
leaderboardApi.get('/:teamId', (ctx) => {
const teamId = ctx.req.param('teamId')
const foundTeam = leaderboard.find((stats) => stats.team.id === teamId)

return foundTeam ? ctx.json(foundTeam) : ctx.json({ message: 'Team not found' }, 404)
})

export { leaderboardApi }
23 changes: 23 additions & 0 deletions api/routes/mvp.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Hono } from 'hono'

import mvp from '../../db/mvp.json'

const mvpApi = new Hono()

/**
@api {GET} /mvp Get all presidents
@apiName GetMVPPlayers
@APIGroup MVP
@apiSuccess {Object[]} MVP List of players.
@apiSuccess {String} MVP.playerName MVP player's name.
@apiSuccess {String} MVP.gamesPlayed Player games.
@apiSuccess {String} MVP.mvps Number of MVPs
@apiSuccess {String} MVP.rank Ranking position
@apiSuccess {String} MVP.team Team belongs to player
@apiSuccess {String} MVP.image Logo of the team
*/
mvpApi.get('/', (ctx) => {
return ctx.json(mvp)
})

export { mvpApi }
40 changes: 40 additions & 0 deletions api/routes/presidents.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import { Hono } from 'hono'

import presidents from '../../db/presidents.json'

const presidentApi = new Hono()

/**
@api {GET} /presidents Get all presidents
@apiName GetPresidents
@APIGroup Presidents
@apiSuccess {Object[]} presidents list.
@apiSuccess {Number} presidents.id President ID.
@apiSuccess {String} presidents.name President name.
@apiSuccess {String} presidents.party President political party.
*/
presidentApi.get('/', (ctx) => {
return ctx.json(presidents)
})
/**
@api {GET} /presidents/:id Get a president by ID
@apiName GetPresidentById
@APIGroup Presidents
@apiParam {Number} id President ID.
@apiSuccess {Object} president President object.
@apiSuccess {Number} president.id President ID.
@apiSuccess {String} president.name President name.
@apiSuccess {String} president.party President political party.
@apiError (404) {Object} NotFoundError President not found.
*/
presidentApi.get('/:id', (ctx) => {
const id = ctx.req.param('id')
const foundPresident = presidents.find((president) => president.id === id)
if (!foundPresident) {
return ctx.json({ message: 'President not found' }, 404)
}

return ctx.json(foundPresident)
})

export { presidentApi }
50 changes: 50 additions & 0 deletions api/routes/teams.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Hono } from 'hono'

import teams from '../../db/teams.json'

const teamsApi = new Hono()

/**
@api {GET} /teams Get all teams
@apiName GetTeams
@APIGroup Teams
@apiSuccess {Object[]} team list.
@apiSuccess {Number} teams.id Team ID.
@apiSuccess {String} teams.name Team name.
@apiSuccess {String} teams.image Team image.
@apiSuccess {String} teams.url Team URL.
@apiSuccess {Number} presindent.id ID of President belongs to team.
@apiSuccess {String} teams.channel URL of channel of the team.
@apiSuccess {Array} teams.socialNetwork List of networks of the team.
@apiSuccess {Array} teams.players List of players belongs to team.
@apiSuccess {String} teams.coach Name of the coach.
*/
teamsApi.get('/', (ctx) => {
return ctx.json(teams)
})

/**
@api {GET} /teams/id Get team by ID
@apiName GetTeams
@APIGroup Teams
@apiSuccess {Number} teams.id Team ID.
@apiSuccess {String} teams.name Team name.
@apiSuccess {String} teams.image Team image.
@apiSuccess {String} teams.url Team URL.
@apiSuccess {Number} presindent.id ID of President belongs to team.
@apiSuccess {String} teams.channel URL of channel of the team.
@apiSuccess {Array} teams.socialNetwork List of networks of the team.
@apiSuccess {Array} teams.players List of players belongs to team.
@apiSuccess {String} teams.coach Name of the coach.
@apiError (404) {Object} NotFoundError Team not found.
*/
teamsApi.get('/:id', (ctx) => {
const id = ctx.req.param('id')
const foundTeam = teams.find((team) => team.id === id)

return foundTeam
? ctx.json(foundTeam)
: ctx.json({ message: 'Team not found' }, 404)
})

export { teamsApi }
30 changes: 30 additions & 0 deletions api/routes/top-assists.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Hono } from 'hono'

import topAssists from '../../db/top_assists.json'

const topAssistApi = new Hono()

/**
@api {GET} /top-scores Get Top Scorers
@apiName GetTopScorers
@APIGroup Top Scorers
@apiSuccess {Object[]} Top Scorers.
@apiSuccess {String} topScorer.playerName Top Scorer's name.
@apiSuccess {String} topScorer.gamesPlayed Played games.
@apiSuccess {String} topScorer.goals Number of goals
@apiSuccess {String} topScorer.rank Ranking position
@apiSuccess {String} topScorer.team Team belongs to player
@apiSuccess {String} topScorer.image Logo of the team
*/
topAssistApi.get('/', (ctx) => {
return ctx.json(topAssists)
})

topAssistApi.get('/:rank', (ctx) => {
const ranking = ctx.req.param('rank')
const foundAssist = topAssists.find((scorer) => scorer.ranking === ranking)

return foundAssist ? ctx.json(foundAssist) : ctx.json({ message: 'Top assist not found' }, 404)
})

export { topAssistApi }
30 changes: 30 additions & 0 deletions api/routes/top-scorers.routes.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Hono } from 'hono'

import topScorers from '../../db/top_scorers.json'

const topScorersApi = new Hono()

/**
@api {GET} /top-scores Get Top Scorers
@apiName GetTopScorers
@APIGroup Top Scorers
@apiSuccess {Object[]} Top Scorers.
@apiSuccess {String} topScorer.playerName Top Scorer's name.
@apiSuccess {String} topScorer.gamesPlayed Played games.
@apiSuccess {String} topScorer.goals Number of goals
@apiSuccess {String} topScorer.rank Ranking position
@apiSuccess {String} topScorer.team Team belongs to player
@apiSuccess {String} topScorer.image Logo of the team
*/
topScorersApi.get('/', (ctx) => {
return ctx.json(topScorers)
})

topScorersApi.get('/:rank', (ctx) => {
const ranking = ctx.req.param('rank')
const foundScorer = topScorers.find((scorer) => scorer.ranking === ranking)

return foundScorer ? ctx.json(foundScorer) : ctx.json({ message: 'Top scorer not found' }, 404)
})

export { topScorersApi }
Loading