-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUpvoteController.php
More file actions
39 lines (30 loc) · 927 Bytes
/
UpvoteController.php
File metadata and controls
39 lines (30 loc) · 927 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
<?php
namespace App\Http\Controllers;
use App\Services\UpvoteService;
class UpvoteController extends Controller
{
public function __construct(protected UpvoteService $upvoteService) {}
/**
* Upvote a Model
*/
public function upvote($typeKey, $id)
{
$result = $this->upvoteService->upvote($typeKey, $id);
if (isset($result['error'])) {
return response()->json(['message' => $result['error']], $result['status']);
}
return response()->json($result);
}
/**
* Downvote a Model (type, id)
*/
public function downvote($typeKey, $id)
{
$result = $this->upvoteService->downvote($typeKey, $id);
// TODO: REFACTOR TO EXCEPTIONS
if (isset($result['error'])) {
return response()->json(['message' => $result['error']], $result['status']);
}
return response()->json($result);
}
}