diff --git a/server-new/app/Controllers/Http/SummonersController.ts b/server-new/app/Controllers/Http/SummonersController.ts index 5e16950..ee07cf7 100644 --- a/server-new/app/Controllers/Http/SummonersController.ts +++ b/server-new/app/Controllers/Http/SummonersController.ts @@ -4,8 +4,10 @@ import MatchRepository from 'App/Repositories/MatchRepository' import Jax from 'App/Services/Jax' import MatchService from 'App/Services/MatchService' import SummonerService from 'App/Services/SummonerService' +import LiveMatchTransformer from 'App/Transformers/LiveMatchTransformer' import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator' import SummonerChampionValidator from 'App/Validators/SummonerChampionValidator' +import SummonerLiveValidator from 'App/Validators/SummonerLiveValidator' import SummonerRecordValidator from 'App/Validators/SummonerRecordValidator' export default class SummonersController { @@ -76,7 +78,7 @@ export default class SummonersController { * POST: get champions view summoner data * @param ctx */ - public async champions ({ request, response }) { + public async champions ({ request, response }: HttpContextContract) { console.time('championsRequest') const { puuid, queue, season } = await request.validate(SummonerChampionValidator) const championStats = await MatchRepository.championCompleteStats(puuid, queue, season) @@ -88,11 +90,32 @@ export default class SummonersController { * POST: get records view summoner data * @param ctx */ - public async records ({ request, response }) { + public async records ({ request, response }: HttpContextContract) { console.time('recordsRequest') const { puuid, season } = await request.validate(SummonerRecordValidator) const records = await MatchRepository.records(puuid, season) console.timeEnd('recordsRequest') 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) + } } diff --git a/server-new/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts b/server-new/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts index f187e70..2f98114 100644 --- a/server-new/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts +++ b/server-new/app/Services/Jax/src/Endpoints/SpectatorEndpoint.ts @@ -1,7 +1,61 @@ import { RiotRateLimiter } from '@fightmegg/riot-rate-limiter' +import { LeagueEntriesByQueue } from 'App/Services/SummonerService' import { JaxConfig } from '../../JaxConfig' 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 { private config: JaxConfig private limiter: RiotRateLimiter diff --git a/server-new/app/Validators/SummonerLiveValidator.ts b/server-new/app/Validators/SummonerLiveValidator.ts new file mode 100644 index 0000000..1a4e215 --- /dev/null +++ b/server-new/app/Validators/SummonerLiveValidator.ts @@ -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 = {} +}