Expose etag through JSON responses for child elements
Signed-off-by: Julius Härtl <jus@bitgrid.net>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -36,4 +36,8 @@ class Label extends RelationalEntity {
|
||||
$this->addType('cardId', 'integer');
|
||||
$this->addType('lastModified', 'integer');
|
||||
}
|
||||
|
||||
public function getETag() {
|
||||
return md5((string)$this->getLastModified());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -80,6 +80,9 @@ class RelationalEntity extends Entity implements \JsonSerializable {
|
||||
$json[$property] = $value;
|
||||
}
|
||||
}
|
||||
if ($reflection->hasMethod('getETag')) {
|
||||
$json['ETag'] = $this->getETag();
|
||||
}
|
||||
return $json;
|
||||
}
|
||||
|
||||
|
||||
@@ -32,6 +32,7 @@ class BoardTest extends TestCase {
|
||||
'archived' => false,
|
||||
'users' => ['user1', 'user2'],
|
||||
'settings' => [],
|
||||
'ETag' => $board->getETag(),
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
|
||||
@@ -52,6 +53,7 @@ class BoardTest extends TestCase {
|
||||
'archived' => false,
|
||||
'users' => [],
|
||||
'settings' => [],
|
||||
'ETag' => $board->getETag(),
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
public function testSetAcl() {
|
||||
@@ -80,6 +82,7 @@ class BoardTest extends TestCase {
|
||||
'shared' => 1,
|
||||
'users' => [],
|
||||
'settings' => [],
|
||||
'ETag' => $board->getETag(),
|
||||
], $board->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -84,6 +84,7 @@ class CardTest extends TestCase {
|
||||
'deletedAt' => 0,
|
||||
'commentsUnread' => 0,
|
||||
'lastEditor' => null,
|
||||
'ETag' => $card->getETag(),
|
||||
], $card->jsonSerialize());
|
||||
}
|
||||
public function testJsonSerializeLabels() {
|
||||
@@ -109,6 +110,7 @@ class CardTest extends TestCase {
|
||||
'deletedAt' => 0,
|
||||
'commentsUnread' => 0,
|
||||
'lastEditor' => null,
|
||||
'ETag' => $card->getETag(),
|
||||
], $card->jsonSerialize());
|
||||
}
|
||||
|
||||
@@ -144,6 +146,7 @@ class CardTest extends TestCase {
|
||||
'deletedAt' => 0,
|
||||
'commentsUnread' => 0,
|
||||
'lastEditor' => null,
|
||||
'ETag' => $card->getETag(),
|
||||
], $card->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,8 @@ class LabelTest extends TestCase {
|
||||
'boardId' => 123,
|
||||
'cardId' => null,
|
||||
'lastModified' => null,
|
||||
'color' => '000000'
|
||||
'color' => '000000',
|
||||
'ETag' => $label->getETag(),
|
||||
], $label->jsonSerialize());
|
||||
}
|
||||
public function testJsonSerializeCard() {
|
||||
@@ -54,7 +55,8 @@ class LabelTest extends TestCase {
|
||||
'boardId' => null,
|
||||
'cardId' => 123,
|
||||
'lastModified' => null,
|
||||
'color' => '000000'
|
||||
'color' => '000000',
|
||||
'ETag' => $label->getETag(),
|
||||
], $label->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ class StackTest extends \Test\TestCase {
|
||||
return $board;
|
||||
}
|
||||
public function testJsonSerialize() {
|
||||
$board = $this->createStack();
|
||||
$stack = $this->createStack();
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Stack",
|
||||
@@ -41,12 +41,13 @@ class StackTest extends \Test\TestCase {
|
||||
'boardId' => 1,
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
], $board->jsonSerialize());
|
||||
'ETag' => $stack->getETag(),
|
||||
], $stack->jsonSerialize());
|
||||
}
|
||||
public function testJsonSerializeWithCards() {
|
||||
$cards = ["foo", "bar"];
|
||||
$board = $this->createStack();
|
||||
$board->setCards($cards);
|
||||
$stack = $this->createStack();
|
||||
$stack->setCards($cards);
|
||||
$this->assertEquals([
|
||||
'id' => 1,
|
||||
'title' => "My Stack",
|
||||
@@ -55,6 +56,7 @@ class StackTest extends \Test\TestCase {
|
||||
'cards' => ["foo", "bar"],
|
||||
'deletedAt' => 0,
|
||||
'lastModified' => 0,
|
||||
], $board->jsonSerialize());
|
||||
'ETag' => $stack->getETag(),
|
||||
], $stack->jsonSerialize());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ class BoardApiControllerTest extends \Test\TestCase {
|
||||
|
||||
$expected = new DataResponse($boards, HTTP::STATUS_OK);
|
||||
$actual = $this->controller->index();
|
||||
|
||||
$actual->setETag(null);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -90,6 +90,7 @@ class BoardApiControllerTest extends \Test\TestCase {
|
||||
->will($this->returnValue($boardId));
|
||||
|
||||
$expected = new DataResponse($board, HTTP::STATUS_OK);
|
||||
$expected->setETag($board->getETag());
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -72,6 +72,7 @@ class CardApiControllerTest extends \Test\TestCase {
|
||||
->willReturn($card);
|
||||
|
||||
$expected = new DataResponse($card, HTTP::STATUS_OK);
|
||||
$expected->setETag($card->getETag());
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -78,6 +78,7 @@ class StackApiControllerTest extends \Test\TestCase {
|
||||
|
||||
$expected = new DataResponse($stacks, HTTP::STATUS_OK);
|
||||
$actual = $this->controller->index();
|
||||
$actual->setETag(null);
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
@@ -97,6 +98,7 @@ class StackApiControllerTest extends \Test\TestCase {
|
||||
->willReturn($this->exampleStack['id']);
|
||||
|
||||
$expected = new DataResponse($stack, HTTP::STATUS_OK);
|
||||
$expected->setETag($stack->getETag());
|
||||
$actual = $this->controller->get();
|
||||
$this->assertEquals($expected, $actual);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user