mirror of
https://github.com/vkaelin/LeagueStats.git
synced 2026-03-25 12:57:28 +00:00
feat: start summoner/basic endpoint
This commit is contained in:
parent
508404ba9e
commit
dfc7b64e76
5 changed files with 33 additions and 9 deletions
|
|
@ -15,3 +15,5 @@ REDIS_CONNECTION=local
|
||||||
REDIS_HOST=127.0.0.1
|
REDIS_HOST=127.0.0.1
|
||||||
REDIS_PORT=6379
|
REDIS_PORT=6379
|
||||||
REDIS_PASSWORD=
|
REDIS_PASSWORD=
|
||||||
|
|
||||||
|
RIOT_API_KEY=
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,33 @@
|
||||||
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
import Summoner from 'App/Models/Summoner'
|
||||||
|
import SummonerService from 'App/Services/SummonerService'
|
||||||
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
|
||||||
|
|
||||||
export default class SummonersController {
|
export default class SummonersController {
|
||||||
public async basic({ request, response }: HttpContextContract) {
|
public async basic({ request, response }: HttpContextContract) {
|
||||||
const { summoner, region } = await request.validate(SummonerBasicValidator)
|
const { summoner, region } = await request.validate(SummonerBasicValidator)
|
||||||
return response.json('BASIC REQUEST from ' + summoner + ' - ' + region)
|
const finalJSON: any = {}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const account = await SummonerService.getAccount(summoner, region)
|
||||||
|
// Check if the summoner is found
|
||||||
|
if (!account) {
|
||||||
|
return response.json(null)
|
||||||
|
}
|
||||||
|
account.region = region
|
||||||
|
finalJSON.account = account
|
||||||
|
|
||||||
|
// Summoner in DB
|
||||||
|
const summonerDB = await Summoner.firstOrCreate({ puuid: account.puuid })
|
||||||
|
|
||||||
|
// Summoner names
|
||||||
|
finalJSON.account.names = await SummonerService.getAllSummonerNames(account, summonerDB)
|
||||||
|
} catch (e) {
|
||||||
|
console.log(e)
|
||||||
|
return response.json(null)
|
||||||
|
}
|
||||||
|
|
||||||
|
return response.json(finalJSON)
|
||||||
}
|
}
|
||||||
|
|
||||||
public async overview({ response }: HttpContextContract) {
|
public async overview({ response }: HttpContextContract) {
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,7 @@ export interface JaxConfigRequestOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
export const JAX_CONFIG: JaxConfig = {
|
export const JAX_CONFIG: JaxConfig = {
|
||||||
key: Env.get('API_KEY') as string,
|
key: Env.get('RIOT_API_KEY') as string,
|
||||||
region: 'euw1',
|
region: 'euw1',
|
||||||
requestOptions: {
|
requestOptions: {
|
||||||
retriesBeforeAbort: 3,
|
retriesBeforeAbort: 3,
|
||||||
|
|
|
||||||
|
|
@ -59,13 +59,10 @@ class SummonerService {
|
||||||
* @param summonerDB summoner in the database
|
* @param summonerDB summoner in the database
|
||||||
*/
|
*/
|
||||||
public async getAllSummonerNames(account: SummonerDTO, summonerDB: Summoner) {
|
public async getAllSummonerNames(account: SummonerDTO, summonerDB: Summoner) {
|
||||||
if (!summonerDB.names.find((n) => n.name === account.name)) {
|
await summonerDB.related('names').firstOrCreate({
|
||||||
await summonerDB.related('names').create({
|
name: account.name,
|
||||||
name: account.name,
|
})
|
||||||
})
|
return summonerDB.related('names').query().select('name', 'created_at')
|
||||||
}
|
|
||||||
|
|
||||||
return summonerDB.names
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -33,4 +33,6 @@ export default Env.rules({
|
||||||
REDIS_HOST: Env.schema.string({ format: 'host' }),
|
REDIS_HOST: Env.schema.string({ format: 'host' }),
|
||||||
REDIS_PORT: Env.schema.number(),
|
REDIS_PORT: Env.schema.number(),
|
||||||
REDIS_PASSWORD: Env.schema.string.optional(),
|
REDIS_PASSWORD: Env.schema.string.optional(),
|
||||||
|
|
||||||
|
RIOT_API_KEY: Env.schema.string(),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue