Added dynamic adding and loading of results on the test page
This commit is contained in:
@ -6,11 +6,13 @@ use Psr\Http\Message\ResponseInterface as Response;
|
||||
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||
use Slim\Routing\RouteContext;
|
||||
use BitGoblin\Colossus\Models\Benchmark;
|
||||
use BitGoblin\Colossus\Models\Result;
|
||||
|
||||
class ApiController extends Controller {
|
||||
|
||||
public function getBenchmark(Request $request, Response $response, array $args): Response {
|
||||
$benchmark = Benchmark::where('id', $args['benchmark_id'])->first();
|
||||
public function getBenchmarkDetails(Request $request, Response $response, array $args): Response {
|
||||
$urlParams = $request->getQueryParams();
|
||||
$benchmark = Benchmark::where('id', $urlParams['benchmark_id'])->first();
|
||||
|
||||
$payload = json_encode($benchmark);
|
||||
|
||||
@ -29,4 +31,37 @@ class ApiController extends Controller {
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
public function getResultList(Request $request, Response $response, array $args): Response {
|
||||
$urlParams = $request->getQueryParams();
|
||||
$results = Result::where([
|
||||
['benchmark_id', '=', $urlParams['benchmark_id']],
|
||||
['test_id', '=', $urlParams['test_id']],
|
||||
])->get();
|
||||
|
||||
$payload = json_encode($results);
|
||||
|
||||
$response->getBody()->write($payload);
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
public function postResultAdd(Request $request, Response $response, array $args): Response {
|
||||
$params = (array)$request->getParsedBody();
|
||||
|
||||
$result = new Result;
|
||||
$result->test_id = $params['result_test'];
|
||||
$result->benchmark_id = $params['result_benchmark'];
|
||||
$result->average = $params['result_avg'];
|
||||
$result->minimum = $params['result_min'] ?? null;
|
||||
$result->maximum = $params['result_max'] ?? null;
|
||||
|
||||
$result->save();
|
||||
|
||||
$payload = json_encode('success');
|
||||
|
||||
$response->getBody()->write($payload);
|
||||
return $response
|
||||
->withHeader('Content-Type', 'application/json');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -8,6 +8,7 @@ class Result extends Model {
|
||||
|
||||
protected $fillable = [
|
||||
'test_id',
|
||||
'benchmark_id',
|
||||
'average',
|
||||
'minimum',
|
||||
'maximum',
|
||||
@ -17,10 +18,6 @@ class Result extends Model {
|
||||
return $this->belongsTo(Test::class);
|
||||
}
|
||||
|
||||
public function component() {
|
||||
return $this->belongsTo(Component::class);
|
||||
}
|
||||
|
||||
public function benchmark() {
|
||||
return $this->belongsTo(Benchmark::class);
|
||||
}
|
||||
|
@ -36,6 +36,11 @@ $app->group('/reports', function(RouteCollectorProxy $group) {
|
||||
});
|
||||
|
||||
$app->group('/api', function(RouteCollectorProxy $group) {
|
||||
$group->get('/benchmark/{benchmark_id}', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getBenchmark')->setName('api.benchmark');
|
||||
$group->get('/benchmark/{benchmark_id}/tests', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getBenchmarkTests')->setName('api.benchmark');
|
||||
$group->group('/v1', function(RouteCollectorProxy $apiv1) {
|
||||
$apiv1->get('/benchmark/details', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getBenchmarkDetails')->setName('api.benchmarkDetails');
|
||||
$apiv1->get('/benchmark/tests', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getBenchmarkTests')->setName('api.benchmarkTests');
|
||||
|
||||
$apiv1->get('/result/list', '\\BitGoblin\\Colossus\\Controllers\\ApiController:getResultList')->setName('api.resultList');
|
||||
$apiv1->post('/result/add', '\\BitGoblin\\Colossus\\Controllers\\ApiController:postResultAdd')->setName('api.resultAdd');
|
||||
});
|
||||
});
|
||||
|
Reference in New Issue
Block a user