|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Finder\Http\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Finder\Http\Resources\PostResource; |
|
6
|
|
|
use Population\Manipule\Managers\PostManager; |
|
7
|
|
|
use Illuminate\Contracts\Cache\Factory as CacheManager; |
|
8
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory; |
|
9
|
|
|
use Illuminate\Http\JsonResponse; |
|
10
|
|
|
use Illuminate\Http\Request; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class PostGetAfterIdAction. |
|
14
|
|
|
* |
|
15
|
|
|
* @package Finder\Http\Actions |
|
16
|
|
|
*/ |
|
17
|
|
|
class PostGetAfterIdAction |
|
18
|
|
|
{ |
|
19
|
|
|
/** |
|
20
|
|
|
* @var ResponseFactory |
|
21
|
|
|
*/ |
|
22
|
|
|
private $responseFactory; |
|
23
|
|
|
|
|
24
|
|
|
/** |
|
25
|
|
|
* @var PostManager |
|
26
|
|
|
*/ |
|
27
|
|
|
private $postManager; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @var CacheManager |
|
31
|
|
|
*/ |
|
32
|
|
|
private $cacheManager; |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* PostGetAfterIdAction constructor. |
|
36
|
|
|
* |
|
37
|
|
|
* @param ResponseFactory $responseFactory |
|
38
|
|
|
* @param PostManager $postManager |
|
39
|
|
|
* @param CacheManager $cacheManager |
|
40
|
|
|
*/ |
|
41
|
|
|
public function __construct(ResponseFactory $responseFactory, PostManager $postManager, CacheManager $cacheManager) |
|
42
|
|
|
{ |
|
43
|
|
|
$this->responseFactory = $responseFactory; |
|
44
|
|
|
$this->postManager = $postManager; |
|
45
|
|
|
$this->cacheManager = $cacheManager; |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* @apiVersion 1.0.0 |
|
50
|
|
|
* @api {get} /v1/posts/:post_id/next Get Next |
|
51
|
|
|
* @apiName Get Next |
|
52
|
|
|
* @apiGroup Posts |
|
53
|
|
|
* @apiHeader {String} Accept application/json |
|
54
|
|
|
* @apiParam {Integer{1..N}} :post_id Unique resource ID. |
|
55
|
|
|
* @apiSuccessExample {json} Success-Response: |
|
56
|
|
|
* HTTP/1.1 201 Created |
|
57
|
|
|
* { |
|
58
|
|
|
* "id": 1, |
|
59
|
|
|
* "created_by_user_id": 1, |
|
60
|
|
|
* "is_published": true, |
|
61
|
|
|
* "description": "The post description.", |
|
62
|
|
|
* "published_at": "2099-12-31T23:59:59+00:00", |
|
63
|
|
|
* "created_at": "2099-12-31T23:59:59+00:00", |
|
64
|
|
|
* "updated_at": "2099-12-31T23:59:59+00:00", |
|
65
|
|
|
* "photo": { |
|
66
|
|
|
* "id": 1, |
|
67
|
|
|
* "created_by_user_id" 1, |
|
68
|
|
|
* "avg_color": "#000000", |
|
69
|
|
|
* "created_at": "2099-12-31T23:59:59+00:00", |
|
70
|
|
|
* "exif": { |
|
71
|
|
|
* "manufacturer": "Manufacturer Name", |
|
72
|
|
|
* "model": "Model Number", |
|
73
|
|
|
* "exposure_time": "1/160", |
|
74
|
|
|
* "aperture": "f/11.0", |
|
75
|
|
|
* "iso": 200, |
|
76
|
|
|
* "taken_at": "2099-12-31T23:59:59+00:00", |
|
77
|
|
|
* "software": "Software Name" |
|
78
|
|
|
* }, |
|
79
|
|
|
* "thumbnails": [ |
|
80
|
|
|
* "medium": { |
|
81
|
|
|
* "url": "http://path/to/photo/thumbnail/medium_file" |
|
82
|
|
|
* "width": 500, |
|
83
|
|
|
* "height": 500 |
|
84
|
|
|
* }, |
|
85
|
|
|
* "large": { |
|
86
|
|
|
* "url": "http://path/to/photo/thumbnail/large_file" |
|
87
|
|
|
* "width": 1000, |
|
88
|
|
|
* "height": 1000 |
|
89
|
|
|
* } |
|
90
|
|
|
* ] |
|
91
|
|
|
* }, |
|
92
|
|
|
* "tags": [ |
|
93
|
|
|
* { |
|
94
|
|
|
* "value": "tag", |
|
95
|
|
|
* } |
|
96
|
|
|
* ] |
|
97
|
|
|
* } |
|
98
|
|
|
*/ |
|
99
|
|
|
|
|
100
|
|
|
/** |
|
101
|
|
|
* Get next post. |
|
102
|
|
|
* |
|
103
|
|
|
* @param mixed $id |
|
104
|
|
|
* @param Request $request |
|
105
|
|
|
* @return JsonResponse |
|
106
|
|
|
*/ |
|
107
|
|
|
public function __invoke($id, Request $request): JsonResponse |
|
108
|
|
|
{ |
|
109
|
|
|
$post = $this->postManager->getAfterId((int) $id, $request->all()); |
|
110
|
|
|
|
|
111
|
|
|
return $this->responseFactory->json(new PostResource($post), JsonResponse::HTTP_OK); |
|
112
|
|
|
} |
|
113
|
|
|
} |
|
114
|
|
|
|