mirror of
https://github.com/CachetHQ/Cachet.git
synced 2025-04-21 16:02:11 +02:00
Merge pull request #3191 from TakeMeNL/feature/api-get-incident-templates
Added GET incident templates to use in POST incidents template
This commit is contained in:
commit
415c6de378
51
app/Http/Controllers/Api/IncidentTemplateController.php
Normal file
51
app/Http/Controllers/Api/IncidentTemplateController.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Cachet\Http\Controllers\Api;
|
||||
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
use GrahamCampbell\Binput\Facades\Binput;
|
||||
use Illuminate\Support\Facades\Request;
|
||||
|
||||
class IncidentTemplateController extends AbstractApiController
|
||||
{
|
||||
/**
|
||||
* Get all incident templates.
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$templates = IncidentTemplate::query();
|
||||
|
||||
if ($sortBy = Binput::get('sort')) {
|
||||
$direction = Binput::has('order') && Binput::get('order') == 'desc';
|
||||
|
||||
$templates->sort($sortBy, $direction);
|
||||
}
|
||||
|
||||
$templates = $templates->paginate(Binput::get('per_page', 20));
|
||||
|
||||
return $this->paginator($templates, Request::instance());
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single incident templates.
|
||||
*
|
||||
* @param \CachetHQ\Cachet\Models\IncidentTemplate $incidentTemplate
|
||||
*
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function show(IncidentTemplate $incidentTemplate)
|
||||
{
|
||||
return $this->item($incidentTemplate);
|
||||
}
|
||||
}
|
@ -47,8 +47,11 @@ class ApiRoutes
|
||||
$router->get('components/{component}', 'ComponentController@show');
|
||||
|
||||
$router->get('incidents', 'IncidentController@index');
|
||||
$router->get('incidents/{incident}', 'IncidentController@show');
|
||||
|
||||
$router->get('incidents/templates', 'IncidentTemplateController@index');
|
||||
$router->get('incidents/templates/{incident_template}', 'IncidentTemplateController@show');
|
||||
|
||||
$router->get('incidents/{incident}', 'IncidentController@show');
|
||||
$router->get('incidents/{incident}/updates', 'IncidentUpdateController@index');
|
||||
$router->get('incidents/{incident}/updates/{update}', 'IncidentUpdateController@show');
|
||||
|
||||
|
41
tests/Api/IncidentTemplateTest.php
Normal file
41
tests/Api/IncidentTemplateTest.php
Normal file
@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Cachet.
|
||||
*
|
||||
* (c) Alt Three Services Limited
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace CachetHQ\Tests\Cachet\Api;
|
||||
|
||||
use CachetHQ\Cachet\Models\IncidentTemplate;
|
||||
|
||||
/**
|
||||
* This is the incident template test class.
|
||||
*
|
||||
* @author Marc Hagen <hello@marchagen.nl>
|
||||
*/
|
||||
class IncidentTemplateTest extends AbstractApiTestCase
|
||||
{
|
||||
public function test_can_get_all_incident_templates()
|
||||
{
|
||||
$templates = factory(IncidentTemplate::class, 3)->create();
|
||||
|
||||
$response = $this->json('GET', '/api/v1/incidents/templates');
|
||||
|
||||
$response->assertJsonFragment(['id' => $templates[0]->id]);
|
||||
$response->assertJsonFragment(['id' => $templates[1]->id]);
|
||||
$response->assertJsonFragment(['id' => $templates[2]->id]);
|
||||
$response->assertStatus(200);
|
||||
}
|
||||
|
||||
public function test_cannot_get_invalid_incident_template()
|
||||
{
|
||||
$response = $this->json('GET', '/api/v1/incidents/templates/1');
|
||||
|
||||
$response->assertStatus(404);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user