mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-21 15:31:35 +01:00
Removing website data and add sport state
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Redis from '@ioc:Adonis/Addons/Redis'
|
||||
import StateSleepingValidator from 'App/Validators/states/StateSleepingValidator'
|
||||
import StateValidator from 'App/Validators/states/StateValidator'
|
||||
import { getCurrentPlayingFromCache } from 'App/Utils/SongUtils'
|
||||
|
||||
export default class StatesController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const sleeping = this.formatValue(await Redis.get('states:sleeping'))
|
||||
const developing = this.formatValue(await Redis.get('states:developing'))
|
||||
const sleep = this.formatValue(await Redis.get('states:sleeping'))
|
||||
const develop = this.formatValue(await Redis.get('states:developing'))
|
||||
const sport = this.formatValue(await Redis.get('states:sporting'))
|
||||
return response.status(200).send({
|
||||
sleeping,
|
||||
developing,
|
||||
is_sleeping: sleep,
|
||||
is_developing: develop,
|
||||
is_sporting: sport,
|
||||
listening_music: await getCurrentPlayingFromCache(),
|
||||
})
|
||||
}
|
||||
|
||||
public async setSleeping({ request, response }: HttpContextContract) {
|
||||
const { value } = await request.validate(StateSleepingValidator)
|
||||
public async setSleep({ request, response }: HttpContextContract) {
|
||||
const { value } = await request.validate(StateValidator)
|
||||
await Redis.set('states:sleeping', String(value))
|
||||
await Redis.set('states:developing', String(!value))
|
||||
return response.status(200).send({
|
||||
@@ -24,6 +26,16 @@ export default class StatesController {
|
||||
})
|
||||
}
|
||||
|
||||
public async setSport({ request, response }: HttpContextContract) {
|
||||
const { value } = await request.validate(StateValidator)
|
||||
await Redis.set('states:sporting', String(value))
|
||||
await Redis.set('states:sleeping', String(!value))
|
||||
return response.status(200).send({
|
||||
message: 'State was successfully set!',
|
||||
value: this.formatValue(String(value)),
|
||||
})
|
||||
}
|
||||
|
||||
public formatValue(value: string | null): string {
|
||||
return value === 'true' ? 'Yes' : 'No'
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user