This commit is contained in:
2020-12-19 21:16:44 +01:00
parent 48fa997811
commit 7478e85bae
11 changed files with 149 additions and 44 deletions

View File

@@ -0,0 +1,31 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Location from "App/Models/Location";
import StoreValidator from "App/Validators/locations/StoreValidator";
export default class LocationsController {
public async get ({ response }: HttpContextContract) {
const location = await Location.query().orderBy('since', 'desc').firstOrFail()
return response.status(200).send({
place: location.place,
left: location.left,
since: location.since
})
}
public async history ({ response }: HttpContextContract) {
const locations = await Location.query().orderBy('since', 'desc')
return response.status(200).send({
locations
})
}
public async set ({ request, response }: HttpContextContract) {
const data = await request.validate(StoreValidator)
await Location.create(data)
return response.status(200).send({
message: 'Location successfully added !'
})
}
}