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:
@@ -1,18 +1,34 @@
|
||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||
import FormValidator from "App/Validators/FormValidator";
|
||||
import FormStoreValidator from "App/Validators/form/FormStoreValidator";
|
||||
import Form from "App/Models/Form";
|
||||
import FormConfirmation from "App/Mailers/FormConfirmation";
|
||||
|
||||
export default class FormsController {
|
||||
|
||||
public async send({ request, response }: HttpContextContract) {
|
||||
const data = await request.validate(FormValidator)
|
||||
await Form.create(data)
|
||||
|
||||
await new FormConfirmation(data.name, data.email).preview()
|
||||
//todo send confirmation email + email to me
|
||||
public async index ({ response }: HttpContextContract) {
|
||||
return response.status(200).send({
|
||||
message: 'Form successfully received !'
|
||||
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!'
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user