Completed
Push — master ( 828252...e30674 )
by Omar El
02:51
created
app/Http/Controllers/PostCommentController.php 3 patches
Indentation   +61 added lines, -61 removed lines patch added patch discarded remove patch
@@ -7,95 +7,95 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -5,19 +5,19 @@  discard block
 block discarded – undo
5 5
 
6 6
 use Illuminate\Http\Request;
7 7
 
8
-class PostCommentController extends Controller{
8
+class PostCommentController extends Controller {
9 9
 
10
-	public function __construct(){
10
+	public function __construct() {
11 11
 		
12 12
 		$this->middleware('oauth', ['except' => ['index', 'show']]);
13 13
 		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
14 14
 	}
15 15
 
16
-	public function index($post_id){
16
+	public function index($post_id) {
17 17
 
18 18
 		$post = Post::find($post_id);
19 19
 
20
-		if(!$post){
20
+		if (!$post) {
21 21
 			return $this->error("The post with {$post_id} doesn't exist", 404);
22 22
 		}
23 23
 
@@ -25,11 +25,11 @@  discard block
 block discarded – undo
25 25
 		return $this->success($comments, 200);
26 26
 	}
27 27
 
28
-	public function store(Request $request, $post_id){
28
+	public function store(Request $request, $post_id) {
29 29
 		
30 30
 		$post = Post::find($post_id);
31 31
 
32
-		if(!$post){
32
+		if (!$post) {
33 33
 			return $this->error("The post with {$post_id} doesn't exist", 404);
34 34
 		}
35 35
 
@@ -44,12 +44,12 @@  discard block
 block discarded – undo
44 44
 		return $this->success("The comment with id {$comment->id} has been created and assigned to the post with id {$post_id}", 201);
45 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){
52
+		if (!$comment || !$post) {
53 53
 			return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404);
54 54
 		}
55 55
 
@@ -64,16 +64,16 @@  discard block
 block discarded – undo
64 64
 		return $this->success("The comment with with id {$comment->id} has been updated", 200);
65 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){
72
+		if (!$comment || !$post) {
73 73
 			return $this->error("The comment with {$comment_id} or the post with id {$post_id} doesn't exist", 404);
74 74
 		}
75 75
 
76
-		if(!$post->comments()->find($comment_id)){
76
+		if (!$post->comments()->find($comment_id)) {
77 77
 			return $this->error("The comment with id {$comment_id} isn't assigned to the post with id {$post_id}", 409);
78 78
 		}
79 79
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 		return $this->success("The comment with id {$comment_id} has been removed of the post {$post_id}", 200);
83 83
 	}
84 84
 
85
-	public function validateRequest(Request $request){
85
+	public function validateRequest(Request $request) {
86 86
 
87 87
 		$rules = [
88 88
 			'content' => 'required'
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 		$this->validate($request, $rules);
92 92
 	}
93 93
 
94
-	public function isAuthorized(Request $request){
94
+	public function isAuthorized(Request $request) {
95 95
 
96 96
 		$resource  = "comments";
97 97
 		$comment   = Comment::find($this->getArgs($request)["comment_id"]);
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
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{
Please login to merge, or discard this patch.
app/Http/Controllers/UserController.php 3 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -7,87 +7,87 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -5,21 +5,21 @@  discard block
 block discarded – undo
5 5
 use Illuminate\Http\Request;
6 6
 use Illuminate\Support\Facades\Hash;
7 7
 
8
-class UserController extends Controller{
8
+class UserController extends Controller {
9 9
 
10
-	public function __construct(){
10
+	public function __construct() {
11 11
 
12 12
 		$this->middleware('oauth', ['except' => ['index', 'show']]);
13 13
 		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show']]);
14 14
 	}
15 15
 
16
-	public function index(){
16
+	public function index() {
17 17
 
18 18
 		$users = User::all();
19 19
 		return $this->success($users, 200);
20 20
 	}
21 21
 
22
-	public function store(Request $request){
22
+	public function store(Request $request) {
23 23
 
24 24
 		$this->validateRequest($request);
25 25
 
@@ -31,40 +31,40 @@  discard block
 block discarded – undo
31 31
 		return $this->success("The user with with id {$user->id} has been created", 201);
32 32
 	}
33 33
 
34
-	public function show($id){
34
+	public function show($id) {
35 35
 
36 36
 		$user = User::find($id);
37 37
 
38
-		if(!$user){
38
+		if (!$user) {
39 39
 			return $this->error("The user with {$id} doesn't exist", 404);
40 40
 		}
41 41
 
42 42
 		return $this->success($user, 200);
43 43
 	}
44 44
 
45
-	public function update(Request $request, $id){
45
+	public function update(Request $request, $id) {
46 46
 
47 47
 		$user = User::find($id);
48 48
 
49
-		if(!$user){
49
+		if (!$user) {
50 50
 			return $this->error("The user with {$id} doesn't exist", 404);
51 51
 		}
52 52
 
53 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 58
 		$user->save();
59 59
 
60 60
 		return $this->success("The user with with id {$user->id} has been updated", 200);
61 61
 	}
62 62
 
63
-	public function destroy($id){
63
+	public function destroy($id) {
64 64
 
65 65
 		$user = User::find($id);
66 66
 
67
-		if(!$user){
67
+		if (!$user) {
68 68
 			return $this->error("The user with {$id} doesn't exist", 404);
69 69
 		}
70 70
 
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 		return $this->success("The user with with id {$id} has been deleted", 200);
74 74
 	}
75 75
 
76
-	public function validateRequest(Request $request){
76
+	public function validateRequest(Request $request) {
77 77
 
78 78
 		$rules = [
79 79
 			'email' => 'required|email|unique:users', 
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
 		$this->validate($request, $rules);
84 84
 	}
85 85
 
86
-	public function isAuthorized(Request $request){
86
+	public function isAuthorized(Request $request) {
87 87
 
88 88
 		$resource = "users";
89 89
 		// $user     = User::find($this->getArgs($request)["user_id"]);
Please login to merge, or discard this patch.
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -7,7 +7,6 @@
 block discarded – undo
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{
Please login to merge, or discard this patch.
app/Http/routes.php 2 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
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
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -12,14 +12,14 @@
 block discarded – undo
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');
Please login to merge, or discard this patch.