1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace CSlant\Blog\Api\Http\Actions\Post; |
4
|
|
|
|
5
|
|
|
use Botble\Base\Http\Responses\BaseHttpResponse; |
|
|
|
|
6
|
|
|
use Botble\Blog\Http\Resources\PostResource; |
|
|
|
|
7
|
|
|
use CSlant\Blog\Api\OpenApi\Schemas\Resources\Post\PostModelResourceSchema; |
8
|
|
|
use CSlant\Blog\Api\Services\PostService; |
9
|
|
|
use CSlant\Blog\Core\Http\Actions\Action; |
10
|
|
|
use CSlant\Blog\Core\Http\Repositories\PostRepository; |
|
|
|
|
11
|
|
|
use CSlant\Blog\Core\Supports\Base\FilterPost; |
12
|
|
|
use Illuminate\Http\JsonResponse; |
13
|
|
|
use Illuminate\Http\RedirectResponse; |
14
|
|
|
use Illuminate\Http\Request; |
15
|
|
|
use Illuminate\Http\Resources\Json\JsonResource; |
16
|
|
|
use OpenApi\Attributes\Get; |
17
|
|
|
use OpenApi\Attributes\Items; |
18
|
|
|
use OpenApi\Attributes\JsonContent; |
19
|
|
|
use OpenApi\Attributes\Parameter; |
20
|
|
|
use OpenApi\Attributes\Property; |
21
|
|
|
use OpenApi\Attributes\Response; |
22
|
|
|
use OpenApi\Attributes\Schema; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* Class GetByTagAction |
26
|
|
|
* |
27
|
|
|
* |
28
|
|
|
* @group Blog API |
29
|
|
|
* |
30
|
|
|
* @authenticated |
31
|
|
|
* |
32
|
|
|
* @method BaseHttpResponse httpResponse() |
33
|
|
|
* @method BaseHttpResponse setData(mixed $data) |
34
|
|
|
* @method BaseHttpResponse|JsonResource|JsonResponse|RedirectResponse toApiResponse() |
35
|
|
|
*/ |
36
|
|
|
class PostGetByTagAction extends Action |
37
|
|
|
{ |
38
|
|
|
protected PostService $postService; |
39
|
|
|
|
40
|
|
|
public function __construct(PostService $postService) |
41
|
|
|
{ |
42
|
|
|
$this->postService = $postService; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param Request $request |
47
|
|
|
* |
48
|
|
|
* @group Blog |
49
|
|
|
* |
50
|
|
|
* @queryParam Find by tagId of post. |
51
|
|
|
* |
52
|
|
|
* @return BaseHttpResponse|JsonResource|JsonResponse|RedirectResponse |
53
|
|
|
*/ |
54
|
|
|
#[ |
55
|
|
|
Get( |
56
|
|
|
path: "/posts/get-by-tags", |
57
|
|
|
operationId: "postGetByTag", |
58
|
|
|
description: "Get list post of the tag by tag id |
59
|
|
|
|
60
|
|
|
This API will get record from the database and return list post of the tag by tag id. |
61
|
|
|
", |
62
|
|
|
summary: "Get list post of the tag by tag id", |
63
|
|
|
tags: ["Post"], |
64
|
|
|
parameters: [ |
65
|
|
|
new Parameter( |
66
|
|
|
name: 'tags', |
67
|
|
|
description: 'Filter posts by tag specific tag IDs.', |
68
|
|
|
in: 'query', |
69
|
|
|
required: false, |
70
|
|
|
schema: new Schema( |
71
|
|
|
type: 'array', |
72
|
|
|
items: new Items(description: 'Input the exclude tag ID', type: 'integer'), |
73
|
|
|
default: null |
74
|
|
|
) |
75
|
|
|
), |
76
|
|
|
new Parameter( |
77
|
|
|
name: 'per_page', |
78
|
|
|
description: 'Number of items per page', |
79
|
|
|
in: 'query', |
80
|
|
|
required: false, |
81
|
|
|
schema: new Schema(type: 'integer', default: 10) |
82
|
|
|
), |
83
|
|
|
new Parameter( |
84
|
|
|
name: 'page', |
85
|
|
|
description: 'Page number', |
86
|
|
|
in: 'query', |
87
|
|
|
required: false, |
88
|
|
|
schema: new Schema(type: 'integer', default: 1) |
89
|
|
|
), |
90
|
|
|
], |
91
|
|
|
responses: [ |
92
|
|
|
new Response( |
93
|
|
|
response: 200, |
94
|
|
|
description: "Get list posts by tag successfully", |
95
|
|
|
content: new JsonContent( |
96
|
|
|
properties: [ |
97
|
|
|
new Property( |
98
|
|
|
property: 'error', |
99
|
|
|
description: 'Error status', |
100
|
|
|
type: 'boolean', |
101
|
|
|
default: false |
102
|
|
|
), |
103
|
|
|
new Property( |
104
|
|
|
property: "data", |
105
|
|
|
ref: PostModelResourceSchema::class, |
106
|
|
|
description: "Data of model", |
107
|
|
|
type: "object", |
108
|
|
|
), |
109
|
|
|
] |
110
|
|
|
) |
111
|
|
|
), |
112
|
|
|
new Response( |
113
|
|
|
ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\BadRequestResponseSchema::class, |
114
|
|
|
response: 400, |
115
|
|
|
), |
116
|
|
|
new Response( |
117
|
|
|
ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\ErrorNotFoundResponseSchema::class, |
118
|
|
|
response: 404, |
119
|
|
|
), |
120
|
|
|
new Response( |
121
|
|
|
ref: \CSlant\Blog\Api\OpenApi\Responses\Errors\InternalServerResponseSchema::class, |
122
|
|
|
response: 500, |
123
|
|
|
), |
124
|
|
|
] |
125
|
|
|
) |
126
|
|
|
] |
127
|
|
|
public function __invoke(Request $request): BaseHttpResponse|JsonResponse|JsonResource|RedirectResponse |
128
|
|
|
{ |
129
|
|
|
$filters = FilterPost::setFilters($request->input()); |
130
|
|
|
|
131
|
|
|
$data = $this->postService->getFilters((array) $filters); |
132
|
|
|
|
133
|
|
|
return $this |
134
|
|
|
->httpResponse() |
135
|
|
|
->setData(PostResource::collection($data)) |
136
|
|
|
->toApiResponse(); |
137
|
|
|
} |
138
|
|
|
} |
139
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths