diff --git a/README.md b/README.md index 122cb51..422e87d 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,24 @@ echo $caseCreated->name; // Display "This is a new case." ``` See [dotfile documentation](https://docs.dotfile.com/reference/case-create-one). + + +
+ +Add tags in an existing case + +```php +use Dotfile\Model\Case\CaseTags; +use Dotfile\Model\Case\CaseTagsInput; + +$input = new CaseTagsInput(); +$input->caseId = '39cbd6d5-4da5-4d94-ae71-84895c5e552a'; +$input->tags = ['A faire']; + +$caseAddTags = $client->case->addTags($input); // Returns an instance of CaseTags + +echo $caseAddTags->tags[0]['label']; // Display "A faire" +```
@@ -103,3 +121,11 @@ echo $individual->lastName; // Display "Parks" See [dotfile documentation](https://docs.dotfile.com/reference/individual-create-one). + +### Tests + +To launch all the tests: + +```php +make test +``` diff --git a/src/Exception/DotfileApiException.php b/src/Exception/DotfileApiException.php index 7fa842a..a8890a4 100644 --- a/src/Exception/DotfileApiException.php +++ b/src/Exception/DotfileApiException.php @@ -4,4 +4,6 @@ namespace Dotfile\Exception; -class DotfileApiException extends \Exception {} +class DotfileApiException extends \Exception +{ +} diff --git a/src/Model/Case/CaseTags.php b/src/Model/Case/CaseTags.php new file mode 100644 index 0000000..26378d1 --- /dev/null +++ b/src/Model/Case/CaseTags.php @@ -0,0 +1,18 @@ + + */ + public array $tags = []; +} diff --git a/src/Model/Case/CaseTagsInput.php b/src/Model/Case/CaseTagsInput.php new file mode 100644 index 0000000..ea5daa5 --- /dev/null +++ b/src/Model/Case/CaseTagsInput.php @@ -0,0 +1,23 @@ +serializer->serialize($input, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]); + + $response = $this->client->request(Request::METHOD_POST, 'cases/'.$caseId.'/tags', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'body' => $body, + ]); + + return $this->serializer->deserialize($this->getContent($response), CaseTags::class, 'json'); + } } diff --git a/src/Service/TagsCaseService.php b/src/Service/TagsCaseService.php new file mode 100644 index 0000000..8ff278a --- /dev/null +++ b/src/Service/TagsCaseService.php @@ -0,0 +1,27 @@ +serializer->serialize($input, 'json', [AbstractObjectNormalizer::SKIP_NULL_VALUES => true]); + + $response = $this->client->request(Request::METHOD_POST, 'cases/'.$caseId.'/tags', [ + 'headers' => [ + 'Content-Type' => 'application/json', + ], + 'body' => $body, + ]); + + return $this->serializer->deserialize($this->getContent($response), CaseTags::class, 'json'); + } +} diff --git a/tests/FunctionalTests/CaseAddTagsTest.php b/tests/FunctionalTests/CaseAddTagsTest.php new file mode 100644 index 0000000..76fa560 --- /dev/null +++ b/tests/FunctionalTests/CaseAddTagsTest.php @@ -0,0 +1,34 @@ +caseId = '39cbd6d5-4da5-4d94-ae71-84895c5e552a'; + $input->tags = ['A faire']; + + $caseAddTags = $client->case->addTags($input, $input->caseId); + + $this->assertInstanceOf(CaseTags::class, $caseAddTags); + $this->assertSame([ + 'id' => 'ea5c5935-2ec8-4519-a526-7ab25c71ac4e', + 'label' => 'A faire', + ], current($caseAddTags->tags)); + } +} diff --git a/tests/fixtures/case_add_tags_with_minimal_data_response.json b/tests/fixtures/case_add_tags_with_minimal_data_response.json new file mode 100644 index 0000000..ab3d862 --- /dev/null +++ b/tests/fixtures/case_add_tags_with_minimal_data_response.json @@ -0,0 +1,8 @@ +{ + "tags": [ + { + "id": "ea5c5935-2ec8-4519-a526-7ab25c71ac4e", + "label": "A faire" + } + ] +} \ No newline at end of file