1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace App\Http\Controllers; |
4
|
|
|
|
5
|
|
|
use App\Facades\User as UserFacade; |
6
|
|
|
use App\Models\Photo; |
7
|
|
|
use App\Models\PhotoLike; |
8
|
|
|
use App\Models\PhotoReport; |
9
|
|
|
use Illuminate\Http\JsonResponse; |
10
|
|
|
use Illuminate\Http\Request; |
11
|
|
|
use Illuminate\Http\Response; |
12
|
|
|
use Laravel\Lumen\Routing\Controller as BaseController; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* Class PhotosController. |
16
|
|
|
*/ |
17
|
|
|
class PhotosController extends BaseController |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Render a set of Public HabboWEB Photos. |
21
|
|
|
* |
22
|
|
|
* @TODO: Exclude Approved Reported Photos from the List |
23
|
|
|
* |
24
|
|
|
* @return JsonResponse |
25
|
|
|
*/ |
26
|
|
|
public function show(): JsonResponse |
27
|
|
|
{ |
28
|
|
|
return response()->json(Photo::all(), 200, [], JSON_UNESCAPED_SLASHES); |
|
|
|
|
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Register a Report of a Photo |
33
|
|
|
* Observation.: We will not create a limit of max reports. |
34
|
|
|
* Since it's a retro we don't really care about reports. |
35
|
|
|
* |
36
|
|
|
* @MODERATION: Reporting Status (0 = Not Reviewed, 1 = Report Approved, 2 = Report Not Approved |
37
|
|
|
* |
38
|
|
|
* @param Request $request |
39
|
|
|
* @param int $photoId |
40
|
|
|
* |
41
|
|
|
* @return Response |
42
|
|
|
*/ |
43
|
|
|
public function report(Request $request, int $photoId): Response |
44
|
|
|
{ |
45
|
|
|
(new PhotoReport())->store($photoId, $request->json()->get('reason'), UserFacade::getUser()->uniqueId); |
46
|
|
|
|
47
|
|
|
return response(null); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Like a Photo. |
52
|
|
|
* |
53
|
|
|
* @param int $photoId |
54
|
|
|
* |
55
|
|
|
* @return Response |
56
|
|
|
*/ |
57
|
|
|
public function likePhoto(int $photoId): Response |
58
|
|
|
{ |
59
|
|
|
if (PhotoLike::where('username', UserFacade::getUser()->name)->where('photo_id', $photoId)->count() > 0) { |
60
|
|
|
return response(null); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
(new PhotoLike())->store($photoId, UserFacade::getUser()->name); |
64
|
|
|
|
65
|
|
|
return response(null); |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* Unlike a Photo. |
70
|
|
|
* |
71
|
|
|
* @param int $photoId |
72
|
|
|
* |
73
|
|
|
* @return Response |
74
|
|
|
*/ |
75
|
|
|
public function unlikePhoto(int $photoId): Response |
76
|
|
|
{ |
77
|
|
|
if (PhotoLike::where('username', UserFacade::getUser()->name)->where('photo_id', $photoId)->count() == 0) { |
78
|
|
|
return response(null); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
PhotoLike::where('username', UserFacade::getUser()->name)->where('photo_id', $photoId)->delete(); |
82
|
|
|
|
83
|
|
|
return response(null); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
/** |
87
|
|
|
* Delete a Photo. |
88
|
|
|
* |
89
|
|
|
* @param int $photoId |
90
|
|
|
* |
91
|
|
|
* @return Response |
92
|
|
|
*/ |
93
|
|
|
public function delete(int $photoId): Response |
94
|
|
|
{ |
95
|
|
|
$photo = Photo::find($photoId); |
96
|
|
|
|
97
|
|
|
if ($photo == null || $photo->creator_id != UserFacade::getUser()->uniqueId) { |
98
|
|
|
return response(null, 401); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
$photo->delete(); |
102
|
|
|
|
103
|
|
|
return response(null); |
104
|
|
|
} |
105
|
|
|
} |
106
|
|
|
|
This check looks at variables that are passed out again to other methods.
If the outgoing method call has stricter type requirements than the method itself, an issue is raised.
An additional type check may prevent trouble.