mirror of
https://github.com/ArthurDanjou/artdanj-api.git
synced 2026-02-01 20:37:49 +01:00
Rename profile to information
This commit is contained in:
23
app/Controllers/Http/InformationsController.ts
Normal file
23
app/Controllers/Http/InformationsController.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
||||||
|
import Information from "App/Models/Information";
|
||||||
|
import InformationUpdateValidator from "App/Validators/information/InformationUpdateValidator";
|
||||||
|
|
||||||
|
export default class InformationsController {
|
||||||
|
|
||||||
|
public async index ( { response }: HttpContextContract ) {
|
||||||
|
return response.status(200).send({
|
||||||
|
informations: await Information.first()
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
public async update ( { response, request }: HttpContextContract ) {
|
||||||
|
const information = await Information.firstOrFail()
|
||||||
|
const data = await request.validate(InformationUpdateValidator)
|
||||||
|
await information.merge(data).save()
|
||||||
|
|
||||||
|
return response.status(200).send({
|
||||||
|
information
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import {HttpContextContract} from "@ioc:Adonis/Core/HttpContext";
|
|
||||||
import Profile from "App/Models/Profile";
|
|
||||||
import ProfileUpdateValidator from "App/Validators/profile/ProfileUpdateValidator";
|
|
||||||
|
|
||||||
export default class ProfilesController {
|
|
||||||
|
|
||||||
public async index ( { response }: HttpContextContract ) {
|
|
||||||
return response.status(200).send({
|
|
||||||
profile: await Profile.first()
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
public async update ( { response, request }: HttpContextContract ) {
|
|
||||||
const profile = await Profile.firstOrFail()
|
|
||||||
const data = await request.validate(ProfileUpdateValidator)
|
|
||||||
await profile.merge(data).save()
|
|
||||||
|
|
||||||
return response.status(200).send({
|
|
||||||
profile
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,15 +1,19 @@
|
|||||||
import {DateTime} from 'luxon'
|
import {DateTime} from 'luxon'
|
||||||
import {BaseModel, column} from '@ioc:Adonis/Lucid/Orm'
|
import {BaseModel, BelongsTo, belongsTo, column} from '@ioc:Adonis/Lucid/Orm'
|
||||||
|
import Translation from "App/Models/Translation";
|
||||||
|
|
||||||
export default class Profile extends BaseModel {
|
export default class Information extends BaseModel {
|
||||||
@column({ isPrimary: true })
|
@column({ isPrimary: true })
|
||||||
public id: number
|
public id: number
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public age: number
|
public age: number
|
||||||
|
|
||||||
|
@belongsTo(() => Translation)
|
||||||
|
public translation: BelongsTo<typeof Translation>
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public hiringStatus: string
|
public translationId: number
|
||||||
|
|
||||||
@column()
|
@column()
|
||||||
public hiringColor: string
|
public hiringColor: string
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
import {schema} from '@ioc:Adonis/Core/Validator'
|
import {schema} from '@ioc:Adonis/Core/Validator'
|
||||||
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
import {HttpContextContract} from '@ioc:Adonis/Core/HttpContext'
|
||||||
|
|
||||||
export default class ProfileUpdateValidator {
|
export default class InformationUpdateValidator {
|
||||||
public schema = schema.create({
|
public schema = schema.create({
|
||||||
age: schema.number.optional(),
|
age: schema.number.optional(),
|
||||||
hiring_status: schema.string.optional(),
|
hiring_status: schema.string.optional(),
|
||||||
@@ -1,14 +1,18 @@
|
|||||||
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
import BaseSchema from '@ioc:Adonis/Lucid/Schema'
|
||||||
|
|
||||||
export default class Profiles extends BaseSchema {
|
export default class Informations extends BaseSchema {
|
||||||
protected tableName = 'profiles'
|
protected tableName = 'informations'
|
||||||
|
|
||||||
public async up () {
|
public async up () {
|
||||||
this.schema.createTable(this.tableName, (table) => {
|
this.schema.createTable(this.tableName, (table) => {
|
||||||
table.increments('id')
|
table.increments('id')
|
||||||
table.integer('age').notNullable()
|
table.integer('age').notNullable()
|
||||||
table.string('hiring_color').notNullable()
|
table.string('hiring_color').notNullable()
|
||||||
table.string('hiring_status').notNullable()
|
table
|
||||||
|
.integer('translation_id')
|
||||||
|
.unsigned()
|
||||||
|
.references('translations.id')
|
||||||
|
.onDelete('CASCADE')
|
||||||
table.timestamps(true, true)
|
table.timestamps(true, true)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -9,7 +9,7 @@ Route.group(() => {
|
|||||||
|
|
||||||
Route.resource('/projects', 'ProjectsController').except(['edit', 'create'])
|
Route.resource('/projects', 'ProjectsController').except(['edit', 'create'])
|
||||||
|
|
||||||
Route.resource('/profile', 'ProfilesController').only(['index', 'update'])
|
Route.resource('/informations', 'InformationsController').only(['index', 'update'])
|
||||||
|
|
||||||
Route.group(() => {
|
Route.group(() => {
|
||||||
Route.get('/:slug', 'PostsController.getLikes')
|
Route.get('/:slug', 'PostsController.getLikes')
|
||||||
|
|||||||
Reference in New Issue
Block a user