mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-19 14:31:36 +01:00
Removing website data and add sport state
This commit is contained in:
@@ -1,37 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Announce from 'App/Models/Announce'
|
||||
import AnnounceUpdateValidator from 'App/Validators/announce/AnnounceUpdateValidator'
|
||||
import File from 'App/Models/File'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class AnnouncesController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const announce = await Announce
|
||||
.query()
|
||||
.orderBy('created_at', 'desc')
|
||||
.preload('message')
|
||||
.preload('cover')
|
||||
.first()
|
||||
return response.status(200).send({
|
||||
announce,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(AnnounceUpdateValidator)
|
||||
const announce = await Announce.findOrFail(params.id)
|
||||
|
||||
if (data.code)
|
||||
await announce.related('message').associate(await getTranslation(data.code))
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover)
|
||||
await announce.related('cover').associate(cover)
|
||||
|
||||
await announce.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
announce,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Experience from 'App/Models/Experience'
|
||||
import ExperienceStoreValidator from 'App/Validators/experience/ExperienceStoreValidator'
|
||||
import ExperienceUpdateValidator from 'App/Validators/experience/ExperienceUpdateValidator'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class ExperiencesController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const experiences = await Experience
|
||||
.query()
|
||||
.orderBy('begin_date', 'desc')
|
||||
.preload('title')
|
||||
return response.status(200).send({
|
||||
experiences,
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(ExperienceStoreValidator)
|
||||
const experience = await Experience.create(data)
|
||||
await experience.related('title').associate(await getTranslation(data.title))
|
||||
|
||||
return response.status(200).send({
|
||||
experience,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const experience = await Experience.findOrFail(params.id)
|
||||
experience.load('title')
|
||||
return response.status(200).send({
|
||||
experience,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(ExperienceUpdateValidator)
|
||||
const experience = await Experience.findOrFail(params.id)
|
||||
|
||||
if (data.title)
|
||||
await experience.related('title').associate(await getTranslation(data.title))
|
||||
|
||||
await experience.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
experience,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const experience = await Experience.findOrFail(params.id)
|
||||
await experience.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Experience successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,64 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormationStoreValidator from 'App/Validators/formation/FormationStoreValidator'
|
||||
import FormationUpdateValidator from 'App/Validators/formation/FormationUpdateValidator'
|
||||
import Formation from 'App/Models/Formation'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class FormationsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const formations = await Formation
|
||||
.query()
|
||||
.orderBy('begin_date', 'desc')
|
||||
.preload('title')
|
||||
.preload('description')
|
||||
return response.status(200).send({
|
||||
formations,
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormationStoreValidator)
|
||||
const formation = await Formation.create(data)
|
||||
|
||||
await formation.related('title').associate(await getTranslation(data.title))
|
||||
await formation.related('description').associate(await getTranslation(data.description))
|
||||
|
||||
return response.status(200).send({
|
||||
formation,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const formation = await Formation.findOrFail(params.id)
|
||||
formation.load('title')
|
||||
formation.load('description')
|
||||
return response.status(200).send({
|
||||
formation,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormationUpdateValidator)
|
||||
const formation = await Formation.findOrFail(params.id)
|
||||
|
||||
if (data.title)
|
||||
await formation.related('title').associate(await getTranslation(data.title))
|
||||
|
||||
if (data.description)
|
||||
await formation.related('description').associate(await getTranslation(data.description))
|
||||
|
||||
await formation.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
formation,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const formation = await Formation.findOrFail(params.id)
|
||||
await formation.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Formation successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormStoreValidator from 'App/Validators/form/FormStoreValidator'
|
||||
import Form from 'App/Models/Form'
|
||||
|
||||
export default class FormsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
forms: Form.query().orderBy('created_at', 'asc'),
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormStoreValidator)
|
||||
// todo send confirmation email + email to me with FormConfirmation
|
||||
return response.status(200).send({
|
||||
form: await Form.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
form: await Form.findOrFail(params.id),
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const form = await Form.findOrFail(params.id)
|
||||
await form.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Form successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Information from 'App/Models/Information'
|
||||
import InformationUpdateValidator from 'App/Validators/information/InformationUpdateValidator'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class InformationsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
informations: await Information
|
||||
.query()
|
||||
.preload('translation')
|
||||
.first(),
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ response, request }: HttpContextContract) {
|
||||
const information = await Information.firstOrFail()
|
||||
const data = await request.validate(InformationUpdateValidator)
|
||||
|
||||
if (data.code) {
|
||||
const translation = await getTranslation(data.code)
|
||||
await information.related('translation').associate(translation)
|
||||
}
|
||||
|
||||
await information.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
information,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Location from 'App/Models/Location'
|
||||
import LocationValidator from 'App/Validators/location/LocationValidator'
|
||||
|
||||
export default class LocationsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const location = await Location.query().orderBy('since', 'desc').first()
|
||||
if (location) {
|
||||
return response.status(200).send({
|
||||
location: {
|
||||
place: location.place,
|
||||
left: location.left,
|
||||
since: location.since,
|
||||
},
|
||||
})
|
||||
}
|
||||
else {
|
||||
return response.status(200).send({
|
||||
location: 'Location is unknown...',
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(LocationValidator)
|
||||
const location = await Location.create(data)
|
||||
return response.status(200).send({
|
||||
location,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,31 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Maintenance from 'App/Models/Maintenance'
|
||||
import MaintenanceUpdateValidator from 'App/Validators/maintenance/MaintenanceUpdateValidator'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class MaintenancesController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const maintenance = await Maintenance
|
||||
.query()
|
||||
.orderBy('created_at', 'desc')
|
||||
.preload('reason')
|
||||
.first()
|
||||
return response.status(200).send({
|
||||
maintenance,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(MaintenanceUpdateValidator)
|
||||
const maintenance = await Maintenance.findOrFail(params.id)
|
||||
|
||||
if (data.reason)
|
||||
await maintenance.related('reason').associate(await getTranslation(data.reason))
|
||||
|
||||
await maintenance.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
maintenance,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import PostColor from 'App/Models/PostColor'
|
||||
import PostColorStoreValidator from 'App/Validators/postColor/PostColorStoreValidator'
|
||||
import PostColorUpdateValidator from 'App/Validators/postColor/PostColorUpdateValidator'
|
||||
|
||||
export default class PostColorsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
post_colors: await PostColor.all(),
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(PostColorStoreValidator)
|
||||
const postColor = await PostColor.create(data)
|
||||
return response.status(200).send({
|
||||
post_color: postColor,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
return response.status(200).send({
|
||||
post_color: postColor,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(PostColorUpdateValidator)
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
await postColor.merge(data).save()
|
||||
return response.status(200).send({
|
||||
post_color: postColor,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
await postColor.delete()
|
||||
return response.status(200).send({
|
||||
message: 'PostColor successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
import Post from 'App/Models/Post'
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import PostUpdateValidator from 'App/Validators/post/PostUpdateValidator'
|
||||
import File from 'App/Models/File'
|
||||
import PostStoreValidator from 'App/Validators/post/PostStoreValidator'
|
||||
import PostColor from 'App/Models/PostColor'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class PostsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
posts: await Post.query()
|
||||
.orderBy('id', 'desc')
|
||||
.preload('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
})
|
||||
.preload('cover')
|
||||
.preload('color')
|
||||
.preload('content')
|
||||
.preload('title')
|
||||
.preload('description'),
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(PostStoreValidator)
|
||||
const post = await Post.create(data)
|
||||
|
||||
const cover = await File.findByOrFail('label', data.cover)
|
||||
const color = await PostColor.findByOrFail('name', data.color)
|
||||
|
||||
await post.related('cover').associate(cover)
|
||||
await post.related('color').associate(color)
|
||||
|
||||
await post.related('description').associate(await getTranslation(data.description))
|
||||
await post.related('title').associate(await getTranslation(data.title))
|
||||
await post.related('content').associate(await getTranslation(data.content))
|
||||
|
||||
await post.related('tags').sync(data.tags!)
|
||||
|
||||
return response.status(200).send({
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const post = await Post.findOrFail(params.id)
|
||||
await post.load('cover')
|
||||
await post.load('title')
|
||||
await post.load('description')
|
||||
await post.load('content')
|
||||
await post.load('color')
|
||||
await post.load('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
})
|
||||
return response.status(200).send({
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async get({ params, response }: HttpContextContract) {
|
||||
const post = await Post.firstOrCreate({
|
||||
slug: params.slug,
|
||||
}, {
|
||||
slug: params.slug,
|
||||
likes: 0,
|
||||
})
|
||||
await post.load('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
})
|
||||
await post.load('cover')
|
||||
await post.load('description')
|
||||
await post.load('title')
|
||||
await post.load('content')
|
||||
await post.load('color')
|
||||
return response.status(200).send({
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const post = await Post.findOrFail(params.id)
|
||||
const data = await request.validate(PostUpdateValidator)
|
||||
|
||||
await post.merge(data).save()
|
||||
|
||||
await post.related('tags').sync(data.tags!)
|
||||
await post.related('description').associate(await getTranslation(data.description!))
|
||||
await post.related('title').associate(await getTranslation(data.title!))
|
||||
await post.related('content').associate(await getTranslation(data.content!))
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover)
|
||||
await post.related('cover').associate(cover)
|
||||
|
||||
const color = await PostColor.findBy('name', data.color)
|
||||
if (color)
|
||||
await post.related('color').associate(color)
|
||||
|
||||
return response.status(200).send({
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const post = await Post.findOrFail(params.id)
|
||||
await post.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Post successfully deleted!',
|
||||
})
|
||||
}
|
||||
|
||||
public async like({ params, response }: HttpContextContract) {
|
||||
const post = await Post.firstOrCreate({
|
||||
slug: params.slug,
|
||||
}, {
|
||||
slug: params.slug,
|
||||
likes: 0,
|
||||
})
|
||||
const getLikes = post.likes
|
||||
await post.merge({
|
||||
likes: getLikes + 1,
|
||||
}).save()
|
||||
return response.status(200).send({
|
||||
post,
|
||||
})
|
||||
}
|
||||
|
||||
public async unlike({ params, response }: HttpContextContract) {
|
||||
const post = await Post.findByOrFail('slug', params.slug)
|
||||
const getLikes = post.likes
|
||||
await post.merge({
|
||||
likes: getLikes - 1,
|
||||
}).save()
|
||||
return response.status(200).send({
|
||||
post,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ export default class ProfileController {
|
||||
},
|
||||
databases: ['MongoDB', 'MariaDB', 'Redis'],
|
||||
messaging: ['RabbitMQ'],
|
||||
other: ['Docker', 'Git'],
|
||||
other: ['Docker', 'Git', 'Kubernetes'],
|
||||
operating_systems: ['MacOS', 'Linux'],
|
||||
},
|
||||
})
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Project from 'App/Models/Project'
|
||||
import ProjectStoreValidator from 'App/Validators/project/ProjectStoreValidator'
|
||||
import ProjectUpdateValidator from 'App/Validators/project/ProjectUpdateValidator'
|
||||
import File from 'App/Models/File'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class ProjectsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
projects: await Project.query()
|
||||
.orderBy('id', 'asc')
|
||||
.preload('cover')
|
||||
.preload('description')
|
||||
.preload('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
}),
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(ProjectStoreValidator)
|
||||
const project = await Project.create(data)
|
||||
const cover = await File.findByOrFail('label', data.cover)
|
||||
|
||||
await project.related('cover').associate(cover)
|
||||
await project.related('description').associate(await getTranslation(data.description))
|
||||
await project.related('tags').sync(data.tags!)
|
||||
return response.status(200).send({
|
||||
project,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
await project.load('cover')
|
||||
await project.load('description')
|
||||
await project.load('tags', (tags) => {
|
||||
tags.preload('label')
|
||||
})
|
||||
return response.status(200).send({
|
||||
project,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
const data = await request.validate(ProjectUpdateValidator)
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
|
||||
await project.merge(data).save()
|
||||
if (cover)
|
||||
await project.related('cover').associate(cover)
|
||||
|
||||
if (data.description)
|
||||
await project.related('description').associate(await getTranslation(data.description))
|
||||
|
||||
await project.related('tags').sync(data.tags!)
|
||||
return response.status(200).send({
|
||||
project,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const project = await Project.findOrFail(params.id)
|
||||
await project.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Project successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,59 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import File from 'App/Models/File'
|
||||
import Skill from 'App/Models/Skill'
|
||||
import SkillStoreValidator from 'App/Validators/skill/SkillStoreValidator'
|
||||
import SkillUpdateValidator from 'App/Validators/skill/SkillUpdateValidator'
|
||||
|
||||
export default class SkillsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const skills = await Skill
|
||||
.query()
|
||||
.preload('file')
|
||||
return response.status(200).send({
|
||||
skills,
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(SkillStoreValidator)
|
||||
const skill = await Skill.create(data)
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover)
|
||||
await skill.related('file').associate(cover)
|
||||
|
||||
return response.status(200).send({
|
||||
skill,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const skill = await Skill.findOrFail(params.id)
|
||||
skill.load('file')
|
||||
return response.status(200).send({
|
||||
skill,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(SkillUpdateValidator)
|
||||
const skill = await Skill.findOrFail(params.id)
|
||||
|
||||
const cover = await File.findBy('label', data.cover)
|
||||
if (cover)
|
||||
await skill.related('file').associate(cover)
|
||||
await skill.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
skill,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const skill = await Skill.findOrFail(params.id)
|
||||
await skill.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Skill successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -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'
|
||||
}
|
||||
|
||||
@@ -1,28 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Subscriber from 'App/Models/Subscriber'
|
||||
import SubscriberStoreValidator from 'App/Validators/subscriber/SubscriberStoreValidator'
|
||||
|
||||
export default class SubscribersController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const subscribers = await Subscriber.query()
|
||||
return response.status(200).send({
|
||||
count: subscribers.length,
|
||||
subscribers,
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(SubscriberStoreValidator)
|
||||
return response.status(200).send({
|
||||
subscriber: await Subscriber.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ params, response }: HttpContextContract) {
|
||||
const subscriber = await Subscriber.findOrFail(params.id)
|
||||
await subscriber.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Subscriber successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,55 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import TagStoreValidator from 'App/Validators/tag/TagStoreValidator'
|
||||
import TagUpdateValidator from 'App/Validators/tag/TagUpdateValidator'
|
||||
import Tag from 'App/Models/Tag'
|
||||
import { getTranslation } from 'App/Utils/TranslationsUtils'
|
||||
|
||||
export default class TagsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
const tags = await Tag
|
||||
.query()
|
||||
.preload('label')
|
||||
return response.status(200).send({
|
||||
tags,
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(TagStoreValidator)
|
||||
const tag = await Tag.create({})
|
||||
|
||||
await tag.related('label').associate(await getTranslation(data.label))
|
||||
|
||||
return response.status(200).send({
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
const tag = await Tag.findOrFail(params.id)
|
||||
tag.load('label')
|
||||
return response.status(200).send({
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const data = await request.validate(TagUpdateValidator)
|
||||
const tag = await Tag.findOrFail(params.id)
|
||||
|
||||
if (data.label)
|
||||
await tag.related('label').associate(await getTranslation(data.label))
|
||||
|
||||
return response.status(200).send({
|
||||
tag,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const tag = await Tag.findOrFail(params.id)
|
||||
await tag.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Tag successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
import type { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
|
||||
import Translation from 'App/Models/Translation'
|
||||
import TranslationStoreValidator from 'App/Validators/translation/TranslationStoreValidator'
|
||||
import TranslationUpdateValidator from 'App/Validators/translation/TranslationUpdateValidator'
|
||||
|
||||
export default class TranslationsController {
|
||||
public async index({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
translations: await Translation.query().orderBy('id', 'asc'),
|
||||
})
|
||||
}
|
||||
|
||||
public async store({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(TranslationStoreValidator)
|
||||
return response.status(200).send({
|
||||
translation: await Translation.create(data),
|
||||
})
|
||||
}
|
||||
|
||||
public async show({ params, response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
translation: await Translation.findOrFail(params.id),
|
||||
})
|
||||
}
|
||||
|
||||
public async update({ request, params, response }: HttpContextContract) {
|
||||
const translation = await Translation.findOrFail(params.id)
|
||||
const data = await request.validate(TranslationUpdateValidator)
|
||||
await translation.merge(data).save()
|
||||
|
||||
return response.status(200).send({
|
||||
translation,
|
||||
})
|
||||
}
|
||||
|
||||
public async destroy({ response, params }: HttpContextContract) {
|
||||
const translation = await Translation.findOrFail(params.id)
|
||||
await translation.delete()
|
||||
return response.status(200).send({
|
||||
message: 'Translation successfully deleted!',
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user