mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: load more matches button
This commit is contained in:
parent
973bc8e29b
commit
d6c4fe3e11
7 changed files with 81 additions and 21 deletions
|
|
@ -178,22 +178,15 @@ export const actions = {
|
|||
async moreMatches({ commit, getters, rootState }) {
|
||||
commit('MATCHES_LOADING')
|
||||
|
||||
const gameIds = getters.filteredMatchList
|
||||
const matchIds = getters.filteredMatchList
|
||||
.slice(state.overview.matchIndex, state.overview.matchIndex + 10)
|
||||
.map((gameId) => {
|
||||
if(typeof gameId == 'string') {
|
||||
return gameId
|
||||
}
|
||||
return gameId.gameId.toString()
|
||||
})
|
||||
|
||||
const resp = await axios(({
|
||||
url: 'match',
|
||||
data: {
|
||||
puuid: state.basic.account.puuid,
|
||||
accountId: state.basic.account.accountId,
|
||||
region: rootState.regionsList[rootState.settings.region],
|
||||
gameIds
|
||||
matchIds
|
||||
},
|
||||
method: 'POST'
|
||||
})).catch(() => { })
|
||||
|
|
|
|||
22
server-v2/app/Controllers/Http/MatchesController.ts
Normal file
22
server-v2/app/Controllers/Http/MatchesController.ts
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import MatchService from 'App/Services/MatchService'
|
||||
import MatchesIndexValidator from 'App/Validators/MatchesIndexValidator'
|
||||
|
||||
export default class MatchesController {
|
||||
/**
|
||||
* POST - Return data from matches searched by gameIds
|
||||
* @param ctx
|
||||
*/
|
||||
public async index({ request, response }: HttpContextContract) {
|
||||
console.log('More Matches Request')
|
||||
const { puuid, region, matchIds, season } = await request.validate(MatchesIndexValidator)
|
||||
const matches = await MatchService.getMatches(region, matchIds, puuid)
|
||||
|
||||
// TODO: add Stats here
|
||||
// const stats = await StatsService.getSummonerStats(puuid, season)
|
||||
return response.json({
|
||||
matches,
|
||||
stats: 'TODO',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -54,21 +54,22 @@ export default class SummonersController {
|
|||
|
||||
public async overview({ request, response }: HttpContextContract) {
|
||||
console.time('OVERVIEW_REQUEST')
|
||||
const { puuid, accountId, region, season } = await request.validate(SummonerOverviewValidator)
|
||||
const { puuid, region, season } = await request.validate(SummonerOverviewValidator)
|
||||
const finalJSON: any = {}
|
||||
|
||||
// Summoner in DB
|
||||
const summonerDB = await Summoner.firstOrCreate({ puuid: puuid })
|
||||
|
||||
// MATCHES BASIC
|
||||
const matchIds = await summonerDB
|
||||
const matchlist = await summonerDB
|
||||
.related('matchList')
|
||||
.query()
|
||||
.select('matchId')
|
||||
.orderBy('matchId', 'desc')
|
||||
.limit(10)
|
||||
const matchIds = matchlist.map((m) => m.matchId)
|
||||
|
||||
finalJSON.matchesDetails = await MatchService.getMatches(region, matchIds, summonerDB)
|
||||
finalJSON.matchesDetails = await MatchService.getMatches(region, matchIds, puuid)
|
||||
|
||||
// TODO: STATS
|
||||
// console.time('STATS')
|
||||
|
|
|
|||
|
|
@ -81,16 +81,16 @@ class MatchService {
|
|||
*/
|
||||
public async getMatches(
|
||||
region: string,
|
||||
matchList: SummonerMatchlist[],
|
||||
summonerDB: Summoner
|
||||
matchIds: string[],
|
||||
puuid: string
|
||||
): Promise<SerializedMatch[]> {
|
||||
console.time('getMatches')
|
||||
|
||||
let matches: SerializedMatch[] = []
|
||||
const matchesToGetFromRiot: MatchlistDto = []
|
||||
for (let i = 0; i < matchList.length; ++i) {
|
||||
for (let i = 0; i < matchIds.length; ++i) {
|
||||
const matchSaved = await Match.query()
|
||||
.where('id', matchList[i].matchId)
|
||||
.where('id', matchIds[i])
|
||||
.preload('blueTeam')
|
||||
.preload('redTeam')
|
||||
.preload('players')
|
||||
|
|
@ -98,9 +98,9 @@ class MatchService {
|
|||
|
||||
if (matchSaved) {
|
||||
// TODO: Serialize match from DB + put it in Redis + push it in "matches"
|
||||
matches.push(BasicMatchSerializer.serializeOneMatch(matchSaved, summonerDB.puuid))
|
||||
matches.push(BasicMatchSerializer.serializeOneMatch(matchSaved, puuid))
|
||||
} else {
|
||||
matchesToGetFromRiot.push(matchList[i].matchId)
|
||||
matchesToGetFromRiot.push(matchIds[i])
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -113,7 +113,7 @@ class MatchService {
|
|||
const parsedMatches: any = await MatchParser.parse(matchesFromApi)
|
||||
|
||||
// TODO: Serialize match from DB + put it in Redis + push it in "matches"
|
||||
const serializedMatches = BasicMatchSerializer.serialize(parsedMatches, summonerDB.puuid)
|
||||
const serializedMatches = BasicMatchSerializer.serialize(parsedMatches, puuid)
|
||||
matches = [...matches, ...serializedMatches]
|
||||
}
|
||||
|
||||
|
|
|
|||
45
server-v2/app/Validators/MatchesIndexValidator.ts
Normal file
45
server-v2/app/Validators/MatchesIndexValidator.ts
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { schema } from '@ioc:Adonis/Core/Validator'
|
||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
|
||||
export default class MatchesIndexValidator {
|
||||
constructor(protected ctx: HttpContextContract) {}
|
||||
|
||||
/*
|
||||
* Define 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({
|
||||
puuid: schema.string(),
|
||||
region: schema.string(),
|
||||
matchIds: schema.array().members(schema.string()),
|
||||
season: schema.number.optional(),
|
||||
})
|
||||
|
||||
/**
|
||||
* 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 = {}
|
||||
}
|
||||
|
|
@ -25,7 +25,6 @@ export default class SummonerOverviewValidator {
|
|||
*/
|
||||
public schema = schema.create({
|
||||
puuid: schema.string(),
|
||||
accountId: schema.string(),
|
||||
region: schema.string(),
|
||||
season: schema.number.optional(),
|
||||
})
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ Route.post('/summoner/overview', 'SummonersController.overview')
|
|||
// Route.post('/summoner/records', 'SummonersController.records')
|
||||
// Route.post('/summoner/live', 'SummonersController.liveMatchDetails')
|
||||
|
||||
// Route.post('/match', 'MatchesController.index')
|
||||
Route.post('/match', 'MatchesController.index')
|
||||
// Route.post('/match/details', 'MatchesController.show')
|
||||
// Route.post('/match/details/ranks', 'MatchesController.showRanks')
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue