mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-29 02:50:27 +01:00
Fix
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
import StateValidator from "App/Validators/state/StateValidator";
|
|
||||||
import Redis from "@ioc:Adonis/Addons/Redis";
|
import Redis from "@ioc:Adonis/Addons/Redis";
|
||||||
import {UpdateGitHubReadme} from "App/tasks/UpdateGithubReadme";
|
import {UpdateGitHubReadme} from "App/tasks/UpdateGithubReadme";
|
||||||
|
|
||||||
@@ -19,27 +18,39 @@ export default class StatesController {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
public async set ({request, response}: HttpContextContract) {
|
public async setSleepingStatus ({request, response}: HttpContextContract) {
|
||||||
const data = await request.validate(StateValidator)
|
const sleeping = await request.input('sleeping')
|
||||||
const { is_developing, is_learning, is_listening_music, is_sleeping } = data
|
await Redis.set('artapi/states/sleeping', this.getState(sleeping))
|
||||||
|
|
||||||
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))
|
|
||||||
}
|
|
||||||
|
|
||||||
await UpdateGitHubReadme()
|
await UpdateGitHubReadme()
|
||||||
|
|
||||||
return response.status(200).send({
|
return response.status(200).send({
|
||||||
message: 'States successfully modified !'
|
message: 'State successfully updated !'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async setDevelopingStatus ({request, response}: HttpContextContract) {
|
||||||
|
const developing = await request.input('developing')
|
||||||
|
await Redis.set('artapi/states/developing', this.getState(developing))
|
||||||
|
await UpdateGitHubReadme()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'State successfully updated !'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async setLearningStatus ({request, response}: HttpContextContract) {
|
||||||
|
const learning = await request.input('learning')
|
||||||
|
await Redis.set('artapi/states/learning', this.getState(learning))
|
||||||
|
await UpdateGitHubReadme()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'State successfully updated !'
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async setListeningStatus ({request, response}: HttpContextContract) {
|
||||||
|
const listening = await request.input('listening')
|
||||||
|
await Redis.set('artapi/states/listening', this.getState(listening))
|
||||||
|
await UpdateGitHubReadme()
|
||||||
|
return response.status(200).send({
|
||||||
|
message: 'State successfully updated !'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,19 +0,0 @@
|
|||||||
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 = {
|
|
||||||
required: 'Le champ {{field}} doit être valide !',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -57,7 +57,10 @@ Route.group(() => {
|
|||||||
Route.resource('posts', 'PostsController').only(['store', 'update', 'destroy'])
|
Route.resource('posts', 'PostsController').only(['store', 'update', 'destroy'])
|
||||||
Route.resource('subscribers', 'SubscribersController').only(['store', 'update', 'destroy'])
|
Route.resource('subscribers', 'SubscribersController').only(['store', 'update', 'destroy'])
|
||||||
Route.resource('files', 'FileController').only(['store', 'destroy'])
|
Route.resource('files', 'FileController').only(['store', 'destroy'])
|
||||||
Route.post('/states', 'StatesController.set')
|
Route.post('/states/sleeping', 'StatesController.setSleepingStatus')
|
||||||
|
Route.post('/states/learning', 'StatesController.setLearningStatus')
|
||||||
|
Route.post('/states/developing', 'StatesController.setDevelopingStatus')
|
||||||
|
Route.post('/states/music', 'StatesController.setListeningStatus')
|
||||||
Route.post('/stats/build', 'StatesController.incrementBuild')
|
Route.post('/stats/build', 'StatesController.incrementBuild')
|
||||||
Route.post('/stats/command', 'StatesController.incrementCommand')
|
Route.post('/stats/command', 'StatesController.incrementCommand')
|
||||||
Route.post('/locations', 'LocationsController.add')
|
Route.post('/locations', 'LocationsController.add')
|
||||||
|
|||||||
Reference in New Issue
Block a user