Expose etag through JSON responses for child elements

Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
Julius Härtl
2020-11-10 17:15:05 +01:00
parent 6a8e607134
commit a46d31caf2
10 changed files with 35 additions and 9 deletions

View File

@@ -24,6 +24,7 @@
namespace OCA\Deck\Controller;
use OCA\Deck\Db\Board;
use OCA\Deck\StatusException;
use OCP\AppFramework\ApiController;
use OCP\AppFramework\Http;
@@ -72,7 +73,11 @@ class BoardApiController extends ApiController {
}
$boards = $this->boardService->findAll($date->getTimestamp(), $details);
}
return new DataResponse($boards, HTTP::STATUS_OK);
$response = new DataResponse($boards, HTTP::STATUS_OK);
$response->setETag(md5(json_encode(array_map(function (Board $board) {
return $board->getId() . '-' . $board->getETag();
}, $boards))));
return $response;
}
/**

View File

@@ -36,4 +36,8 @@ class Label extends RelationalEntity {
$this->addType('cardId', 'integer');
$this->addType('lastModified', 'integer');
}
public function getETag() {
return md5((string)$this->getLastModified());
}
}

View File

@@ -80,6 +80,9 @@ class RelationalEntity extends Entity implements \JsonSerializable {
$json[$property] = $value;
}
}
if ($reflection->hasMethod('getETag')) {
$json['ETag'] = $this->getETag();
}
return $json;
}