Added me endpoints

This commit is contained in:
Constantin Graf
2024-07-18 10:00:20 +02:00
committed by Gregor Vostrak
parent 0e7dec2f40
commit 21207a4058
11 changed files with 261 additions and 48 deletions

View File

@@ -14,5 +14,5 @@ class MemberCollection extends ResourceCollection implements PaginatedResourceCo
*
* @var string
*/
public $collects = MemberPivotResource::class;
public $collects = MemberResource::class;
}

View File

@@ -1,44 +0,0 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\V1\Member;
use App\Http\Resources\V1\BaseResource;
use App\Models\Member;
use App\Models\User;
use Illuminate\Http\Request;
/**
* @property User $resource
*/
class MemberPivotResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, string|bool|int|null|array<string>>
*/
public function toArray(Request $request): array
{
/** @var Member $member */
$member = $this->resource->getRelationValue('membership');
return [
/** @var string $id ID of membership */
'id' => $member->id,
/** @var string $id ID of user */
'user_id' => $this->resource->id,
/** @var string $name Name */
'name' => $this->resource->name,
/** @var string $email Email */
'email' => $this->resource->email,
/** @var string $role Role */
'role' => $member->role,
/** @var bool $is_placeholder Placeholder user for imports, user might not really exist and does not know about this placeholder membership */
'is_placeholder' => $this->resource->is_placeholder,
/** @var int|null $billable_rate Billable rate in cents per hour */
'billable_rate' => $member->billable_rate,
];
}
}

View File

@@ -0,0 +1,18 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\V1\Member;
use App\Http\Resources\PaginatedResourceCollection;
use Illuminate\Http\Resources\Json\ResourceCollection;
class PersonalMemberCollection extends ResourceCollection implements PaginatedResourceCollection
{
/**
* The resource that this resource collects.
*
* @var string
*/
public $collects = PersonalMemberResource::class;
}

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources\V1\Member;
use App\Http\Resources\V1\BaseResource;
use App\Models\Member;
use Illuminate\Http\Request;
/**
* @property Member $resource
*/
class PersonalMemberResource extends BaseResource
{
/**
* Transform the resource into an array.
*
* @return array<string, string|bool|int|null|array<string>>
*/
public function toArray(Request $request): array
{
return [
/** @var string $id ID of membership */
'id' => $this->resource->id,
'organization' => [
/** @var int $id ID of organization */
'id' => $this->resource->organization->id,
/** @var string $name Name of organization */
'name' => $this->resource->organization->name,
],
/** @var string $role Role */
'role' => $this->resource->role,
];
}
}