diff --git a/app/Controllers/Http/StatesController.ts b/app/Controllers/Http/StatesController.ts new file mode 100644 index 0000000..eb4372d --- /dev/null +++ b/app/Controllers/Http/StatesController.ts @@ -0,0 +1,49 @@ +import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext"; +import StateValidator from "App/Validators/state/StateValidator"; +import Redis from "@ioc:Adonis/Addons/Redis"; + +export default class StatesController { + + public async get ({response}: HttpContextContract) { + const is_sleeping = Boolean(await Redis.get('artapi/state/sleeping')) || false + const is_learning = Boolean(await Redis.get('artapi/state/learning')) || false + const is_developing = Boolean(await Redis.get('artapi/state/developing')) || false + const is_listening_music = Boolean(await Redis.get('artapi/state/listening')) || false + + return response.status(200).send({ + is_sleeping, + is_learning, + is_developing, + is_listening_music + }) + } + + public async set ({request, response}: HttpContextContract) { + const data = await request.validate(StateValidator) + const { is_developing, is_learning, is_listening_music, is_sleeping } = data + + if (is_listening_music) { + await Redis.set('artapi/state/listening', this.getState(is_listening_music)) + } + if (is_developing) { + await Redis.set('artapi/state/developing', this.getState(is_developing)) + } + if (is_learning) { + await Redis.set('artapi/state/learning', this.getState(is_learning)) + } + if (is_sleeping) { + await Redis.set('artapi/state/sleeping', this.getState(is_sleeping)) + } + + //Todo updateGitHub + + return response.status(200).send({ + message: 'States successfully modified !' + }) + } + + getState(state: boolean):number { + return state ? 1 : 0 + } + +} diff --git a/app/Controllers/Http/StatsController.ts b/app/Controllers/Http/StatsController.ts new file mode 100644 index 0000000..8c29075 --- /dev/null +++ b/app/Controllers/Http/StatsController.ts @@ -0,0 +1,32 @@ +import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' + +export default class StatsController { + + public async get ({response}: HttpContextContract) { + return response.status(200).send({ + daily: this.getDailyStats(), + weekly: this.getWeeklyStats(), + monthly: this.getMontlyStats() + }) + } + + getDailyStats() { + return { + development_hours: 0 + } + } + + getWeeklyStats() { + return { + development_hours: 0 + } + } + + getMontlyStats() { + + return { + development_hours: 0 + } + } + +} diff --git a/app/Models/DockerBuild.ts b/app/Models/DockerBuild.ts new file mode 100644 index 0000000..a8dae4b --- /dev/null +++ b/app/Models/DockerBuild.ts @@ -0,0 +1,13 @@ +import { DateTime } from 'luxon' +import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm' + +export default class DockerBuild extends BaseModel { + @column({ isPrimary: true }) + public id: number + + @column() + public build: bigint + + @column.dateTime({ autoCreate: true }) + public createdAt: DateTime +} diff --git a/app/Models/DockerCommand.ts b/app/Models/DockerCommand.ts new file mode 100644 index 0000000..80f112c --- /dev/null +++ b/app/Models/DockerCommand.ts @@ -0,0 +1,13 @@ +import { DateTime } from 'luxon' +import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm' + +export default class DockerCommand extends BaseModel { + @column({ isPrimary: true }) + public id: number + + @column() + public command: string + + @column.dateTime({ autoCreate: true }) + public createdAt: DateTime +} diff --git a/app/Models/Location.ts b/app/Models/Location.ts new file mode 100644 index 0000000..53ab170 --- /dev/null +++ b/app/Models/Location.ts @@ -0,0 +1,16 @@ +import { DateTime } from 'luxon' +import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm' + +export default class Location extends BaseModel { + @column({ isPrimary: true }) + public id: number + + @column.date({ autoCreate: true }) + public since: DateTime + + @column() + public location: string + + @column() + public left: string +} diff --git a/app/Models/Song.ts b/app/Models/Song.ts new file mode 100644 index 0000000..bb65730 --- /dev/null +++ b/app/Models/Song.ts @@ -0,0 +1,34 @@ +import { DateTime } from 'luxon' +import { BaseModel, column } from '@ioc:Adonis/Lucid/Orm' + +export default class Song extends BaseModel { + @column({ isPrimary: true }) + public id: number + + @column() + public author: string + + @column() + public album: string + + @column() + public title: string + + @column() + public type: string + + @column() + public device: string + + @column() + public duration: number + + @column.date() + public releaseDate: DateTime + + @column.dateTime({ autoCreate: true }) + public createdAt: DateTime + + @column.dateTime({ autoCreate: true, autoUpdate: true }) + public updatedAt: DateTime +} diff --git a/app/Validators/state/StateValidator.ts b/app/Validators/state/StateValidator.ts new file mode 100644 index 0000000..7d81648 --- /dev/null +++ b/app/Validators/state/StateValidator.ts @@ -0,0 +1,17 @@ +import { schema } from '@ioc:Adonis/Core/Validator' +import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext' + +export default class StateValidator { + constructor (protected ctx: HttpContextContract) { + } + + public schema = schema.create({ + is_sleeping: schema.boolean.optional(), + is_learning: schema.boolean.optional(), + is_developing: schema.boolean.optional(), + is_listening_music: schema.boolean.optional(), + }) + + + public messages = {} +} diff --git a/app/tasks/GetDevelopmentHours.ts b/app/tasks/GetDevelopmentHours.ts new file mode 100644 index 0000000..e69de29 diff --git a/app/tasks/LogDeezerHistory.ts b/app/tasks/LogDeezerHistory.ts new file mode 100644 index 0000000..e69de29 diff --git a/app/tasks/UpdateGithubReadme.ts b/app/tasks/UpdateGithubReadme.ts new file mode 100644 index 0000000..e69de29 diff --git a/start/routes.ts b/start/routes.ts index a100305..0131810 100644 --- a/start/routes.ts +++ b/start/routes.ts @@ -10,10 +10,10 @@ Route.get('/', async ({response}: HttpContextContract) => { domain: "api.arthurdanjou.fr", version: "1.0", routes: { - deezer_data: "", - stats_data: "", + deezer_data: `${BASE_URL}/deezer`, + stats_data: `${BASE_URL}/stats`, state_data: `${BASE_URL}/state`, - locations_data: "", + locations_data: `${BASE_URL}/location`, health: `${BASE_URL}/health` } }) @@ -36,6 +36,7 @@ Route.get('/health', async ({ response }) => { const report = await HealthCheck.getReport() return report.healthy ? response.ok(report) : response.badRequest(report) }) +Route.get('/stats', 'StatsController.get') Route.get('/state', 'StatesController.get') Route.resource('users', 'UsersController').only(['index', 'show']) Route.get('/posts/:slug', 'PostsController.getLikes')