2020-10-11 14:35:23 +00:00
|
|
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
2021-09-20 17:20:51 +00:00
|
|
|
import Match from 'App/Models/Match'
|
|
|
|
|
import MatchPlayerRankParser from 'App/Parsers/MatchPlayerRankParser'
|
|
|
|
|
import DetailedMatchSerializer from 'App/Serializers/DetailedMatchSerializer'
|
|
|
|
|
import MatchPlayerRankSerializer from 'App/Serializers/MatchPlayerRankSerializer'
|
2020-10-11 14:35:23 +00:00
|
|
|
import MatchService from 'App/Services/MatchService'
|
|
|
|
|
import StatsService from 'App/Services/StatsService'
|
2020-10-11 15:31:16 +00:00
|
|
|
import DetailedMatchValidator from 'App/Validators/DetailedMatchValidator'
|
2020-10-11 14:35:23 +00:00
|
|
|
import MatchesIndexValidator from 'App/Validators/MatchesIndexValidator'
|
2020-10-04 20:05:44 +00:00
|
|
|
|
|
|
|
|
export default class MatchesController {
|
2020-10-11 15:31:16 +00:00
|
|
|
/**
|
2021-09-20 17:20:51 +00:00
|
|
|
* POST - Return data from matches searched by matchIds
|
|
|
|
|
* @param ctx
|
2020-10-11 15:31:16 +00:00
|
|
|
*/
|
2021-09-20 17:20:51 +00:00
|
|
|
public async index({ request, response }: HttpContextContract) {
|
|
|
|
|
const { puuid, region, matchIds, season } = await request.validate(MatchesIndexValidator)
|
|
|
|
|
const matches = await MatchService.getMatches(region, matchIds, puuid)
|
2020-10-11 14:35:23 +00:00
|
|
|
|
2020-11-14 17:47:17 +00:00
|
|
|
const stats = await StatsService.getSummonerStats(puuid, season)
|
2020-10-11 14:35:23 +00:00
|
|
|
return response.json({
|
|
|
|
|
matches,
|
|
|
|
|
stats,
|
|
|
|
|
})
|
|
|
|
|
}
|
2020-10-11 15:31:16 +00:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST - Return details data for one specific match
|
2021-09-20 17:20:51 +00:00
|
|
|
* @param ctx
|
2020-10-11 15:31:16 +00:00
|
|
|
*/
|
2021-09-20 17:20:51 +00:00
|
|
|
public async show({ request, response }: HttpContextContract) {
|
2020-10-11 15:31:16 +00:00
|
|
|
console.time('MatchDetails')
|
2021-09-20 17:20:51 +00:00
|
|
|
const { matchId } = await request.validate(DetailedMatchValidator)
|
2020-10-11 15:31:16 +00:00
|
|
|
|
2021-09-20 17:20:51 +00:00
|
|
|
const match = await Match.query()
|
|
|
|
|
.where('id', matchId)
|
|
|
|
|
.preload('teams')
|
|
|
|
|
.preload('players', (playersQuery) => {
|
|
|
|
|
playersQuery.preload('ranks')
|
|
|
|
|
})
|
|
|
|
|
.firstOrFail()
|
2021-03-15 20:29:36 +00:00
|
|
|
|
2021-09-20 17:20:51 +00:00
|
|
|
const { match: matchDetails, ranksLoaded } = DetailedMatchSerializer.serializeOneMatch(match)
|
2020-10-11 15:31:16 +00:00
|
|
|
|
|
|
|
|
console.timeEnd('MatchDetails')
|
|
|
|
|
|
|
|
|
|
return response.json({
|
|
|
|
|
matchDetails,
|
2021-09-20 17:20:51 +00:00
|
|
|
ranksLoaded,
|
2020-10-11 15:31:16 +00:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* POST - Return ranks of players for a specific game
|
2021-09-20 17:20:51 +00:00
|
|
|
* @param ctx
|
2020-10-11 15:31:16 +00:00
|
|
|
*/
|
2021-09-20 17:20:51 +00:00
|
|
|
public async showRanks({ request, response }: HttpContextContract) {
|
2020-10-11 15:31:16 +00:00
|
|
|
console.time('Ranks')
|
2021-09-20 17:20:51 +00:00
|
|
|
const { matchId } = await request.validate(DetailedMatchValidator)
|
|
|
|
|
const match = await Match.query().where('id', matchId).preload('players').firstOrFail()
|
|
|
|
|
const parsedRanks = await MatchPlayerRankParser.parse(match)
|
|
|
|
|
const serializedRanks = MatchPlayerRankSerializer.serialize(parsedRanks)
|
2020-10-11 15:31:16 +00:00
|
|
|
|
|
|
|
|
console.timeEnd('Ranks')
|
2021-09-20 17:20:51 +00:00
|
|
|
return response.json(serializedRanks)
|
2020-10-11 15:31:16 +00:00
|
|
|
}
|
2020-10-04 20:05:44 +00:00
|
|
|
}
|