Skip to content
Snippets Groups Projects
Commit 15175eb5 authored by Florian Azizian's avatar Florian Azizian
Browse files

FIX #11270 TIME 0:20 get custom fields

parent 77e4e5fe
No related branches found
No related tags found
No related merge requests found
...@@ -128,6 +128,7 @@ $app->get('/contactsFilling', \Contact\controllers\ContactController::class . ': ...@@ -128,6 +128,7 @@ $app->get('/contactsFilling', \Contact\controllers\ContactController::class . ':
$app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':updateFilling'); $app->put('/contactsFilling', \Contact\controllers\ContactController::class . ':updateFilling');
//CustomFields //CustomFields
$app->get('/customFields', \CustomField\controllers\CustomFieldController::class . ':get');
$app->post('/customFields', \CustomField\controllers\CustomFieldController::class . ':create'); $app->post('/customFields', \CustomField\controllers\CustomFieldController::class . ':create');
$app->put('/customFields/{id}', \CustomField\controllers\CustomFieldController::class . ':update'); $app->put('/customFields/{id}', \CustomField\controllers\CustomFieldController::class . ':update');
$app->delete('/customFields/{id}', \Contact\controllers\ContactController::class . ':delete'); $app->delete('/customFields/{id}', \Contact\controllers\ContactController::class . ':delete');
......
...@@ -26,6 +26,21 @@ use Slim\Http\Response; ...@@ -26,6 +26,21 @@ use Slim\Http\Response;
class CustomFieldController class CustomFieldController
{ {
public function get(Request $request, Response $response)
{
if (!ServiceModel::hasService(['id' => 'admin_custom_fields', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
}
$customFields = CustomFieldModel::get();
foreach ($customFields as $key => $customField) {
$customFields[$key]['values'] = json_decode($customField['values'], true);
}
return $response->withJson(['customFields' => $customFields]);
}
public function create(Request $request, Response $response) public function create(Request $request, Response $response)
{ {
if (!ServiceModel::hasService(['id' => 'admin_custom_fields', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) { if (!ServiceModel::hasService(['id' => 'admin_custom_fields', 'userId' => $GLOBALS['userId'], 'location' => 'apps', 'type' => 'admin'])) {
......
...@@ -54,6 +54,18 @@ class CustomFieldControllerTest extends TestCase ...@@ -54,6 +54,18 @@ class CustomFieldControllerTest extends TestCase
$this->assertSame('Custom field with this label already exists', $responseBody->errors); $this->assertSame('Custom field with this label already exists', $responseBody->errors);
} }
public function testReadList()
{
$environment = \Slim\Http\Environment::mock(['REQUEST_METHOD' => 'GET']);
$request = \Slim\Http\Request::createFromEnvironment($environment);
$customFieldController = new \CustomField\controllers\CustomFieldController();
$response = $customFieldController->get($request, new \Slim\Http\Response());
$responseBody = json_decode((string)$response->getBody());
$this->assertNotNull($responseBody->customFields);
}
public function testUpdate() public function testUpdate()
{ {
$customFieldController = new \CustomField\controllers\CustomFieldController(); $customFieldController = new \CustomField\controllers\CustomFieldController();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment