Skip to content

Commit

Permalink
Fix response when dont have notes. Issue #44
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdelellis committed Oct 3, 2020
1 parent c259645 commit b471181
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
6 changes: 4 additions & 2 deletions lib/Controller/NoteApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,16 @@ public function __construct($AppName,
*/
public function index(): JSONResponse {
$notes = $this->noteService->getAll($this->userId);
$etag = md5(json_encode($notes));
if (count($notes) === 0) {
return new JSONResponse([]);
}

$lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
$timestamp = max(array_map(function($note) { return $note->getTimestamp(); }, $notes));
$lastModified->setTimestamp($timestamp);

$response = new JSONResponse($notes);
$response->setETag($etag);
$response->setETag(md5(json_encode($notes)));
$response->setLastModified($lastModified);

return $response;
Expand Down
6 changes: 4 additions & 2 deletions lib/Controller/NoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,16 @@ public function __construct($AppName,
*/
public function index(): JSONResponse {
$notes = $this->noteService->getAll($this->userId);
$etag = md5(json_encode($notes));
if (count($notes) === 0) {
return new JSONResponse([]);
}

$lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
$timestamp = max(array_map(function($note) { return $note->getTimestamp(); }, $notes));
$lastModified->setTimestamp($timestamp);

$response = new JSONResponse($notes);
$response->setETag($etag);
$response->setETag(md5(json_encode($notes)));
$response->setLastModified($lastModified);

return $response;
Expand Down

0 comments on commit b471181

Please sign in to comment.