mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 21:07:27 +00:00
feat: add summoners/live endpoint
This commit is contained in:
parent
54a0e07474
commit
2dbf4ba73a
3 changed files with 132 additions and 2 deletions
|
|
@ -4,8 +4,10 @@ import MatchRepository from 'App/Repositories/MatchRepository'
|
||||||
import Jax from 'App/Services/Jax'
|
import Jax from 'App/Services/Jax'
|
||||||
import MatchService from 'App/Services/MatchService'
|
import MatchService from 'App/Services/MatchService'
|
||||||
import SummonerService from 'App/Services/SummonerService'
|
import SummonerService from 'App/Services/SummonerService'
|
||||||
|
import LiveMatchTransformer from 'App/Transformers/LiveMatchTransformer'
|
||||||
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
||||||
import SummonerChampionValidator from 'App/Validators/SummonerChampionValidator'
|
import SummonerChampionValidator from 'App/Validators/SummonerChampionValidator'
|
||||||
|
import SummonerLiveValidator from 'App/Validators/SummonerLiveValidator'
|
||||||
import SummonerRecordValidator from 'App/Validators/SummonerRecordValidator'
|
import SummonerRecordValidator from 'App/Validators/SummonerRecordValidator'
|
||||||
|
|
||||||
export default class SummonersController {
|
export default class SummonersController {
|
||||||
|
|
@ -76,7 +78,7 @@ export default class SummonersController {
|
||||||
* POST: get champions view summoner data
|
* POST: get champions view summoner data
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public async champions ({ request, response }) {
|
public async champions ({ request, response }: HttpContextContract) {
|
||||||
console.time('championsRequest')
|
console.time('championsRequest')
|
||||||
const { puuid, queue, season } = await request.validate(SummonerChampionValidator)
|
const { puuid, queue, season } = await request.validate(SummonerChampionValidator)
|
||||||
const championStats = await MatchRepository.championCompleteStats(puuid, queue, season)
|
const championStats = await MatchRepository.championCompleteStats(puuid, queue, season)
|
||||||
|
|
@ -88,11 +90,32 @@ export default class SummonersController {
|
||||||
* POST: get records view summoner data
|
* POST: get records view summoner data
|
||||||
* @param ctx
|
* @param ctx
|
||||||
*/
|
*/
|
||||||
public async records ({ request, response }) {
|
public async records ({ request, response }: HttpContextContract) {
|
||||||
console.time('recordsRequest')
|
console.time('recordsRequest')
|
||||||
const { puuid, season } = await request.validate(SummonerRecordValidator)
|
const { puuid, season } = await request.validate(SummonerRecordValidator)
|
||||||
const records = await MatchRepository.records(puuid, season)
|
const records = await MatchRepository.records(puuid, season)
|
||||||
console.timeEnd('recordsRequest')
|
console.timeEnd('recordsRequest')
|
||||||
return response.json(records)
|
return response.json(records)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* POST - Return live match detail
|
||||||
|
* @param ctx
|
||||||
|
*/
|
||||||
|
public async liveMatchDetails ({ request, response }: HttpContextContract) {
|
||||||
|
console.time('liveMatchDetails')
|
||||||
|
const { id, region } = await request.validate(SummonerLiveValidator)
|
||||||
|
|
||||||
|
// CURRENT GAME
|
||||||
|
let currentGame = await Jax.Spectator.summonerID(id, region)
|
||||||
|
|
||||||
|
if (!currentGame) {
|
||||||
|
return response.json(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
currentGame = await LiveMatchTransformer.transform(currentGame, { region })
|
||||||
|
console.timeEnd('liveMatchDetails')
|
||||||
|
|
||||||
|
return response.json(currentGame)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,61 @@
|
||||||
import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter'
|
import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter'
|
||||||
|
import { LeagueEntriesByQueue } from 'App/Services/SummonerService'
|
||||||
import { JaxConfig } from '../../JaxConfig'
|
import { JaxConfig } from '../../JaxConfig'
|
||||||
import JaxRequest from '../JaxRequest'
|
import JaxRequest from '../JaxRequest'
|
||||||
|
|
||||||
|
export interface CurrentGameInfo {
|
||||||
|
gameId: number,
|
||||||
|
gameType: string
|
||||||
|
gameStartTime: number,
|
||||||
|
mapId: number,
|
||||||
|
gameLength: number,
|
||||||
|
platformId: string,
|
||||||
|
gameMode: string,
|
||||||
|
bannedChampions: BannedChampion[],
|
||||||
|
gameQueueConfigId: number,
|
||||||
|
observers: Observer,
|
||||||
|
participants: CurrentGameParticipant[],
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface BannedChampion {
|
||||||
|
pickTurn: number,
|
||||||
|
championId: number,
|
||||||
|
teamId: number,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Observer {
|
||||||
|
encryptionKey: string,
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CurrentGameParticipant {
|
||||||
|
championId: number,
|
||||||
|
perks: Perks,
|
||||||
|
profileIconId: number,
|
||||||
|
bot: boolean,
|
||||||
|
teamId: number,
|
||||||
|
summonerName: string,
|
||||||
|
summonerId: string,
|
||||||
|
spell1Id: number,
|
||||||
|
spell2Id: number,
|
||||||
|
gameCustomizationObjects: GameCustomizationObject[],
|
||||||
|
// Custom types from here
|
||||||
|
role?: string,
|
||||||
|
runes?: { primaryRune: string, secondaryRune: string } | {}
|
||||||
|
level?: number,
|
||||||
|
rank?: LeagueEntriesByQueue
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Perks {
|
||||||
|
perkIds: number[]
|
||||||
|
perkStyle: number,
|
||||||
|
perkSubStyle: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface GameCustomizationObject {
|
||||||
|
category: string,
|
||||||
|
content: string
|
||||||
|
}
|
||||||
|
|
||||||
export default class SpectatorEndpoint {
|
export default class SpectatorEndpoint {
|
||||||
private config: JaxConfig
|
private config: JaxConfig
|
||||||
private limiter: RiotRateLimiter
|
private limiter: RiotRateLimiter
|
||||||
|
|
|
||||||
53
server-new/app/Validators/SummonerLiveValidator.ts
Normal file
53
server-new/app/Validators/SummonerLiveValidator.ts
Normal file
|
|
@ -0,0 +1,53 @@
|
||||||
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
import { schema } from '@ioc:Adonis/Core/Validator'
|
||||||
|
|
||||||
|
export default class SummonerLiveValidator {
|
||||||
|
constructor (private ctx: HttpContextContract) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defining a schema to validate the "shape", "type", "formatting" and "integrity" of data.
|
||||||
|
*
|
||||||
|
* For example:
|
||||||
|
* 1. The username must be of data type string. But then also, it should
|
||||||
|
* not contain special characters or numbers.
|
||||||
|
* ```
|
||||||
|
* schema.string({}, [ rules.alpha() ])
|
||||||
|
* ```
|
||||||
|
*
|
||||||
|
* 2. The email must be of data type string, formatted as a valid
|
||||||
|
* email. But also, not used by any other user.
|
||||||
|
* ```
|
||||||
|
* schema.string({}, [
|
||||||
|
* rules.email(),
|
||||||
|
* rules.unique({ table: 'users', column: 'email' }),
|
||||||
|
* ])
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
|
public schema = schema.create({
|
||||||
|
id: schema.string(),
|
||||||
|
region: schema.string(),
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The `schema` first gets compiled to a reusable function and then that compiled
|
||||||
|
* function validates the data at runtime.
|
||||||
|
*
|
||||||
|
* Since, compiling the schema is an expensive operation, you must always cache it by
|
||||||
|
* defining a unique cache key. The simplest way is to use the current request route
|
||||||
|
* key, which is a combination of the route pattern and HTTP method.
|
||||||
|
*/
|
||||||
|
public cacheKey = this.ctx.routeKey
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Custom messages for validation failures. You can make use of dot notation `(.)`
|
||||||
|
* for targeting nested fields and array expressions `(*)` for targeting all
|
||||||
|
* children of an array. For example:
|
||||||
|
*
|
||||||
|
* {
|
||||||
|
* 'profile.username.required': 'Username is required',
|
||||||
|
* 'scores.*.number': 'Define scores as valid numbers'
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public messages = {}
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue