From a6423523b87dc5be1da1700768fd8611435c3f3f Mon Sep 17 00:00:00 2001 From: DarkBrines Date: Sat, 30 Mar 2024 15:52:04 +0100 Subject: [PATCH] Added rank in press articles --- app/Controllers/Http/PressController.ts | 2 +- app/Models/PressArticle.ts | 3 +++ .../1711809658053_add_rank_to_press_articles.ts | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 database/migrations/1711809658053_add_rank_to_press_articles.ts diff --git a/app/Controllers/Http/PressController.ts b/app/Controllers/Http/PressController.ts index 3f5b549..d5dc4ec 100644 --- a/app/Controllers/Http/PressController.ts +++ b/app/Controllers/Http/PressController.ts @@ -3,7 +3,7 @@ import PressArticle from "App/Models/PressArticle" export default class PressController { public async index({ view }: HttpContextContract) { - const pressArticles = await PressArticle.query().exec() + const pressArticles = await PressArticle.query().orderBy("rank", "desc").exec() return view.render('press/index', { pressArticles: pressArticles diff --git a/app/Models/PressArticle.ts b/app/Models/PressArticle.ts index 3580236..f7c430c 100644 --- a/app/Models/PressArticle.ts +++ b/app/Models/PressArticle.ts @@ -5,6 +5,9 @@ export default class PressArticle extends BaseModel { @column({ isPrimary: true }) public id: number + @column() + public rank: number + @column() public title: string diff --git a/database/migrations/1711809658053_add_rank_to_press_articles.ts b/database/migrations/1711809658053_add_rank_to_press_articles.ts new file mode 100644 index 0000000..110c7d8 --- /dev/null +++ b/database/migrations/1711809658053_add_rank_to_press_articles.ts @@ -0,0 +1,15 @@ +import BaseSchema from '@ioc:Adonis/Lucid/Schema' + +export default class extends BaseSchema { + protected tableName = 'press_articles' + + public async up() { + this.schema.alterTable(this.tableName, (table) => { + table.integer('rank') + }) + } + + public async down() { + this.schema.dropTable(this.tableName) + } +}