Skip to content
Snippets Groups Projects
Verified Commit e87419ba authored by Thomas SAUVAGE's avatar Thomas SAUVAGE
Browse files

create picture

parent 241b2229
No related branches found
No related tags found
1 merge request!3Validation & tests
Pipeline #13756 passed
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Picture from 'App/Models/Picture'
import { createPictureSchema } from 'App/Schemas/pictures.schema'
/** Get all pictures of an event, with param id */
export const getPictures = async ({ response, params }: HttpContextContract) => {
......@@ -7,3 +8,14 @@ export const getPictures = async ({ response, params }: HttpContextContract) =>
return response.ok(pictures)
}
/**
* Create a picture
* TODO: Really create a picture, not just metadata
*/
export const createPicture = async ({ request, response }: HttpContextContract) => {
const newPicture = await request.validate({ schema: createPictureSchema })
await Picture.create(newPicture)
return response.created({ message: 'Picture created' })
}
import { rules, schema } from '@ioc:Adonis/Core/Validator'
export const createPictureSchema = schema.create({
fileName: schema.string([rules.minLength(1), rules.maxLength(255)]),
author: schema.string([rules.minLength(1), rules.maxLength(255)]),
eventId: schema.number([rules.exists({ table: 'events', column: 'id' })]),
})
......@@ -41,9 +41,10 @@ Route.group(() => {
})
.prefix('/event')
.middleware('auth:api')
/** ==== Pictures ==== */
Route.group(() => {
Route.get('/get/:id', 'PictureController.getPictures')
Route.get('/get/:id', 'PictureController.getPictures').where('id', Route.matchers.number())
})
.prefix('/picture')
.middleware('auth:api')
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment