This repository was archived by the owner on Nov 14, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.php
98 lines (69 loc) · 2.25 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
<?php
/**
* Copyright (C) 2018 Michael Milawski - All Rights Reserved
* You may use, distribute and modify this code under the
* terms of the MIT license.
*/
error_reporting(E_ALL);
ini_set('display_errors', 1);
use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;
require_once __DIR__ . "/src/initapp.php";
$container->logger->addInfo("Hello World");
$app->get('/hello/{name}', function (Request $request, Response $response, array $args) {
$name = $args['name'];
$response->getBody()->write("Hello, $name");
return $response;
});
$app->get('/', function (Request $request, Response $response, array $args) {
$this->logger->addInfo("Opened Index page");
$newResponse = $response->withJson([
"version" => "1.0.0",
"status" => "running",
]);
return $newResponse;
});
$app->post('/jobs/add', function (Request $request, Response $response) {
$this->logger->addInfo("Adding a job");
$payload = $request->getParsedBody();
$job_id = $this->jobs->addJob($payload);
$newResponse = $response->withJson([
"status" => "OK",
"job_id" => $job_id
]);
return $newResponse;
});
//Get the job status for a specific job
$app->get('/jobs/status/{id}', function (Request $request, Response $response, array $args) {
$job_id = (int) $args['id'];
$status = $this->jobs->getStatus($job_id);
$status_code = 200;
if(!$status){
$status_code = 404;
$status = 'Job not found';
}
$status = [
'status' => $status_code,
'data' => $status,
];
$newResponse = $response->withJson($status, $status_code);
return $newResponse;
});
//Get the job status for all jobs in the queue
$app->get('/jobs/status', function (Request $request, Response $response) {
$status = $this->jobs->getJobsCount();
$status = [
'status' => 200,
'data' => $status,
];
$newResponse = $response->withJson($status);
return $newResponse;
});
//Middleware - will be used later for auth
$app->add(function ($request, $response, $next) {
//$response->getBody()->write('BEFORE');
$response = $next($request, $response);
//$response->getBody()->write('AFTER');
return $response;
});
$app->run();