Skip to content

Commit

Permalink
finessed review marshalling
Browse files Browse the repository at this point in the history
  • Loading branch information
RocketMan committed Nov 24, 2024
1 parent 9ee9335 commit 686acf5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 9 deletions.
10 changes: 5 additions & 5 deletions api/OffsetPaginationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use Enm\JsonApi\Exception\NotAllowedException;
use Enm\JsonApi\Model\Document\Document;
use Enm\JsonApi\Model\Request\RequestInterface;
use Enm\JsonApi\Model\Resource\JsonResource;
use Enm\JsonApi\Model\Resource\Link\Link;
use Enm\JsonApi\Model\Resource\Relationship\Relationship;
use Enm\JsonApi\Model\Resource\ResourceCollection;
Expand Down Expand Up @@ -143,11 +144,10 @@ protected function marshallReviews(array $records, $flags) {
$relation->links()->set(new Link("related", Engine::getBaseUrl()."album/{$record["tag"]}/reviews"));
$resource->relationships()->set($relation);
if($flags & Albums::LINKS_REVIEWS_WITH_BODY) {
$reviews = Engine::api(IReview::class)->getReviews($record["id"], 1, "", Engine::session()->isAuth("u"), 1);
$record["airname"] = $reviews[0]["airname"] ?? $reviews[0]["realname"];
$record["review"] = $reviews[0]["review"];
}
$res = Reviews::fromRecord($record);
$review = Engine::api(IReview::class)->getReviews($record["id"], 1, "", Engine::session()->isAuth("u"), 1)[0];
$res = Reviews::fromRecord($review);
} else
$res = new JsonResource("review", $record["id"]);
$res->metaInformation()->set("date", $record["reviewed"]);
$relations->set($res);

Expand Down
5 changes: 1 addition & 4 deletions api/Reviews.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,9 @@ public static function fromRecord($rec) {
$res = new JsonResource("review", $rec["id"]);
$res->links()->set(new Link("self", Engine::getBaseUrl()."review/".$rec["id"]));
foreach(self::FIELDS as $field) {
if(!array_key_exists($field, $rec))
continue;

switch($field) {
case "date":
$value = substr($rec["reviewed"], 0, 10);
$value = substr($rec["reviewed"] ?? $rec["created"], 0, 10);
break;
case "airname":
$value = $rec["airname"] ?? $rec["realname"];
Expand Down

0 comments on commit 686acf5

Please sign in to comment.