@@ 18-130 (lines=113) @@ | ||
15 | * |
|
16 | * @package Finder\Http\Actions |
|
17 | */ |
|
18 | class PostPaginateAction |
|
19 | { |
|
20 | /** |
|
21 | * @var ResponseFactory |
|
22 | */ |
|
23 | private $responseFactory; |
|
24 | ||
25 | /** |
|
26 | * @var PostManager |
|
27 | */ |
|
28 | private $postManager; |
|
29 | ||
30 | /** |
|
31 | * @var CacheManager |
|
32 | */ |
|
33 | private $cacheManager; |
|
34 | ||
35 | /** |
|
36 | * PostPaginateAction constructor. |
|
37 | * |
|
38 | * @param ResponseFactory $responseFactory |
|
39 | * @param PostManager $postManager |
|
40 | * @param CacheManager $cacheManager |
|
41 | */ |
|
42 | public function __construct(ResponseFactory $responseFactory, PostManager $postManager, CacheManager $cacheManager) |
|
43 | { |
|
44 | $this->responseFactory = $responseFactory; |
|
45 | $this->postManager = $postManager; |
|
46 | $this->cacheManager = $cacheManager; |
|
47 | } |
|
48 | ||
49 | /** |
|
50 | * @apiVersion 1.0.0 |
|
51 | * @api {get} /v1/posts?page=:page&per_page=:per_page Paginate |
|
52 | * @apiName Paginate |
|
53 | * @apiGroup Posts |
|
54 | * @apiHeader {String} Accept application/json |
|
55 | * @apiParam {Integer{1..N}} [page=1] |
|
56 | * @apiParam {Integer{1..100}} [per_page=20] |
|
57 | * @apiSuccessExample {json} Success-Response: |
|
58 | * HTTP/1.1 200 OK |
|
59 | * { |
|
60 | * "total": 100, |
|
61 | * "per_page": 10, |
|
62 | * "current_page": 2, |
|
63 | * "last_page": 10, |
|
64 | * "next_page_url": "http://path/to/api/resource?page=3", |
|
65 | * "prev_page_url": "http://path/to/api/resource?page=1", |
|
66 | * "from": 10, |
|
67 | * "to": 20, |
|
68 | * "data": [ |
|
69 | * { |
|
70 | * "id": 1, |
|
71 | * "created_by_user_id": 1, |
|
72 | * "is_published": true, |
|
73 | * "description": "The post description.", |
|
74 | * "published_at": "2099-12-31T23:59:59+00:00", |
|
75 | * "created_at": "2099-12-31T23:59:59+00:00", |
|
76 | * "updated_at": "2099-12-31T23:59:59+00:00", |
|
77 | * "photo": { |
|
78 | * "id": 1, |
|
79 | * "created_by_user_id" 1, |
|
80 | * "avg_color": "#000000", |
|
81 | * "created_at": "2099-12-31T23:59:59+00:00", |
|
82 | * "exif": { |
|
83 | * "manufacturer": "Manufacturer Name", |
|
84 | * "model": "Model Number", |
|
85 | * "exposure_time": "1/160", |
|
86 | * "aperture": "f/11.0", |
|
87 | * "iso": 200, |
|
88 | * "taken_at": "2099-12-31T23:59:59+00:00", |
|
89 | * "software": "Software Name" |
|
90 | * }, |
|
91 | * "thumbnails": [ |
|
92 | * "medium": { |
|
93 | * "url": "http://path/to/photo/thumbnail/medium_file" |
|
94 | * "width": 500, |
|
95 | * "height": 500 |
|
96 | * }, |
|
97 | * "large": { |
|
98 | * "url": "http://path/to/photo/thumbnail/large_file" |
|
99 | * "width": 1000, |
|
100 | * "height": 1000 |
|
101 | * } |
|
102 | * ] |
|
103 | * }, |
|
104 | * "tags": [ |
|
105 | * { |
|
106 | * "value": "tag", |
|
107 | * } |
|
108 | * ] |
|
109 | * } |
|
110 | * ] |
|
111 | * } |
|
112 | */ |
|
113 | ||
114 | /** |
|
115 | * Paginate over posts. |
|
116 | * |
|
117 | * @param PaginatedRequest $request |
|
118 | * @return JsonResponse |
|
119 | */ |
|
120 | public function __invoke(PaginatedRequest $request): JsonResponse |
|
121 | { |
|
122 | $posts = $this->postManager->paginate( |
|
123 | $request->get('page', 1), |
|
124 | $request->get('per_page', 20), |
|
125 | $request->all() |
|
126 | ); |
|
127 | ||
128 | return $this->responseFactory->json(new PaginatedResource($posts, PostResource::class), JsonResponse::HTTP_OK); |
|
129 | } |
|
130 | } |
|
131 |
@@ 17-83 (lines=67) @@ | ||
14 | * |
|
15 | * @package Finder\Http\Actions |
|
16 | */ |
|
17 | class SubscriptionPaginateAction |
|
18 | { |
|
19 | /** |
|
20 | * @var ResponseFactory |
|
21 | */ |
|
22 | private $responseFactory; |
|
23 | ||
24 | /** |
|
25 | * @var SubscriptionManager |
|
26 | */ |
|
27 | private $subscriptionManager; |
|
28 | ||
29 | /** |
|
30 | * SubscriptionPaginateAction constructor. |
|
31 | * |
|
32 | * @param ResponseFactory $responseFactory |
|
33 | * @param SubscriptionManager $subscriptionManager |
|
34 | */ |
|
35 | public function __construct(ResponseFactory $responseFactory, SubscriptionManager $subscriptionManager) |
|
36 | { |
|
37 | $this->responseFactory = $responseFactory; |
|
38 | $this->subscriptionManager = $subscriptionManager; |
|
39 | } |
|
40 | ||
41 | /** |
|
42 | * @apiVersion 1.0.0 |
|
43 | * @api {get} /v1/subscriptions?page=:page&per_page=:per_page Paginate |
|
44 | * @apiName Paginate |
|
45 | * @apiGroup Subscriptions |
|
46 | * @apiHeader {String} Accept application/json |
|
47 | * @apiParam {Integer{1..N}} [page=1] |
|
48 | * @apiParam {Integer{1..100}} [per_page=20] |
|
49 | * @apiSuccessExample {json} Success-Response: |
|
50 | * HTTP/1.1 200 OK |
|
51 | * { |
|
52 | * "total": 100, |
|
53 | * "per_page": 10, |
|
54 | * "current_page": 2, |
|
55 | * "last_page": 10, |
|
56 | * "next_page_url": "http://path/to/api/resource?page=3", |
|
57 | * "prev_page_url": "http://path/to/api/resource?page=1", |
|
58 | * "from": 10, |
|
59 | * "to": 20, |
|
60 | * "data": [ |
|
61 | * { |
|
62 | * "email": "[email protected]", |
|
63 | * "token": "subscription_token_string" |
|
64 | * } |
|
65 | * ] |
|
66 | * } |
|
67 | */ |
|
68 | ||
69 | /** |
|
70 | * @param PaginatedRequest $request |
|
71 | * @return JsonResponse |
|
72 | */ |
|
73 | public function __invoke(PaginatedRequest $request): JsonResponse |
|
74 | { |
|
75 | $paginator = $this->subscriptionManager->paginate( |
|
76 | $request->get('page', 1), |
|
77 | $request->get('per_page', 20), |
|
78 | $request->query() |
|
79 | ); |
|
80 | ||
81 | return $this->responseFactory->json(new PaginatedResource($paginator, SubscriptionPlainResource::class), JsonResponse::HTTP_OK); |
|
82 | } |
|
83 | } |
|
84 |
@@ 18-85 (lines=68) @@ | ||
15 | * |
|
16 | * @package Finder\Http\Actions |
|
17 | */ |
|
18 | class TagPaginateAction |
|
19 | { |
|
20 | /** |
|
21 | * @var ResponseFactory |
|
22 | */ |
|
23 | private $responseFactory; |
|
24 | ||
25 | /** |
|
26 | * @var TagManager |
|
27 | */ |
|
28 | private $tagManager; |
|
29 | ||
30 | /** |
|
31 | * TagPaginateAction constructor. |
|
32 | * |
|
33 | * @param ResponseFactory $responseFactory |
|
34 | * @param TagManager $tagManager |
|
35 | */ |
|
36 | public function __construct(ResponseFactory $responseFactory, TagManager $tagManager) |
|
37 | { |
|
38 | $this->responseFactory = $responseFactory; |
|
39 | $this->tagManager = $tagManager; |
|
40 | } |
|
41 | ||
42 | /** |
|
43 | * @apiVersion 1.0.0 |
|
44 | * @api {get} /v1/tags?page=:page&per_page=:per_page Paginate |
|
45 | * @apiName Paginate |
|
46 | * @apiGroup Tags |
|
47 | * @apiHeader {String} Accept application/json |
|
48 | * @apiParam {Integer{1..N}} [page=1] |
|
49 | * @apiParam {Integer{1..100}} [per_page=20] |
|
50 | * @apiSuccessExample {json} Success-Response: |
|
51 | * HTTP/1.1 200 OK |
|
52 | * { |
|
53 | * "total": 100, |
|
54 | * "per_page": 10, |
|
55 | * "current_page": 2, |
|
56 | * "last_page": 10, |
|
57 | * "next_page_url": "http://path/to/api/resource?page=3", |
|
58 | * "prev_page_url": "http://path/to/api/resource?page=1", |
|
59 | * "from": 10, |
|
60 | * "to": 20, |
|
61 | * "data": [ |
|
62 | * { |
|
63 | * "value": "tag" |
|
64 | * } |
|
65 | * ] |
|
66 | * } |
|
67 | */ |
|
68 | ||
69 | /** |
|
70 | * Paginate over tags. |
|
71 | * |
|
72 | * @param PaginatedRequest $request |
|
73 | * @return JsonResponse |
|
74 | */ |
|
75 | public function __invoke(PaginatedRequest $request): JsonResponse |
|
76 | { |
|
77 | $paginator = $this->tagManager->paginate( |
|
78 | $request->get('page', 1), |
|
79 | $request->get('per_page', 20), |
|
80 | $request->query() |
|
81 | ); |
|
82 | ||
83 | return $this->responseFactory->json(new PaginatedResource($paginator, TagPlainResource::class), Response::HTTP_OK); |
|
84 | } |
|
85 | } |
|
86 |