Beispiel #1
0
<?php

$this->respond(['GET', 'POST'], '/create', function ($request, $response, $service, $app) {
    $data = ['content' => $request->param('content', ''), 'investor' => $request->param('investor', ''), 'log' => $request->param('log', '')];
    $id = Notes::createNote($data);
    if ($id > 0) {
        $response->json(Result::success('Note Created.', ['id' => $id]));
    } else {
        $response->json(Result::error('Note Creation Failed.'));
    }
});
$this->respond(['GET', 'POST'], '/get/[i:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $result = Notes::getNote($id);
    if ($result) {
        $response->json(Result::success('', $result));
    } else {
        $response->json(Result::error('Note not found'));
    }
});
$this->respond(['GET', 'POST'], '/edit/[:id]', function ($request, $response, $service, $app) {
    $id = $request->param('id');
    $data = json_decode($request->body());
    $result = Notes::updateNote($id, $data);
    if ($result > 0) {
        $response->json(Result::success('Note Updated.'));
    } elseif ($result === 0) {
        $response->json(Result::success('Note not Updated.'));
    } else {
        $response->json(Result::error('Note not found'));
    }