var express = require('express');
var bodyParser = require('body-parser');
var app = express();
var api = require('./patient.js');

app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());

app.get('/', (request, response) => {
    console.log("Anfrage erhalten");
    response.send("Hello World");
})

app.get('/patients', (req, res) => {
    res.json(api.readAll());
});

app.get('/patients/:id', (req, res) => {
    var patient = api.read(req.params.id);
    if (patient)
        res.json(patient);
    else
        res.sendStatus(404);
})

app.post('/patients', (req, res) => {

});

app.put('/patients/:id', (req, res) => {
    var count = api.update(req.params.id, req.body);
    res.json({ "count": count });
});

app.delete('/patients/:id', (req, res) => {

});

app.listen(3000, () => {
    console.log("MDT5/2 Server");
})