mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-01-14 20:19:26 +01:00
Add PostColor and content
This commit is contained in:
46
app/Controllers/Http/PostColorsController.ts
Normal file
46
app/Controllers/Http/PostColorsController.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import {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({
|
||||
users: 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({
|
||||
postColor
|
||||
})
|
||||
}
|
||||
|
||||
public async show ({ params, response }: HttpContextContract) {
|
||||
const postColor = await PostColor.findOrFail(params.id)
|
||||
return response.status(200).send({
|
||||
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({
|
||||
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!'
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user