mongo reposityory
This commit is contained in:
parent
4995182651
commit
20ec2747ae
5 changed files with 268 additions and 49 deletions
98
js/index.js
98
js/index.js
|
@ -1,64 +1,70 @@
|
|||
|
||||
const express = require('express')
|
||||
const app = express()
|
||||
const InMemoryWorkshop = require("./inMemoryWorkshop")
|
||||
const path = require("path")
|
||||
const ejs = require('ejs')
|
||||
var bodyParser = require('body-parser')
|
||||
const repository = require('./inMemoryWorkshop');
|
||||
//const repository = require("./mongoWorkshop");
|
||||
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
repository.init().then(() => {
|
||||
|
||||
// set the view engine to ejs
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', path.join(__dirname, '..', '/ejs'));
|
||||
app.use(express.static(path.join(__dirname , '..', 'css')));
|
||||
app.use(bodyParser.urlencoded({ extended: false }))
|
||||
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
InMemoryWorkshop.getWorkshopList()
|
||||
.then(workshops => {
|
||||
res.render("index", {
|
||||
workshops: workshops
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
app.get('/workshop', function (req, res) {
|
||||
console.log("get")
|
||||
res.render('workshop')
|
||||
})
|
||||
|
||||
app.post('/workshop', function (req, res) {
|
||||
const name = req.body.name
|
||||
const description = req.body.description
|
||||
InMemoryWorkshop.addWorkshop(name, description).then(() => {
|
||||
InMemoryWorkshop.getWorkshopList()
|
||||
// set the view engine to ejs
|
||||
app.set('view engine', 'ejs');
|
||||
app.set('views', path.join(__dirname, '..', '/ejs'));
|
||||
app.use(express.static(path.join(__dirname , '..', 'css')));
|
||||
|
||||
|
||||
app.get('/', function (req, res) {
|
||||
repository.getWorkshopList()
|
||||
.then(workshops => {
|
||||
res.render("index", {
|
||||
workshops: workshops
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(e =>res.send(e.message))
|
||||
})
|
||||
|
||||
app.get('/workshop/:name', function (req, res) {
|
||||
const workshopName = req.params.name
|
||||
InMemoryWorkshop.getWorkshopByName(workshopName)
|
||||
.then(workshop => {
|
||||
res.render('ejs/workshop', workshop)
|
||||
|
||||
app.get('/workshop', function (req, res) {
|
||||
console.log("get")
|
||||
res.render('workshop')
|
||||
})
|
||||
.catch(e =>ejs.send(e.message))
|
||||
|
||||
app.post('/workshop', function (req, res) {
|
||||
const name = req.body.name
|
||||
const description = req.body.description
|
||||
repository.addWorkshop(name, description).then(() => {
|
||||
repository.getWorkshopList()
|
||||
.then(workshops => {
|
||||
res.render("index", {
|
||||
workshops: workshops
|
||||
})
|
||||
})
|
||||
})
|
||||
.catch(e =>res.send(e.message))
|
||||
})
|
||||
|
||||
app.get('/workshop/:name', function (req, res) {
|
||||
const workshopName = req.params.name
|
||||
repository.getWorkshopByName(workshopName)
|
||||
.then(workshop => {
|
||||
res.render('ejs/workshop', workshop)
|
||||
})
|
||||
.catch(e =>ejs.send(e.message))
|
||||
})
|
||||
|
||||
app.post('/remove-workshop', function (req, res) {
|
||||
res.status(500).send("TODO")
|
||||
})
|
||||
|
||||
app.post('/update-workshop', function(req, res) {
|
||||
res.status(500).send("TODO")
|
||||
})
|
||||
|
||||
app.listen(3000, function () {
|
||||
console.log('Workshop app listening on port 3000!')
|
||||
})
|
||||
|
||||
})
|
||||
|
||||
app.post('/remove-workshop', function (req, res) {
|
||||
res.status(500).send("TODO")
|
||||
})
|
||||
|
||||
app.post('/update-workshop', function(req, res) {
|
||||
res.status(500).send("TODO")
|
||||
})
|
||||
|
||||
app.listen(3000, function () {
|
||||
console.log('Workshop app listening on port 3000!')
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue