Skip to content

Commit 47c17e9

Browse files
authored
Merge pull request #2816 from samsonasik/api-response-updated
add respondUpdated() method into API\ResponseTrait
2 parents 895f1e6 + 997782d commit 47c17e9

2 files changed

Lines changed: 24 additions & 0 deletions

File tree

system/API/ResponseTrait.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ trait ResponseTrait
6666
protected $codes = [
6767
'created' => 201,
6868
'deleted' => 200,
69+
'updated' => 200,
6970
'no_content' => 204,
7071
'invalid_request' => 400,
7172
'unsupported_response_type' => 400,
@@ -196,6 +197,19 @@ public function respondDeleted($data = null, string $message = '')
196197
return $this->respond($data, $this->codes['deleted'], $message);
197198
}
198199

200+
/**
201+
* Used after a resource has been successfully updated.
202+
*
203+
* @param mixed $data Data.
204+
* @param string $message Message.
205+
*
206+
* @return mixed
207+
*/
208+
public function respondUpdated($data = null, string $message = '')
209+
{
210+
return $this->respond($data, $this->codes['updated'], $message);
211+
}
212+
199213
//--------------------------------------------------------------------
200214

201215
/**

tests/system/API/ResponseTraitTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,16 @@ public function testDeleted()
242242
$this->assertEquals($this->formatter->format(['id' => 3]), $this->response->getBody());
243243
}
244244

245+
public function testUpdated()
246+
{
247+
$controller = $this->makeController();
248+
$controller->respondUpdated(['id' => 3], 'A Custom Reason');
249+
250+
$this->assertEquals('A Custom Reason', $this->response->getReason());
251+
$this->assertEquals(200, $this->response->getStatusCode());
252+
$this->assertEquals($this->formatter->format(['id' => 3]), $this->response->getBody());
253+
}
254+
245255
public function testUnauthorized()
246256
{
247257
$controller = $this->makeController();

0 commit comments

Comments
 (0)