@@ 17-127 (lines=111) @@ | ||
14 | * |
|
15 | * @package Finder\Http\Actions |
|
16 | */ |
|
17 | class PostCreateAction |
|
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 | * PostCreateAction 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 {post} /v1/posts Create |
|
51 | * @apiName Create |
|
52 | * @apiGroup Posts |
|
53 | * @apiHeader {String} Accept application/json |
|
54 | * @apiHeader {String} Content-type application/json |
|
55 | * @apiParamExample {json} Request-Body-Example: |
|
56 | * { |
|
57 | * "is_published": true, |
|
58 | * "description": "The post description.", |
|
59 | * "photo": { |
|
60 | * "id": 1 |
|
61 | * }, |
|
62 | * "tags": [ |
|
63 | * { |
|
64 | * "value": "tag", |
|
65 | * } |
|
66 | * ] |
|
67 | * } |
|
68 | * @apiSuccessExample {json} Success-Response: |
|
69 | * HTTP/1.1 201 Created |
|
70 | * { |
|
71 | * "id": 1, |
|
72 | * "created_by_user_id": 1, |
|
73 | * "is_published": true, |
|
74 | * "description": "The post description.", |
|
75 | * "published_at": "2099-12-31T23:59:59+00:00", |
|
76 | * "created_at": "2099-12-31T23:59:59+00:00", |
|
77 | * "updated_at": "2099-12-31T23:59:59+00:00", |
|
78 | * "photo": { |
|
79 | * "id": 1, |
|
80 | * "created_by_user_id" 1, |
|
81 | * "avg_color": "#000000", |
|
82 | * "created_at": "2099-12-31T23:59:59+00:00", |
|
83 | * "exif": { |
|
84 | * "manufacturer": "Manufacturer Name", |
|
85 | * "model": "Model Number", |
|
86 | * "exposure_time": "1/160", |
|
87 | * "aperture": "f/11.0", |
|
88 | * "iso": 200, |
|
89 | * "taken_at": "2099-12-31T23:59:59+00:00", |
|
90 | * "software": "Software Name" |
|
91 | * }, |
|
92 | * "thumbnails": [ |
|
93 | * "medium": { |
|
94 | * "url": "http://path/to/photo/thumbnail/medium_file" |
|
95 | * "width": 500, |
|
96 | * "height": 500 |
|
97 | * }, |
|
98 | * "large": { |
|
99 | * "url": "http://path/to/photo/thumbnail/large_file" |
|
100 | * "width": 1000, |
|
101 | * "height": 1000 |
|
102 | * } |
|
103 | * ] |
|
104 | * }, |
|
105 | * "tags": [ |
|
106 | * { |
|
107 | * "value": "tag", |
|
108 | * } |
|
109 | * ] |
|
110 | * } |
|
111 | */ |
|
112 | ||
113 | /** |
|
114 | * Create a post. |
|
115 | * |
|
116 | * @param Request $request |
|
117 | * @return JsonResponse |
|
118 | */ |
|
119 | public function __invoke(Request $request): JsonResponse |
|
120 | { |
|
121 | $post = $this->postManager->create($request->all()); |
|
122 | ||
123 | $this->cacheManager->tags(['posts', 'photos', 'tags'])->flush(); |
|
124 | ||
125 | return $this->responseFactory->json(new PostResource($post), JsonResponse::HTTP_CREATED); |
|
126 | } |
|
127 | } |
|
128 |
@@ 17-129 (lines=113) @@ | ||
14 | * |
|
15 | * @package Finder\Http\Actions |
|
16 | */ |
|
17 | class PostUpdateByIdAction |
|
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 | * PostUpdateByIdAction 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 {put} /v1/posts/:post_id Update |
|
51 | * @apiName Update |
|
52 | * @apiGroup Posts |
|
53 | * @apiHeader {String} Accept application/json |
|
54 | * @apiHeader {String} Content-type application/json |
|
55 | * @apiParam {Integer{1..N}} :post_id Unique resource ID. |
|
56 | * @apiParamExample {json} Request-Body-Example: |
|
57 | * { |
|
58 | * "is_published": true, |
|
59 | * "description": "The post description.", |
|
60 | * "photo": { |
|
61 | * "id": 1 |
|
62 | * }, |
|
63 | * "tags": [ |
|
64 | * { |
|
65 | * "value": "tag", |
|
66 | * } |
|
67 | * ] |
|
68 | * } |
|
69 | * @apiSuccessExample {json} Success-Response: |
|
70 | * HTTP/1.1 201 Created |
|
71 | * { |
|
72 | * "id": 1, |
|
73 | * "created_by_user_id": 1, |
|
74 | * "is_published": true, |
|
75 | * "description": "The post description.", |
|
76 | * "published_at": "2099-12-31T23:59:59+00:00", |
|
77 | * "created_at": "2099-12-31T23:59:59+00:00", |
|
78 | * "updated_at": "2099-12-31T23:59:59+00:00", |
|
79 | * "photo": { |
|
80 | * "id": 1, |
|
81 | * "created_by_user_id" 1, |
|
82 | * "avg_color": "#000000", |
|
83 | * "created_at": "2099-12-31T23:59:59+00:00", |
|
84 | * "exif": { |
|
85 | * "manufacturer": "Manufacturer Name", |
|
86 | * "model": "Model Number", |
|
87 | * "exposure_time": "1/160", |
|
88 | * "aperture": "f/11.0", |
|
89 | * "iso": 200, |
|
90 | * "taken_at": "2099-12-31T23:59:59+00:00", |
|
91 | * "software": "Software Name" |
|
92 | * }, |
|
93 | * "thumbnails": [ |
|
94 | * "medium": { |
|
95 | * "url": "http://path/to/photo/thumbnail/medium_file" |
|
96 | * "width": 500, |
|
97 | * "height": 500 |
|
98 | * }, |
|
99 | * "large": { |
|
100 | * "url": "http://path/to/photo/thumbnail/large_file" |
|
101 | * "width": 1000, |
|
102 | * "height": 1000 |
|
103 | * } |
|
104 | * ] |
|
105 | * }, |
|
106 | * "tags": [ |
|
107 | * { |
|
108 | * "value": "tag", |
|
109 | * } |
|
110 | * ] |
|
111 | * } |
|
112 | */ |
|
113 | ||
114 | /** |
|
115 | * Update a post. |
|
116 | * |
|
117 | * @param mixed $id |
|
118 | * @param Request $request |
|
119 | * @return JsonResponse |
|
120 | */ |
|
121 | public function __invoke($id, Request $request): JsonResponse |
|
122 | { |
|
123 | $post = $this->postManager->updateById((int) $id, $request->all()); |
|
124 | ||
125 | $this->cacheManager->tags(['posts', 'photos', 'tags'])->flush(); |
|
126 | ||
127 | return $this->responseFactory->json(new PostResource($post), JsonResponse::HTTP_OK); |
|
128 | } |
|
129 | } |
|
130 |