|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Finder\Http\Actions; |
|
4
|
|
|
|
|
5
|
|
|
use Finder\Http\Resources\PhotoResource; |
|
6
|
|
|
use Population\Manipule\Managers\PhotoManager; |
|
7
|
|
|
use Illuminate\Contracts\Routing\ResponseFactory; |
|
8
|
|
|
use Illuminate\Http\JsonResponse; |
|
9
|
|
|
use Illuminate\Http\Request; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* Class PhotoUpdateByIdAction. |
|
13
|
|
|
* |
|
14
|
|
|
* @package Finder\Http\Actions |
|
15
|
|
|
*/ |
|
16
|
|
|
class PhotoUpdateByIdAction |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @var ResponseFactory |
|
20
|
|
|
*/ |
|
21
|
|
|
private $responseFactory; |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @var PhotoManager |
|
25
|
|
|
*/ |
|
26
|
|
|
private $photoManager; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* PhotoUpdateByIdAction constructor. |
|
30
|
|
|
* |
|
31
|
|
|
* @param ResponseFactory $responseFactory |
|
32
|
|
|
* @param PhotoManager $photoManager |
|
33
|
|
|
*/ |
|
34
|
|
|
public function __construct(ResponseFactory $responseFactory, PhotoManager $photoManager) |
|
35
|
|
|
{ |
|
36
|
|
|
$this->responseFactory = $responseFactory; |
|
37
|
|
|
$this->photoManager = $photoManager; |
|
38
|
|
|
} |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* @apiVersion 1.0.0 |
|
42
|
|
|
* @api {put} /v1/photos/:photo_id Update |
|
43
|
|
|
* @apiName Update |
|
44
|
|
|
* @apiGroup Photos |
|
45
|
|
|
* @apiHeader {String} Accept application/json |
|
46
|
|
|
* @apiHeader {String} Content-type multipart/form-data |
|
47
|
|
|
* @apiParam {Integer{1..N}} :photo_id Unique resource ID. |
|
48
|
|
|
* @apiParam {Object} location Photo location. |
|
49
|
|
|
* @apiParam {Number{-90-90}} location.latitude Photo location latitude. |
|
50
|
|
|
* @apiParam {Number{-180-180}} location.longitude Photo location longitude. |
|
51
|
|
|
* @apiSuccessExample {json} Success-Response: |
|
52
|
|
|
* HTTP/1.1 200 OK |
|
53
|
|
|
* { |
|
54
|
|
|
* "id": 1, |
|
55
|
|
|
* "created_by_user_id" 1, |
|
56
|
|
|
* "avg_color": "#000000", |
|
57
|
|
|
* "created_at": "2099-12-31T23:59:59+00:00", |
|
58
|
|
|
* "location": { |
|
59
|
|
|
* "latitude": 49.85, |
|
60
|
|
|
* "longitude": 24.0166666667 |
|
61
|
|
|
* } |
|
62
|
|
|
* "exif": { |
|
63
|
|
|
* "manufacturer": "Manufacturer Name", |
|
64
|
|
|
* "model": "Model Number", |
|
65
|
|
|
* "exposure_time": "1/160", |
|
66
|
|
|
* "aperture": "f/11.0", |
|
67
|
|
|
* "iso": 200, |
|
68
|
|
|
* "taken_at": "2099-12-31T23:59:59+00:00", |
|
69
|
|
|
* "software": "Software Name" |
|
70
|
|
|
* }, |
|
71
|
|
|
* "thumbnails": [ |
|
72
|
|
|
* "medium": { |
|
73
|
|
|
* "url": "http://path/to/photo/thumbnail/medium_file" |
|
74
|
|
|
* "width": 500, |
|
75
|
|
|
* "height": 500 |
|
76
|
|
|
* }, |
|
77
|
|
|
* "large": { |
|
78
|
|
|
* "url": "http://path/to/photo/thumbnail/large_file" |
|
79
|
|
|
* "width": 1000, |
|
80
|
|
|
* "height": 1000 |
|
81
|
|
|
* } |
|
82
|
|
|
* ] |
|
83
|
|
|
* } |
|
84
|
|
|
*/ |
|
85
|
|
|
|
|
86
|
|
|
/** |
|
87
|
|
|
* Update a photo. |
|
88
|
|
|
* |
|
89
|
|
|
* @param mixed $id |
|
90
|
|
|
* @param Request $request |
|
91
|
|
|
* @return JsonResponse |
|
92
|
|
|
*/ |
|
93
|
|
|
public function __invoke($id, Request $request): JsonResponse |
|
94
|
|
|
{ |
|
95
|
|
|
$photo = $this->photoManager->updateById((int) $id, $request->all()); |
|
96
|
|
|
|
|
97
|
|
|
return $this->responseFactory->json(new PhotoResource($photo), JsonResponse::HTTP_OK); |
|
98
|
|
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|