diff --git a/migrations/20230219070939-create-guestbook.js b/migrations/20230219070939-create-guestbook.js index 369d2f4..7a99296 100644 --- a/migrations/20230219070939-create-guestbook.js +++ b/migrations/20230219070939-create-guestbook.js @@ -37,6 +37,8 @@ module.exports = { }); }, async down(queryInterface, Sequelize) { - await queryInterface.dropTable('Guestbooks'); + if (await queryInterface.tableExists('guestbook')) { + await queryInterface.dropTable('guestbook'); + } } }; \ No newline at end of file diff --git a/migrations/20230222114001-create-articles.js b/migrations/20230222114001-create-articles.js new file mode 100644 index 0000000..157161f --- /dev/null +++ b/migrations/20230222114001-create-articles.js @@ -0,0 +1,47 @@ +'use strict'; + +/** @type {import('sequelize-cli').Migration} */ +module.exports = { + /** @param {import('sequelize').QueryInterface} queryInterface */ + async up (queryInterface, DataTypes) { + queryInterface.createTable('articles', { + id: { + type: DataTypes.BIGINT(11), + primaryKey: true, + autoIncrement: true, + allowNull: false + }, + title: { + type: DataTypes.TEXT, + allowNull: false + }, + shortText: { + type: DataTypes.TEXT, + allowNull: false + }, + body: { + type: DataTypes.TEXT, + allowNull: false + }, + submitted: { + type: DataTypes.BIGINT, + allowNull: false + }, + edited: { + type: DataTypes.BIGINT, + allowNull: false + }, + submitter: { + type: DataTypes.BIGINT, + allowNull: false + } + }); + }, + + /** @param {import('sequelize').QueryInterface} queryInterface */ + async down (queryInterface, DataTypes) { + if (await queryInterface.tableExists('articles')) { + await queryInterface.dropTable('articles'); + } + } +}; diff --git a/routes/articles.js b/routes/articles.js new file mode 100644 index 0000000..47554d7 --- /dev/null +++ b/routes/articles.js @@ -0,0 +1,17 @@ +const handler = require('express-async-handler'); +const Helpers = require('../helpers'); +const Sequelize = require('../models'); + +async function articles(req, res) { + + const articles = await Sequelize.Article.findAll(); + + res.send(await Helpers.ViewLoader.load('articles/articles.pug', { + current_route: res.originalUrl, + articles + })); +} + +module.exports = (router) => { + router.get('/articles', handler(articles)); +} \ No newline at end of file diff --git a/view/articles/articles.pug b/view/articles/articles.pug new file mode 100644 index 0000000..bb17f93 --- /dev/null +++ b/view/articles/articles.pug @@ -0,0 +1,25 @@ +extends ../layout/main.pug +block root + - var title = 'Articles' + +block content + h2 Articles + p. + This is a bunch of articles written by me (like a tech blog of some sort) + if articles + table(style='max-width:600px;min-width:600px;border-collapse:collapse;border:0') + each article of articles + tr + td(style='border:1px solid #c2c4c2;box-shadow:0 2px 2px #c2c4c280;border-radius:8px;padding:4px 24px') + h4(style='margin:8px 0;padding:0') + span(style='font-family:monospace') [##{article.id}] + = article.title + hr + p= article.shortText + p + a(href='/article/' + article.id) Open full article + tr + td + div(style='min-height:12px;max-height:12px') + else + p Error while loading articles: data is not present \ No newline at end of file diff --git a/view/layout/main.pug b/view/layout/main.pug index 882ca6e..177b4a1 100644 --- a/view/layout/main.pug +++ b/view/layout/main.pug @@ -5,8 +5,10 @@ block root "Main page": '/', "Projects": "/project", "About me": "/about", - "hr": "hr", - "Guestbook": "/guestbook" + "hr_1": "hr", + "Guestbook": "/guestbook", + "hr_2": "hr", + "Articles": "/articles" } doctype html