<?php

//GET -> /tweets/
//GET -> /tweets/:id
//POST -> /tweets/
//POST -> /tweets/
//DELETE -> /tweets/:id
//PUT -> /tweets/:id
//GET -> /tweets/tags/:tag => alle tweets met een specifieke hashtag ophalen
$tweetDAO = new TweetDAO();
$app->get('/tweets/?', function () use($tweetDAO) {
    header("Content-Type: application/json");
    echo json_encode($tweetDAO->selectAll(), JSON_NUMERIC_CHECK);
    exit;
});
$app->get('/tweets/:id/?', function ($id) use($tweetDAO) {
    header("Content-Type: application/json");
    echo json_encode($tweetDAO->selectById($id), JSON_NUMERIC_CHECK);
    exit;
});
$app->post('/tweets/?', function () use($app, $tweetDAO) {
    header("Content-Type: application/json");
    $post = $app->request->post();
    if (empty($post)) {
        $post = (array) json_decode($app->request()->getBody());
    }
    echo json_encode($tweetDAO->insert($post), JSON_NUMERIC_CHECK);
    exit;
});
$app->delete('/tweets/:id/?', function ($id) use($tweetDAO) {
    header("Content-Type: application/json");