Finalized API
This commit is contained in:
parent
045eb7ecc9
commit
f372401e19
4 changed files with 86 additions and 5 deletions
30
juggl-server/api/addProject.php
Normal file
30
juggl-server/api/addProject.php
Normal file
|
@ -0,0 +1,30 @@
|
|||
<?php
|
||||
session_start();
|
||||
require_once(__DIR__ . "/services/apiBranch.inc.php");
|
||||
require_once(__DIR__ . "/services/jsonBuilder.inc.php");
|
||||
require_once(__DIR__ . "/services/responses.inc.php");
|
||||
require_once(__DIR__ . "/services/jugglDbApi.inc.php");
|
||||
|
||||
class AddProjectBranch extends ApiBranch
|
||||
{
|
||||
function get(ParamCleaner $params)
|
||||
{
|
||||
respondStatus(405);
|
||||
}
|
||||
|
||||
function post(ParamCleaner $params)
|
||||
{
|
||||
$user_id = $params->get("user_id");
|
||||
|
||||
if ($params->exists(["name", "start_date"]) == false) {
|
||||
respondStatus(400, "Missing parameter");
|
||||
}
|
||||
|
||||
addProject($user_id, $params);
|
||||
|
||||
respondStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
$branch = new AddProjectBranch();
|
||||
$branch->execute();
|
29
juggl-server/api/removeRecord.php
Normal file
29
juggl-server/api/removeRecord.php
Normal file
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
session_start();
|
||||
require_once(__DIR__ . "/services/apiBranch.inc.php");
|
||||
require_once(__DIR__ . "/services/responses.inc.php");
|
||||
require_once(__DIR__ . "/services/jugglDbApi.inc.php");
|
||||
|
||||
class RemoveRecordBranch extends ApiBranch
|
||||
{
|
||||
function get(ParamCleaner $params)
|
||||
{
|
||||
respondStatus(405);
|
||||
}
|
||||
|
||||
function post(ParamCleaner $params)
|
||||
{
|
||||
$user_id = $params->get("user_id");
|
||||
|
||||
if ($params->exists(["record_id"]) == false) {
|
||||
respondStatus(400, "Missing parameter");
|
||||
}
|
||||
|
||||
removeRecord($user_id, $params);
|
||||
|
||||
respondStatus(200);
|
||||
}
|
||||
}
|
||||
|
||||
$branch = new RemoveRecordBranch();
|
||||
$branch->execute();
|
|
@ -15,6 +15,19 @@ function addStartRecord($user_id, $params, $project_id = null, $start_device_id
|
|||
$db->execute();
|
||||
}
|
||||
|
||||
function addProject($user_id, $params)
|
||||
{
|
||||
$data = [
|
||||
"user_id" => $user_id,
|
||||
"name" => $params->get("name"),
|
||||
"start_date" => $params->get("start_date")
|
||||
];
|
||||
|
||||
$db = new DbOperations();
|
||||
$db->insert("projects", $data);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
function addTimeRecord($user_id, $params, $project_id = null, $start_device_id = null)
|
||||
{
|
||||
$data = [
|
||||
|
@ -168,8 +181,6 @@ function updateEndRecord($user_id, $params)
|
|||
|
||||
// Get start instance to calculate duration
|
||||
$start_time = getTimeRecord($user_id, $record_id)["start_time"];
|
||||
var_dump($start_time);
|
||||
var_dump($params->get("end_time"));
|
||||
|
||||
$data = [
|
||||
"end_time" => $params->get("end_time"),
|
||||
|
@ -183,6 +194,17 @@ function updateEndRecord($user_id, $params)
|
|||
$db->execute();
|
||||
}
|
||||
|
||||
function removeRecord($user_id, $params)
|
||||
{
|
||||
$record_id = $params->get("record_id");
|
||||
|
||||
$db = new DbOperations();
|
||||
$db->delete("time_records");
|
||||
$db->where("user_id", Comparison::EQUAL, $user_id);
|
||||
$db->where("record_id", Comparison::EQUAL, $record_id);
|
||||
$db->execute();
|
||||
}
|
||||
|
||||
function updateTimeRecord($user_id, $params)
|
||||
{
|
||||
$data = [];
|
||||
|
|
|
@ -10,20 +10,20 @@ function setDefaultHeader()
|
|||
}
|
||||
|
||||
function respondJson(JsonBuilder $builder) {
|
||||
defaultHeader();
|
||||
setDefaultHeader();
|
||||
header('Content-type: application/json');
|
||||
echo($builder->getJson());
|
||||
}
|
||||
|
||||
function respondHtml(string $html)
|
||||
{
|
||||
defaultHeader();
|
||||
setDefaultHeader();
|
||||
print($html);
|
||||
}
|
||||
|
||||
function respondStatus(int $statusCode, string $message = "")
|
||||
{
|
||||
defaultHeader();
|
||||
setDefaultHeader();
|
||||
http_response_code($statusCode);
|
||||
die($message);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue