taktik - laravel

This commit is contained in:
2025-01-23 00:19:07 +01:00
commit 43b6cff880
127 changed files with 15025 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use OpenApi\Annotations as OA;
/**
* @OA\Schema(
* schema="CategoryCollection",
* type="array",
* title="Category Collection",
* description="A collection of CategoryResource",
* @OA\Items(ref="#/components/schemas/CategoryResource")
* )
*/
class CategoryCollection extends ResourceCollection
{
/**
* @param Request $request
* @return array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<string, mixed>|\JsonSerializable
*/
public function toArray(Request $request): array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
{
return parent::toArray($request);
}
}

View File

@@ -0,0 +1,63 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Annotations as OA;
/**
* @mixin Category
* @OA\Schema(
* schema="CategoryResource",
* type="object",
* title="Category Resource",
* description="Resource representing a single category",
* @OA\Property(
* property="id",
* type="integer",
* description="ID of the category",
* example=1
* ),
* @OA\Property(
* property="name",
* type="string",
* description="Name of the category",
* example="Technology"
* ),
* @OA\Property(
* property="created_at",
* type="string",
* format="date-time",
* description="Timestamp when the category was created",
* example="2023-12-10T14:17:00Z"
* ),
* @OA\Property(
* property="updated_at",
* type="string",
* format="date-time",
* description="Timestamp when the category was last updated",
* example="2023-12-11T15:20:00Z"
* )
* )
*/
class CategoryResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'created_at' => $this->created_at->toDateTimeString(),
'updated_at' => $this->updated_at->toDateTimeString(),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use OpenApi\Annotations as OA;
/**
* @OA\Schema(
* schema="CommentCollection",
* type="array",
* title="Comment Collection",
* description="A collection of CommentCollection",
* @OA\Items(ref="#/components/schemas/CommentResource")
* )
*/
class CommentCollection extends ResourceCollection
{
/**
* @param Request $request
* @return array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<string, mixed>|\JsonSerializable
*/
public function toArray(Request $request): array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
{
return parent::toArray($request);
}
}

View File

