Skip to content

Commit

Permalink
Merge pull request #2816 from samsonasik/api-response-updated
Browse files Browse the repository at this point in the history
add respondUpdated() method into API\ResponseTrait
  • Loading branch information
lonnieezell authored Apr 15, 2020
2 parents 895f1e6 + 997782d commit 47c17e9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
14 changes: 14 additions & 0 deletions system/API/ResponseTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ trait ResponseTrait
protected $codes = [
'created' => 201,
'deleted' => 200,
'updated' => 200,
'no_content' => 204,
'invalid_request' => 400,
'unsupported_response_type' => 400,
Expand Down Expand Up @@ -196,6 +197,19 @@ public function respondDeleted($data = null, string $message = '')
return $this->respond($data, $this->codes['deleted'], $message);
}

/**
* Used after a resource has been successfully updated.
*
* @param mixed $data Data.
* @param string $message Message.
*
* @return mixed
*/
public function respondUpdated($data = null, string $message = '')
{
return $this->respond($data, $this->codes['updated'], $message);
}

//--------------------------------------------------------------------

/**
Expand Down
10 changes: 10 additions & 0 deletions tests/system/API/ResponseTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,16 @@ public function testDeleted()
$this->assertEquals($this->formatter->format(['id' => 3]), $this->response->getBody());
}

public function testUpdated()
{
$controller = $this->makeController();
$controller->respondUpdated(['id' => 3], 'A Custom Reason');

$this->assertEquals('A Custom Reason', $this->response->getReason());
$this->assertEquals(200, $this->response->getStatusCode());
$this->assertEquals($this->formatter->format(['id' => 3]), $this->response->getBody());
}

public function testUnauthorized()
{
$controller = $this->makeController();
Expand Down

0 comments on commit 47c17e9

Please sign in to comment.