mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
working
This commit is contained in:
49
app/Controllers/Http/StatesController.ts
Normal file
49
app/Controllers/Http/StatesController.ts
Normal file
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
32
app/Controllers/Http/StatsController.ts
Normal file
32
app/Controllers/Http/StatsController.ts
Normal file
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
13
app/Models/DockerBuild.ts
Normal file
13
app/Models/DockerBuild.ts
Normal file
@@ -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
|
||||
}
|
||||
13
app/Models/DockerCommand.ts
Normal file
13
app/Models/DockerCommand.ts
Normal file
@@ -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
|
||||
}
|
||||
16
app/Models/Location.ts
Normal file
16
app/Models/Location.ts
Normal file
@@ -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
|
||||
}
|
||||
34
app/Models/Song.ts
Normal file
34
app/Models/Song.ts
Normal file
@@ -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
|
||||
}
|
||||
17
app/Validators/state/StateValidator.ts
Normal file
17
app/Validators/state/StateValidator.ts
Normal file
@@ -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 = {}
|
||||
}
|
||||
0
app/tasks/GetDevelopmentHours.ts
Normal file
0
app/tasks/GetDevelopmentHours.ts
Normal file
0
app/tasks/LogDeezerHistory.ts
Normal file
0
app/tasks/LogDeezerHistory.ts
Normal file
0
app/tasks/UpdateGithubReadme.ts
Normal file
0
app/tasks/UpdateGithubReadme.ts
Normal file
@@ -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')
|
||||
|
||||
Reference in New Issue
Block a user