@@ -0,0 +1,62 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Comment;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Annotations as OA;
/**
* @mixin Comment
* @OA\Schema(
* schema="CommentResource",
* type="object",
* title="Comment Resource",
* description="Resource representing a single comment",
* @OA\Property(
* property="id",
* type="integer",
* description="ID of the comment",
* example=1
* ),
* @OA\Property(
* property="content",
* type="string",
* description="Content of the comment",
* example="This is a sample comment."
* ),
* @OA\Property(
* property="created_at",
* type="string",
* format="date-time",
* description="Timestamp when the comment was created",
* example="2023-12-10T15:24:00Z"
* ),
* @OA\Property(
* property="updated_at",
* type="string",
* format="date-time",
* description="Timestamp when the comment was last updated",
* example="2023-12-10T16:30:00Z"
* )
* )
*/
class CommentResource extends JsonResource
{
/** Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'content' => $this->content,
'created_at' => $this->created_at->toDateTimeString(),
'updated_at' => $this->updated_at->toDateTimeString(),
];
}
}

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Annotations as OA;
/**
* @template T
* @mixin \App\Services\PaginableResource<T>
* Souhrnný formát výstupu pro paginovaná data s metadaty.
*
* @OA\Schema(
* schema="PaginableResourceMeta",
* type="object",
* title="Paginable Resource (meta)",
* description="A paginated collection with meta information",
* @OA\Property(property="totalCount", type="integer", example=1),
* @OA\Property(property="pages", type="integer", example=10),
* )
*/
class PaginableResource extends JsonResource
{
public function __construct(mixed $resource, protected readonly string $classResource)
{
parent::__construct($resource);
}
/**
* Transform the resource collection into an array.
*
* @return array<int|string, mixed>
*/
public function toArray(Request $request): array
{
return [
'items' => $this->classResource::make($this->data),
'meta' => [
'totalCount' => $this->totalCount,
'pages' => $this->totalPages,
]
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use OpenApi\Annotations as OA;
/**
* @OA\Schema(
* schema="PostCollection",
* type="array",
* title="Post Collection",
* description="A collection of PostResource",
* @OA\Items(ref="#/components/schemas/PostResource")
* )
*/
class PostCollection extends ResourceCollection
{
/**
* @param Request $request
* @return array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<string, mixed>|\JsonSerializable
*/
public function toArray(Request $request): array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
{
return parent::toArray($request);
}
}

View File

@@ -0,0 +1,89 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Post;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Annotations as OA;
/**
* @mixin Post
* @OA\Schema(
* schema="PostResource",
* type="object",
* title="Post Resource",
* description="Resource representing a single post",
* @OA\Property(
* property="id",
* type="integer",
* description="ID of the post",
* example=1
* ),
* @OA\Property(
* property="title",
* type="string",
* description="Title of the post",
* example="Sample Post Title"
* ),
* @OA\Property(
* property="content",
* type="string",
* description="Content of the post",
* example="This is a sample post content."
* ),
* @OA\Property(
* property="category_id",
* type="integer",
* description="Category ID the post belongs to",
* example=1
* ),
* @OA\Property(
* property="category",
* description="Category object",
* ref="#/components/schemas/CategoryResource",
* ),
* @OA\Property(
* property="tags",
* ref="#/components/schemas/TagCollection",
* description="Collection of tags related to the post"
* ),
* @OA\Property(
* property="created_at",
* type="string",
* format="date-time",
* description="Timestamp when the post was created",
* example="2023-12-10T15:24:00Z"
* ),
* @OA\Property(
* property="updated_at",
* type="string",
* format="date-time",
* description="Timestamp when the post was last updated",
* example="2023-12-10T15:26:00Z"
* )
* )
*/
class PostResource extends JsonResource
{
/**
* Transform the resource collection into an array.
*
* @return array<int|string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'title' => $this->title,
'content' => $this->content,
'category_id' => $this->category_id,
'category' => new CategoryResource($this->whenLoaded('category')),
'tags' => new TagCollection($this->whenLoaded('tags')),
'created_at' => $this->created_at->toDateTimeString(),
'updated_at' => $this->updated_at->toDateTimeString(),
];
}
}

View File

@@ -0,0 +1,30 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\ResourceCollection;
use OpenApi\Annotations as OA;
/**
* @OA\Schema(
* schema="TagCollection",
* type="array",
* title="Tag Collection",
* description="A collection of TagResource",
* @OA\Items(ref="#/components/schemas/TagResource")
* )
*/
class TagCollection extends ResourceCollection
{
/**
* @param Request $request
* @return array<string, mixed>|\Illuminate\Contracts\Support\Arrayable<string, mixed>|\JsonSerializable
*/
public function toArray(Request $request): array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
{
return parent::toArray($request);
}
}

View File

@@ -0,0 +1,67 @@
<?php
declare(strict_types=1);
namespace App\Http\Resources;
use App\Models\Tag;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use OpenApi\Annotations as OA;
/**
* @mixin Tag
*/
/**
* @mixin Tag
* @OA\Schema(
* schema="TagResource",
* type="object",
* title="Tag Resource",
* description="Resource representing a single tag",
* @OA\Property(
* property="id",
* type="integer",
* description="ID of the tag",
* example=1
* ),
* @OA\Property(
* property="name",
* type="string",
* description="Name of the tag",
* example="Laravel"
* ),
* @OA\Property(
* property="created_at",
* type="string",
* format="date-time",
* description="Timestamp when the tag was created",
* example="2023-12-10T14:17:00Z"
* ),
* @OA\Property(
* property="updated_at",
* type="string",
* format="date-time",
* description="Timestamp when the tag was last updated",
* example="2023-12-11T15:20:00Z"
* )
* )
*/
class TagResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'name' => $this->name,
'created_at' => $this->created_at->toDateTimeString(),
'updated_at' => $this->updated_at->toDateTimeString(),
];
}
}