Created
March 1, 2018 09:56
-
-
Save deepal/4be710048d1277fdd9442552be6cf9f3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const express = require('express'); | |
const bodyParser = require('body-parser'); | |
const database = require('../database'); | |
const app = express(); | |
app.use(bodyParser.json()); | |
app.get('/list', function (req, res) { | |
const todos = database.getToDoList(); | |
res.status(200).send(todos); | |
}); | |
app.post('/create', function (req, res) { | |
const todoTitle = req.body.title; | |
database.createToDo(todoTitle); | |
res.status(201).send({ | |
message: `todo created with title: ${todoTitle}` | |
}); | |
}); | |
app.put('/update', function (req, res) { | |
const todoId = req.body.id; | |
const newTodoTitle = req.body.title; | |
const newTodoStatus = req.body.done; | |
database.updateToDo(todoId, { | |
title: newTodoTitle, | |
done: newTodoStatus | |
}); | |
res.status(200).send({ | |
message: `todo with id ${todoId} updated` | |
}); | |
}); | |
app.delete('/delete', function (req, res) { | |
const deletingTodoId = req.query.id; | |
database.deleteTodo(deletingTodoId); | |
res.status(200).send({ | |
message: `todo with id ${deletingTodoId} deleted` | |
}); | |
}); | |
module.exports = app; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment