mirror of https://github.com/kcal-app/kcal.git
59 lines
1.4 KiB
PHP
59 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\JsonApi\Schemas;
|
|
|
|
use CloudCreativity\LaravelJsonApi\Schema\SchemaProvider;
|
|
|
|
class GoalSchema extends SchemaProvider
|
|
{
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
protected string $resourceType = 'goals';
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getId($resource): string
|
|
{
|
|
return (string) $resource->getRouteKey();
|
|
}
|
|
|
|
/**
|
|
* {@inheritdoc}
|
|
*/
|
|
public function getAttributes($resource): array
|
|
{
|
|
/** @var \App\Models\Goal $resource */
|
|
return [
|
|
'name' => $resource->name,
|
|
'days' => $resource->days,
|
|
'daysFormatted' => $resource->days_formatted,
|
|
'calories' => $resource->calories,
|
|
'carbohydrates' => $resource->carbohydrates,
|
|
'cholesterol' => $resource->cholesterol,
|
|
'fat' => $resource->fat,
|
|
'protein' => $resource->protein,
|
|
'sodium' => $resource->sodium,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* @inheritdoc
|
|
*/
|
|
public function getRelationships($resource, $isPrimary, array $includeRelationships): array
|
|
{
|
|
return [
|
|
'user' => [
|
|
self::SHOW_SELF => true,
|
|
self::SHOW_RELATED => true,
|
|
self::SHOW_DATA => isset($includeRelationships['user']),
|
|
self::DATA => function () use ($resource) {
|
|
return $resource->user; // @codeCoverageIgnore
|
|
},
|
|
],
|
|
];
|
|
}
|
|
}
|