diff --git a/core/controllers/questionController.js b/core/controllers/questionController.js
deleted file mode 100644
index e571b45..0000000
--- a/core/controllers/questionController.js
+++ /dev/null
@@ -1,12 +0,0 @@
-'use strict'
-
-const Question = require('../models/question')
-
-module.exports = class QuestionController {
-
- static showExample() {
- const question = new Question()
- console.log(question.example())
- return question.example()
- }
-}
diff --git a/core/controllers/userController.js b/core/controllers/userController.js
deleted file mode 100644
index f7d93a1..0000000
--- a/core/controllers/userController.js
+++ /dev/null
@@ -1,13 +0,0 @@
-'use strict'
-
-const User = require('../models/user')
-
-module.exports = class UserController {
- static hello() {
- const user = new User()
- user.setName('Ben')
-
- return `Hello ${user.name}`
- }
-
-}
diff --git a/core/models/question.js b/core/models/question.js
index 71d7e0c..7e8ae83 100644
--- a/core/models/question.js
+++ b/core/models/question.js
@@ -1,7 +1,31 @@
'use strict'
+const Database = require('sqlite-async')
+
+const dbName = 'server.db'
+
module.exports = class Question {
example() {
return 'this is an example'
}
+
+ async getAllQuestions(query) {
+ try {
+ let sql = 'SELECT id, title, question FROM Questions;'
+ console.log(query.search)
+ if(query !== undefined && query.search !== undefined) {
+ sql = `SELECT id, title, question FROM Questions
+ WHERE upper(title) LIKE "%${query.search}%";`
+ }
+ const db = await Database.open(dbName)
+ const data = await db.all(sql)
+ await db.close()
+ console.log(data)
+ return data
+ } catch(err) {
+ return err.message
+ }
+ }
+
+
}
diff --git a/core/routes.js b/core/routes.js
index 57510d1..cf25969 100644
--- a/core/routes.js
+++ b/core/routes.js
@@ -1,8 +1,44 @@
'use strict'
const Router = require('koa-router')
+const Question = require('./models/question')
+
+//temp
+const Database = require('sqlite-async')
+const handlebars = require('koa-hbs-renderer')
+const dbName = 'server.db'
+//
+
const router = new Router()
+const question = new Question()
+/*
router.get('/', async ctx => await ctx.render('home', {title: 'Home'}))
+*/
+
+//temp
+router.get('/', async ctx => {
+ const data = await question.getAllQuestions(ctx.query)
+ console.log(data)
+ await ctx.render('home', {Questions: data,title: 'Home'})
+})
+
+router.post('/insertquestion', async ctx => {
+ try {
+ console.log(ctx.request.body)
+ const body = ctx.request.body
+ const sql = `INSERT INTO Questions(title, question)
+ VALUES("${body.title}", "${body.question}");`
+ console.log(sql)
+ const db = await Database.open(dbName)
+ await db.run(sql)
+ await db.close()
+ ctx.redirect('/')
+ } catch(err) {
+ ctx.body = err.message
+ }
+})
+
+router.get('/createquestion', async ctx => ctx.render('createquestion'))
module.exports = router
diff --git a/core/views/createquestion.hbs b/core/views/createquestion.hbs
new file mode 100644
index 0000000..c00607b
--- /dev/null
+++ b/core/views/createquestion.hbs
@@ -0,0 +1,18 @@
+{{> header}}
+
+CONTENT WILL BE HERE
+
+
+
+ CONTENT WILL BE HERE
+
+ All Questions
+
+