diff --git a/server-v2/app/Controllers/Http/SummonersController.ts b/server-v2/app/Controllers/Http/SummonersController.ts new file mode 100644 index 0000000..a4252a5 --- /dev/null +++ b/server-v2/app/Controllers/Http/SummonersController.ts @@ -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') + } +} diff --git a/server-v2/app/Validators/SummonerBasicValidator.ts b/server-v2/app/Validators/SummonerBasicValidator.ts new file mode 100644 index 0000000..e8a9fd8 --- /dev/null +++ b/server-v2/app/Validators/SummonerBasicValidator.ts @@ -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 = {} +} diff --git a/server-v2/app/Validators/SummonerOverviewValidator.ts b/server-v2/app/Validators/SummonerOverviewValidator.ts new file mode 100644 index 0000000..3fd6c6b --- /dev/null +++ b/server-v2/app/Validators/SummonerOverviewValidator.ts @@ -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 = {} +} diff --git a/server-v2/start/routes.ts b/server-v2/start/routes.ts index b7b5ced..b257044 100644 --- a/server-v2/start/routes.ts +++ b/server-v2/start/routes.ts @@ -21,6 +21,22 @@ import HealthCheck from '@ioc:Adonis/Core/HealthCheck' import Route from '@ioc:Adonis/Core/Route' -Route.get('/', async () => { - return { report: await HealthCheck.getReport() } -}) +Route.get('/', async () => ({ + 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')