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