@@ -7,95 +7,95 @@ |
||
7 | 7 | |
8 | 8 | class PostCommentController extends Controller{ |
9 | 9 | |
10 | - public function __construct(){ |
|
10 | + public function __construct(){ |
|
11 | 11 | |
12 | - $this->middleware('oauth', ['except' => ['index', 'show']]); |
|
13 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]); |
|
14 | - } |
|
12 | + $this->middleware('oauth', ['except' => ['index', 'show']]); |
|
13 | + $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]); |
|
14 | + } |
|
15 | 15 | |
16 | - public function index($post_id){ |
|
16 | + public function index($post_id){ |
|
17 | 17 | |
18 | - $post = Post::find($post_id); |
|
18 | + $post = Post::find($post_id); |
|
19 | 19 | |
20 | - if(!$post){ |
|
21 | - return $this->error("The post with {$post_id} doesn't exist", 404); |
|
22 | - } |
|
20 | + if(!$post){ |
|
21 | + return $this->error("The post with {$post_id} doesn't exist", 404); |
|
22 | + } |
|
23 | 23 | |
24 | - $comments = $post->comments; |
|
25 | - return $this->success($comments, 200); |
|
26 | - } |
|
24 | + $comments = $post->comments; |
|
25 | + return $this->success($comments, 200); |
|
26 | + } |
|
27 | 27 | |
28 | - public function store(Request $request, $post_id){ |
|
28 | + public function store(Request $request, $post_id){ |
|
29 | 29 | |
30 | - $post = Post::find($post_id); |
|
30 | + $post = Post::find($post_id); |
|
31 | 31 | |
32 | - if(!$post){ |
|
33 | - return $this->error("The post with {$post_id} doesn't exist", 404); |
|
34 | - } |
|
32 | + if(!$post){ |
|
33 | + return $this->error("The post with {$post_id} doesn't exist", 404); |
|
34 | + } |
|
35 | 35 | |
36 | - $this->validateRequest($request); |
|
36 | + $this->validateRequest($request); |
|
37 | 37 | |
38 | - $comment = Comment::create([ |
|
39 | - 'content' => $request->get('content'), |
|
40 | - 'user_id'=> $this->getUserId(), |
|
41 | - 'post_id'=> $post_id |
|
42 | - ]); |
|
38 | + $comment = Comment::create([ |
|
39 | + 'content' => $request->get('content'), |
|
40 | + 'user_id'=> $this->getUserId(), |
|
41 | + 'post_id'=> $post_id |
|
42 | + ]); |
|
43 | 43 | |
44 | - return $this->success("The comment with id {$comment->id} has been created and assigned to the post with id {$post_id}", 201); |
|
45 | - } |
|
44 | + return $this->success("The comment with id {$comment->id} has been created and assigned to the post with id {$post_id}", 201); |
|
45 | + } |
|
46 | 46 | |
47 | - public function update(Request $request, $post_id, $comment_id){ |
|
47 | + public function update(Request $request, $post_id, $comment_id){ |
|
48 | 48 | |
49 | - $comment = Comment::find($comment_id); |
|
50 | - $post = Post::find($post_id); |
|
49 | + $comment = Comment::find($comment_id); |
|
50 | + $post = Post::find($post_id); |
|
51 | 51 | |
52 | - if(!$comment || !$post){ |
|
53 | - return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
|
54 | - } |
|
52 | + if(!$comment || !$post){ |
|
53 | + return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
|
54 | + } |
|
55 | 55 | |
56 | - $this->validateRequest($request); |
|
56 | + $this->validateRequest($request); |
|
57 | 57 | |
58 | - $comment->content = $request->get('content'); |
|
59 | - $comment->user_id = $this->getUserId(); |
|
60 | - $comment->post_id = $post_id; |
|
58 | + $comment->content = $request->get('content'); |
|
59 | + $comment->user_id = $this->getUserId(); |
|
60 | + $comment->post_id = $post_id; |
|
61 | 61 | |
62 | - $comment->save(); |
|
62 | + $comment->save(); |
|
63 | 63 | |
64 | - return $this->success("The comment with with id {$comment->id} has been updated", 200); |
|
65 | - } |
|
64 | + return $this->success("The comment with with id {$comment->id} has been updated", 200); |
|
65 | + } |
|
66 | 66 | |
67 | - public function destroy($post_id, $comment_id){ |
|
67 | + public function destroy($post_id, $comment_id){ |
|
68 | 68 | |
69 | - $comment = Comment::find($comment_id); |
|
70 | - $post = Post::find($post_id); |
|
69 | + $comment = Comment::find($comment_id); |
|
70 | + $post = Post::find($post_id); |
|
71 | 71 | |
72 | - if(!$comment || !$post){ |
|
73 | - return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
|
74 | - } |
|
72 | + if(!$comment || !$post){ |
|
73 | + return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
|
74 | + } |
|
75 | 75 | |
76 | - if(!$post->comments()->find($comment_id)){ |
|
77 | - return $this->error("The comment with id {$comment_id} isn't assigned to the post with id {$post_id}", 409); |
|
78 | - } |
|
76 | + if(!$post->comments()->find($comment_id)){ |
|
77 | + return $this->error("The comment with id {$comment_id} isn't assigned to the post with id {$post_id}", 409); |
|
78 | + } |
|
79 | 79 | |
80 | - $comment->delete(); |
|
80 | + $comment->delete(); |
|
81 | 81 | |
82 | - return $this->success("The comment with id {$comment_id} has been removed of the post {$post_id}", 200); |
|
83 | - } |
|
82 | + return $this->success("The comment with id {$comment_id} has been removed of the post {$post_id}", 200); |
|
83 | + } |
|
84 | 84 | |
85 | - public function validateRequest(Request $request){ |
|
85 | + public function validateRequest(Request $request){ |
|
86 | 86 | |
87 | - $rules = [ |
|
88 | - 'content' => 'required' |
|
89 | - ]; |
|
87 | + $rules = [ |
|
88 | + 'content' => 'required' |
|
89 | + ]; |
|
90 | 90 | |
91 | - $this->validate($request, $rules); |
|
92 | - } |
|
91 | + $this->validate($request, $rules); |
|
92 | + } |
|
93 | 93 | |
94 | - public function isAuthorized(Request $request){ |
|
94 | + public function isAuthorized(Request $request){ |
|
95 | 95 | |
96 | - $resource = "comments"; |
|
97 | - $comment = Comment::find($this->getArgs($request)["comment_id"]); |
|
96 | + $resource = "comments"; |
|
97 | + $comment = Comment::find($this->getArgs($request)["comment_id"]); |
|
98 | 98 | |
99 | - return $this->authorizeUser($request, $resource, $comment); |
|
100 | - } |
|
99 | + return $this->authorizeUser($request, $resource, $comment); |
|
100 | + } |
|
101 | 101 | } |
102 | 102 | \ No newline at end of file |
@@ -7,7 +7,6 @@ |
||
7 | 7 | use Illuminate\Database\Eloquent\Model; |
8 | 8 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
9 | 9 | use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
10 | - |
|
11 | 10 | use Illuminate\Support\Facades\Hash; |
12 | 11 | |
13 | 12 | class User extends Model implements AuthenticatableContract, AuthorizableContract{ |
@@ -7,19 +7,19 @@ discard block |
||
7 | 7 | |
8 | 8 | use Illuminate\Http\Request; |
9 | 9 | |
10 | -class PostCommentController extends Controller{ |
|
10 | +class PostCommentController extends Controller { |
|
11 | 11 | |
12 | - public function __construct(){ |
|
12 | + public function __construct() { |
|
13 | 13 | |
14 | 14 | $this->middleware('oauth', ['except' => ['index', 'show']]); |
15 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]); |
|
15 | + $this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show', 'store']]); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function index($post_id){ |
|
18 | + public function index($post_id) { |
|
19 | 19 | |
20 | 20 | $post = Post::find($post_id); |
21 | 21 | |
22 | - if(!$post){ |
|
22 | + if (!$post) { |
|
23 | 23 | return $this->error("The post with {$post_id} doesn't exist", 404); |
24 | 24 | } |
25 | 25 | |
@@ -27,11 +27,11 @@ discard block |
||
27 | 27 | return $this->success($comments, 200); |
28 | 28 | } |
29 | 29 | |
30 | - public function store(Request $request, $post_id){ |
|
30 | + public function store(Request $request, $post_id) { |
|
31 | 31 | |
32 | 32 | $post = Post::find($post_id); |
33 | 33 | |
34 | - if(!$post){ |
|
34 | + if (!$post) { |
|
35 | 35 | return $this->error("The post with {$post_id} doesn't exist", 404); |
36 | 36 | } |
37 | 37 | |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | return $this->success("The comment with id {$comment->id} has been created and assigned to the post with id {$post_id}", 201); |
47 | 47 | } |
48 | 48 | |
49 | - public function update(Request $request, $post_id, $comment_id){ |
|
49 | + public function update(Request $request, $post_id, $comment_id) { |
|
50 | 50 | |
51 | - $comment = Comment::find($comment_id); |
|
52 | - $post = Post::find($post_id); |
|
51 | + $comment = Comment::find($comment_id); |
|
52 | + $post = Post::find($post_id); |
|
53 | 53 | |
54 | - if(!$comment || !$post){ |
|
54 | + if (!$comment || !$post) { |
|
55 | 55 | return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
56 | 56 | } |
57 | 57 | |
@@ -66,16 +66,16 @@ discard block |
||
66 | 66 | return $this->success("The comment with with id {$comment->id} has been updated", 200); |
67 | 67 | } |
68 | 68 | |
69 | - public function destroy($post_id, $comment_id){ |
|
69 | + public function destroy($post_id, $comment_id) { |
|
70 | 70 | |
71 | - $comment = Comment::find($comment_id); |
|
72 | - $post = Post::find($post_id); |
|
71 | + $comment = Comment::find($comment_id); |
|
72 | + $post = Post::find($post_id); |
|
73 | 73 | |
74 | - if(!$comment || !$post){ |
|
74 | + if (!$comment || !$post) { |
|
75 | 75 | return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404); |
76 | 76 | } |
77 | 77 | |
78 | - if(!$post->comments()->find($comment_id)){ |
|
78 | + if (!$post->comments()->find($comment_id)) { |
|
79 | 79 | return $this->error("The comment with id {$comment_id} isn't assigned to the post with id {$post_id}", 409); |
80 | 80 | } |
81 | 81 | |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | return $this->success("The comment with id {$comment_id} has been removed of the post {$post_id}", 200); |
85 | 85 | } |
86 | 86 | |
87 | - public function validateRequest(Request $request){ |
|
87 | + public function validateRequest(Request $request) { |
|
88 | 88 | |
89 | 89 | $rules = [ |
90 | 90 | 'content' => 'required' |
@@ -93,7 +93,7 @@ discard block |
||
93 | 93 | $this->validate($request, $rules); |
94 | 94 | } |
95 | 95 | |
96 | - public function isAuthorized(Request $request){ |
|
96 | + public function isAuthorized(Request $request) { |
|
97 | 97 | |
98 | 98 | $resource = "comments"; |
99 | 99 | $comment = Comment::find($this->getArgs($request)["comment_id"]); |
@@ -7,87 +7,87 @@ |
||
7 | 7 | |
8 | 8 | class UserController extends Controller{ |
9 | 9 | |
10 | - public function __construct(){ |
|
10 | + public function __construct(){ |
|
11 | 11 | |
12 | - $this->middleware('oauth', ['except' => ['index', 'show']]); |
|
13 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show']]); |
|
14 | - } |
|
12 | + $this->middleware('oauth', ['except' => ['index', 'show']]); |
|
13 | + $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show']]); |
|
14 | + } |
|
15 | 15 | |
16 | - public function index(){ |
|
16 | + public function index(){ |
|
17 | 17 | |
18 | - $users = User::all(); |
|
19 | - return $this->success($users, 200); |
|
20 | - } |
|
18 | + $users = User::all(); |
|
19 | + return $this->success($users, 200); |
|
20 | + } |
|
21 | 21 | |
22 | - public function store(Request $request){ |
|
22 | + public function store(Request $request){ |
|
23 | 23 | |
24 | - $this->validateRequest($request); |
|
24 | + $this->validateRequest($request); |
|
25 | 25 | |
26 | - $user = User::create([ |
|
27 | - 'email' => $request->get('email'), |
|
28 | - 'password'=> Hash::make($request->get('password')) |
|
29 | - ]); |
|
26 | + $user = User::create([ |
|
27 | + 'email' => $request->get('email'), |
|
28 | + 'password'=> Hash::make($request->get('password')) |
|
29 | + ]); |
|
30 | 30 | |
31 | - return $this->success("The user with with id {$user->id} has been created", 201); |
|
32 | - } |
|
31 | + return $this->success("The user with with id {$user->id} has been created", 201); |
|
32 | + } |
|
33 | 33 | |
34 | - public function show($id){ |
|
34 | + public function show($id){ |
|
35 | 35 | |
36 | - $user = User::find($id); |
|
36 | + $user = User::find($id); |
|
37 | 37 | |
38 | - if(!$user){ |
|
39 | - return $this->error("The user with {$id} doesn't exist", 404); |
|
40 | - } |
|
38 | + if(!$user){ |
|
39 | + return $this->error("The user with {$id} doesn't exist", 404); |
|
40 | + } |
|
41 | 41 | |
42 | - return $this->success($user, 200); |
|
43 | - } |
|
42 | + return $this->success($user, 200); |
|
43 | + } |
|
44 | 44 | |
45 | - public function update(Request $request, $id){ |
|
45 | + public function update(Request $request, $id){ |
|
46 | 46 | |
47 | - $user = User::find($id); |
|
47 | + $user = User::find($id); |
|
48 | 48 | |
49 | - if(!$user){ |
|
50 | - return $this->error("The user with {$id} doesn't exist", 404); |
|
51 | - } |
|
49 | + if(!$user){ |
|
50 | + return $this->error("The user with {$id} doesn't exist", 404); |
|
51 | + } |
|
52 | 52 | |
53 | - $this->validateRequest($request); |
|
53 | + $this->validateRequest($request); |
|
54 | 54 | |
55 | - $user->email = $request->get('email'); |
|
56 | - $user->password = Hash::make($request->get('password')); |
|
55 | + $user->email = $request->get('email'); |
|
56 | + $user->password = Hash::make($request->get('password')); |
|
57 | 57 | |
58 | - $user->save(); |
|
58 | + $user->save(); |
|
59 | 59 | |
60 | - return $this->success("The user with with id {$user->id} has been updated", 200); |
|
61 | - } |
|
60 | + return $this->success("The user with with id {$user->id} has been updated", 200); |
|
61 | + } |
|
62 | 62 | |
63 | - public function destroy($id){ |
|
63 | + public function destroy($id){ |
|
64 | 64 | |
65 | - $user = User::find($id); |
|
65 | + $user = User::find($id); |
|
66 | 66 | |
67 | - if(!$user){ |
|
68 | - return $this->error("The user with {$id} doesn't exist", 404); |
|
69 | - } |
|
67 | + if(!$user){ |
|
68 | + return $this->error("The user with {$id} doesn't exist", 404); |
|
69 | + } |
|
70 | 70 | |
71 | - $user->delete(); |
|
71 | + $user->delete(); |
|
72 | 72 | |
73 | - return $this->success("The user with with id {$id} has been deleted", 200); |
|
74 | - } |
|
73 | + return $this->success("The user with with id {$id} has been deleted", 200); |
|
74 | + } |
|
75 | 75 | |
76 | - public function validateRequest(Request $request){ |
|
76 | + public function validateRequest(Request $request){ |
|
77 | 77 | |
78 | - $rules = [ |
|
79 | - 'email' => 'required|email|unique:users', |
|
80 | - 'password' => 'required|min:6' |
|
81 | - ]; |
|
78 | + $rules = [ |
|
79 | + 'email' => 'required|email|unique:users', |
|
80 | + 'password' => 'required|min:6' |
|
81 | + ]; |
|
82 | 82 | |
83 | - $this->validate($request, $rules); |
|
84 | - } |
|
83 | + $this->validate($request, $rules); |
|
84 | + } |
|
85 | 85 | |
86 | - public function isAuthorized(Request $request){ |
|
86 | + public function isAuthorized(Request $request){ |
|
87 | 87 | |
88 | - $resource = "users"; |
|
89 | - // $user = User::find($this->getArgs($request)["user_id"]); |
|
88 | + $resource = "users"; |
|
89 | + // $user = User::find($this->getArgs($request)["user_id"]); |
|
90 | 90 | |
91 | - return $this->authorizeUser($request, $resource); |
|
92 | - } |
|
91 | + return $this->authorizeUser($request, $resource); |
|
92 | + } |
|
93 | 93 | } |
94 | 94 | \ No newline at end of file |
@@ -7,7 +7,6 @@ |
||
7 | 7 | use Illuminate\Database\Eloquent\Model; |
8 | 8 | use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract; |
9 | 9 | use Illuminate\Contracts\Auth\Access\Authorizable as AuthorizableContract; |
10 | - |
|
11 | 10 | use Illuminate\Support\Facades\Hash; |
12 | 11 | |
13 | 12 | class User extends Model implements AuthenticatableContract, AuthorizableContract{ |
@@ -7,21 +7,21 @@ discard block |
||
7 | 7 | use Illuminate\Http\Request; |
8 | 8 | use Illuminate\Support\Facades\Hash; |
9 | 9 | |
10 | -class UserController extends Controller{ |
|
10 | +class UserController extends Controller { |
|
11 | 11 | |
12 | - public function __construct(){ |
|
12 | + public function __construct() { |
|
13 | 13 | |
14 | 14 | $this->middleware('oauth', ['except' => ['index', 'show']]); |
15 | - $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show']]); |
|
15 | + $this->middleware('authorize:'.__CLASS__, ['except' => ['index', 'show']]); |
|
16 | 16 | } |
17 | 17 | |
18 | - public function index(){ |
|
18 | + public function index() { |
|
19 | 19 | |
20 | 20 | $users = User::all(); |
21 | 21 | return $this->success($users, 200); |
22 | 22 | } |
23 | 23 | |
24 | - public function store(Request $request){ |
|
24 | + public function store(Request $request) { |
|
25 | 25 | |
26 | 26 | $this->validateRequest($request); |
27 | 27 | |
@@ -33,40 +33,40 @@ discard block |
||
33 | 33 | return $this->success("The user with with id {$user->id} has been created", 201); |
34 | 34 | } |
35 | 35 | |
36 | - public function show($id){ |
|
36 | + public function show($id) { |
|
37 | 37 | |
38 | 38 | $user = User::find($id); |
39 | 39 | |
40 | - if(!$user){ |
|
40 | + if (!$user) { |
|
41 | 41 | return $this->error("The user with {$id} doesn't exist", 404); |
42 | 42 | } |
43 | 43 | |
44 | 44 | return $this->success($user, 200); |
45 | 45 | } |
46 | 46 | |
47 | - public function update(Request $request, $id){ |
|
47 | + public function update(Request $request, $id) { |
|
48 | 48 | |
49 | 49 | $user = User::find($id); |
50 | 50 | |
51 | - if(!$user){ |
|
51 | + if (!$user) { |
|
52 | 52 | return $this->error("The user with {$id} doesn't exist", 404); |
53 | 53 | } |
54 | 54 | |
55 | 55 | $this->validateRequest($request); |
56 | 56 | |
57 | - $user->email = $request->get('email'); |
|
58 | - $user->password = Hash::make($request->get('password')); |
|
57 | + $user->email = $request->get('email'); |
|
58 | + $user->password = Hash::make($request->get('password')); |
|
59 | 59 | |
60 | 60 | $user->save(); |
61 | 61 | |
62 | 62 | return $this->success("The user with with id {$user->id} has been updated", 200); |
63 | 63 | } |
64 | 64 | |
65 | - public function destroy($id){ |
|
65 | + public function destroy($id) { |
|
66 | 66 | |
67 | 67 | $user = User::find($id); |
68 | 68 | |
69 | - if(!$user){ |
|
69 | + if (!$user) { |
|
70 | 70 | return $this->error("The user with {$id} doesn't exist", 404); |
71 | 71 | } |
72 | 72 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | return $this->success("The user with with id {$id} has been deleted", 200); |
76 | 76 | } |
77 | 77 | |
78 | - public function validateRequest(Request $request){ |
|
78 | + public function validateRequest(Request $request) { |
|
79 | 79 | |
80 | 80 | $rules = [ |
81 | 81 | 'email' => 'required|email|unique:users', |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | $this->validate($request, $rules); |
86 | 86 | } |
87 | 87 | |
88 | - public function isAuthorized(Request $request){ |
|
88 | + public function isAuthorized(Request $request) { |
|
89 | 89 | |
90 | 90 | $resource = "users"; |
91 | 91 | // $user = User::find($this->getArgs($request)["user_id"]); |
@@ -13,7 +13,7 @@ |
||
13 | 13 | |
14 | 14 | // Home Page |
15 | 15 | $app->get('/', function () use ($app){ |
16 | - return $app->version(); |
|
16 | + return $app->version(); |
|
17 | 17 | }); |
18 | 18 | |
19 | 19 | // Posts |
@@ -12,14 +12,14 @@ |
||
12 | 12 | */ |
13 | 13 | |
14 | 14 | // Home Page |
15 | -$app->get('/', function () use ($app){ |
|
15 | +$app->get('/', function() use ($app){ |
|
16 | 16 | return $app->version(); |
17 | 17 | }); |
18 | 18 | |
19 | 19 | // Posts |
20 | -$app->get('/posts','PostController@index'); |
|
21 | -$app->post('/posts','PostController@store'); |
|
22 | -$app->get('/posts/{post_id}','PostController@show'); |
|
20 | +$app->get('/posts', 'PostController@index'); |
|
21 | +$app->post('/posts', 'PostController@store'); |
|
22 | +$app->get('/posts/{post_id}', 'PostController@show'); |
|
23 | 23 | $app->put('/posts/{post_id}', 'PostController@update'); |
24 | 24 | $app->patch('/posts/{post_id}', 'PostController@update'); |
25 | 25 | $app->delete('/posts/{post_id}', 'PostController@destroy'); |