mirror of
https://github.com/JanGross/quicknotes.git
synced 2025-11-30 23:37:16 +01:00
Fix response when dont have notes. Issue #44
This commit is contained in:
@@ -54,14 +54,16 @@ class NoteApiController extends ApiController {
|
|||||||
*/
|
*/
|
||||||
public function index(): JSONResponse {
|
public function index(): JSONResponse {
|
||||||
$notes = $this->noteService->getAll($this->userId);
|
$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'));
|
$lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
|
||||||
$timestamp = max(array_map(function($note) { return $note->getTimestamp(); }, $notes));
|
$timestamp = max(array_map(function($note) { return $note->getTimestamp(); }, $notes));
|
||||||
$lastModified->setTimestamp($timestamp);
|
$lastModified->setTimestamp($timestamp);
|
||||||
|
|
||||||
$response = new JSONResponse($notes);
|
$response = new JSONResponse($notes);
|
||||||
$response->setETag($etag);
|
$response->setETag(md5(json_encode($notes)));
|
||||||
$response->setLastModified($lastModified);
|
$response->setLastModified($lastModified);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|||||||
@@ -52,14 +52,16 @@ class NoteController extends Controller {
|
|||||||
*/
|
*/
|
||||||
public function index(): JSONResponse {
|
public function index(): JSONResponse {
|
||||||
$notes = $this->noteService->getAll($this->userId);
|
$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'));
|
$lastModified = new \DateTime(null, new \DateTimeZone('GMT'));
|
||||||
$timestamp = max(array_map(function($note) { return $note->getTimestamp(); }, $notes));
|
$timestamp = max(array_map(function($note) { return $note->getTimestamp(); }, $notes));
|
||||||
$lastModified->setTimestamp($timestamp);
|
$lastModified->setTimestamp($timestamp);
|
||||||
|
|
||||||
$response = new JSONResponse($notes);
|
$response = new JSONResponse($notes);
|
||||||
$response->setETag($etag);
|
$response->setETag(md5(json_encode($notes)));
|
||||||
$response->setLastModified($lastModified);
|
$response->setLastModified($lastModified);
|
||||||
|
|
||||||
return $response;
|
return $response;
|
||||||
|
|||||||
Reference in New Issue
Block a user