Пример #1
0
$app->post('/participation', function () use($app) {
    $body = json_decode($app->request->getBody());
    $participation = new Participation();
    $participation->setOffer($body->offer);
    $participation->setUser($body->user);
    $participation->setOrder($body->order);
    $participation->save();
});
$app->get('/offer', function () {
    outputJSON(Offer::getAll());
});
$app->get('/offer/:id', function ($id) {
    outputJSON(Offer::getById($id));
});
$app->get('/offer/:id/participation', function ($id) {
    outputJSON(Participation::getByOfferId($id));
});
$app->post('/offer', function () use($app) {
    /**
     * @var $config array
     */
    global $config;
    $body = json_decode($app->request->getBody());
    $offer = new Offer();
    $offer->setUser($body->user);
    $offer->setRestaurant($body->restaurant);
    $offer->setOrderUntil($body->order_until);
    $offer->save();
    // Load user
    $user = User::getById($body->user);
    // Load restaurant