feat: add routes and summoner validators

This commit is contained in:
Kalane 2021-09-12 16:35:50 +02:00
parent 63b42f7c86
commit 508404ba9e
4 changed files with 120 additions and 3 deletions

View file

@ -0,0 +1,13 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import SummonerBasicValidator from 'App/Validators/SummonerBasicValidator'
export default class SummonersController {
public async basic({ request, response }: HttpContextContract) {
const { summoner, region } = await request.validate(SummonerBasicValidator)
return response.json('BASIC REQUEST from ' + summoner + ' - ' + region)
}
public async overview({ response }: HttpContextContract) {
return response.json('OVERVIEW REQUEST')
}
}

View file

@ -0,0 +1,43 @@
import { rules, schema } from '@ioc:Adonis/Core/Validator'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class SummonerBasicValidator {
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({
summoner: schema.string({}, [rules.regex(/^[0-9\p{L} _\.]+$/u)]),
region: schema.string(),
})
/**
* 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 = {}
}

View file

@ -0,0 +1,45 @@
import { schema } from '@ioc:Adonis/Core/Validator'
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
export default class SummonerOverviewValidator {
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(),
accountId: schema.string(),
region: 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 = {}
}

View file

@ -21,6 +21,22 @@
import HealthCheck from '@ioc:Adonis/Core/HealthCheck' import HealthCheck from '@ioc:Adonis/Core/HealthCheck'
import Route from '@ioc:Adonis/Core/Route' import Route from '@ioc:Adonis/Core/Route'
Route.get('/', async () => { Route.get('/', async () => ({
return { report: await HealthCheck.getReport() } hi: 'Hello World from LeagueStats V2 API',
}) uptime: process.uptime(),
}))
Route.get('/health', async () => ({ report: await HealthCheck.getReport() }))
Route.post('/summoner/basic', 'SummonersController.basic')
Route.post('/summoner/overview', 'SummonersController.overview')
// Route.post('/summoner/champions', 'SummonersController.champions')
// Route.post('/summoner/records', 'SummonersController.records')
// Route.post('/summoner/live', 'SummonersController.liveMatchDetails')
// Route.post('/match', 'MatchesController.index')
// Route.post('/match/details', 'MatchesController.show')
// Route.post('/match/details/ranks', 'MatchesController.showRanks')
// Route.get('/cdragon/runes', 'CDragonController.runes')