mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 12:14:33 +01:00
Working on new version of website
Signed-off-by: Arthur DANJOU <arthurdanjou@outlook.fr>
This commit is contained in:
45
app/Controllers/Http/TranslationsController.ts
Normal file
45
app/Controllers/Http/TranslationsController.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {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: Translation.query()
|
||||
})
|
||||
}
|
||||
|
||||
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