Passed
Push — master ( 7d362e...62822e )
by Omar El
02:41
created
app/Comment.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
      *
10 10
      * @var array
11 11
      */
12
-	protected $fillable = ['id', 'post_id', 'user_id', 'content'];
12
+    protected $fillable = ['id', 'post_id', 'user_id', 'content'];
13 13
 
14 14
     /**
15 15
      * The attributes excluded from the model's JSON form.
16 16
      *
17 17
      * @var array
18 18
      */
19
-	protected $hidden   = ['created_at', 'updated_at'];
19
+    protected $hidden   = ['created_at', 'updated_at'];
20 20
 
21 21
     /**
22 22
      * Define an inverse one-to-many relationship with App\Post.
23 23
      *
24 24
      * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
25 25
      */
26
-	public function post(){
27
-		return $this->belongsTo('App\Post');
28
-	}
26
+    public function post(){
27
+        return $this->belongsTo('App\Post');
28
+    }
29 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
app/Post.php 1 patch
Indentation   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -9,22 +9,22 @@
 block discarded – undo
9 9
      *
10 10
      * @var array
11 11
      */
12
-	protected $fillable = ['id', 'user_id', 'title', 'content'];
12
+    protected $fillable = ['id', 'user_id', 'title', 'content'];
13 13
 
14 14
     /**
15 15
      * The attributes excluded from the model's JSON form.
16 16
      *
17 17
      * @var array
18 18
      */
19
-	protected $hidden   = ['created_at', 'updated_at'];
19
+    protected $hidden   = ['created_at', 'updated_at'];
20 20
 
21 21
     /**
22 22
      * Define a one-to-many relationship with App\Comment
23 23
      *
24 24
      * @return \Illuminate\Database\Eloquent\Relations\HasMany
25 25
      */
26
-	public function comments(){
27
-		return $this->hasMany('App\Comment');
28
-	}
26
+    public function comments(){
27
+        return $this->hasMany('App\Comment');
28
+    }
29 29
 
30 30
 }
31 31
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Controllers/CommentController.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -4,20 +4,20 @@
 block discarded – undo
4 4
 
5 5
 class CommentController extends Controller{
6 6
 
7
-	public function index(){
7
+    public function index(){
8 8
 		
9
-		$comments = Comment::all();
10
-		return $this->success($comments, 200);
11
-	}
9
+        $comments = Comment::all();
10
+        return $this->success($comments, 200);
11
+    }
12 12
 
13
-	public function show($id){
13
+    public function show($id){
14 14
 
15
-		$comment = Comment::find($id);
15
+        $comment = Comment::find($id);
16 16
 
17
-		if(!$comment){
18
-			return $this->error("The comment with {$id} doesn't exist", 404);
19
-		}
17
+        if(!$comment){
18
+            return $this->error("The comment with {$id} doesn't exist", 404);
19
+        }
20 20
 
21
-		return $this->success($comment, 200);
22
-	}
21
+        return $this->success($comment, 200);
22
+    }
23 23
 }
24 24
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Controllers/PostController.php 1 patch
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -6,92 +6,92 @@
 block discarded – undo
6 6
 
7 7
 class PostController extends Controller{
8 8
 
9
-	public function __construct(){
9
+    public function __construct(){
10 10
 
11
-		$this->middleware('oauth', ['except' => ['index', 'show']]);
12
-		$this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
13
-	}
11
+        $this->middleware('oauth', ['except' => ['index', 'show']]);
12
+        $this->middleware('authorize:' . __CLASS__, ['except' => ['index', 'show', 'store']]);
13
+    }
14 14
 
15
-	public function index(){
15
+    public function index(){
16 16
 
17
-		$posts = Post::all();
18
-		return $this->success($posts, 200);
19
-	}
17
+        $posts = Post::all();
18
+        return $this->success($posts, 200);
19
+    }
20 20
 
21
-	public function store(Request $request){
21
+    public function store(Request $request){
22 22
 
23
-		$this->validateRequest($request);
23
+        $this->validateRequest($request);
24 24
 
25
-		$post = Post::create([
26
-					'title' => $request->get('title'),
27
-					'content'=> $request->get('content'),
28
-					'user_id' => $this->getUserId()
29
-				]);
25
+        $post = Post::create([
26
+                    'title' => $request->get('title'),
27
+                    'content'=> $request->get('content'),
28
+                    'user_id' => $this->getUserId()
29
+                ]);
30 30
 
31
-		return $this->success("The post with with id {$post->id} has been created", 201);
32
-	}
31
+        return $this->success("The post with with id {$post->id} has been created", 201);
32
+    }
33 33
 
34
-	public function show($id){
34
+    public function show($id){
35 35
 
36
-		$post = Post::find($id);
36
+        $post = Post::find($id);
37 37
 
38
-		if(!$post){
39
-			return $this->error("The post with {$id} doesn't exist", 404);
40
-		}
38
+        if(!$post){
39
+            return $this->error("The post with {$id} doesn't exist", 404);
40
+        }
41 41
 
42
-		return $this->success($post, 200);
43
-	}
42
+        return $this->success($post, 200);
43
+    }
44 44
 
45
-	public function update(Request $request, $id){
45
+    public function update(Request $request, $id){
46 46
 
47
-		$post = Post::find($id);
47
+        $post = Post::find($id);
48 48
 
49
-		if(!$post){
50
-			return $this->error("The post with {$id} doesn't exist", 404);
51
-		}
49
+        if(!$post){
50
+            return $this->error("The post with {$id} doesn't exist", 404);
51
+        }
52 52
 
53
-		$this->validateRequest($request);
53
+        $this->validateRequest($request);
54 54
 
55
-		$post->title 		= $request->get('title');
56
-		$post->content 		= $request->get('content');
57
-		$post->user_id 		= $this->getUserId();
55
+        $post->title 		= $request->get('title');
56
+        $post->content 		= $request->get('content');
57
+        $post->user_id 		= $this->getUserId();
58 58
 
59
-		$post->save();
59
+        $post->save();
60 60
 
61
-		return $this->success("The post with with id {$post->id} has been updated", 200);
62
-	}
61
+        return $this->success("The post with with id {$post->id} has been updated", 200);
62
+    }
63 63
 
64
-	public function destroy($id){
64
+    public function destroy($id){
65 65
 
66
-		$post = Post::find($id);
66
+        $post = Post::find($id);
67 67
 
68
-		if(!$post){
69
-			return $this->error("The post with {$id} doesn't exist", 404);
70
-		}
68
+        if(!$post){
69
+            return $this->error("The post with {$id} doesn't exist", 404);
70
+        }
71 71
 
72
-		// no need to delete the comments for the current post,
73
-		// since we used on delete cascase on update cascase.
74
-		// $post->comments()->delete();
75
-		$post->delete();
72
+        // no need to delete the comments for the current post,
73
+        // since we used on delete cascase on update cascase.
74
+        // $post->comments()->delete();
75
+        $post->delete();
76 76
 
77
-		return $this->success("The post with with id {$id} has been deleted along with it's comments", 200);
78
-	}
77
+        return $this->success("The post with with id {$id} has been deleted along with it's comments", 200);
78
+    }
79 79
 
80
-	public function validateRequest(Request $request){
80
+    public function validateRequest(Request $request){
81 81
 
82
-		$rules = [
83
-			'title' => 'required', 
84
-			'content' => 'required'
85
-		];
82
+        $rules = [
83
+            'title' => 'required', 
84
+            'content' => 'required'
85
+        ];
86 86
 
87
-		$this->validate($request, $rules);
88
-	}
87
+        $this->validate($request, $rules);
88
+    }
89 89
 
90
-	public function isAuthorized(Request $request){
90
+    public function isAuthorized(Request $request){
91 91
 
92
-		$resource = "posts";
93
-		$post     = Post::find($this->getArgs($request)["post_id"]);
92
+        $resource = "posts";
93
+        $post     = Post::find($this->getArgs($request)["post_id"]);
94 94
 
95
-		return $this->authorizeUser($request, $resource, $post);
96
-	}
95
+        return $this->authorizeUser($request, $resource, $post);
96
+    }
97 97
 }
98 98
\ No newline at end of file
Please login to merge, or discard this patch.
app/Http/Controllers/PostCommentController.php 1 patch
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.
app/Http/Controllers/UserController.php 1 patch
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.
app/Http/routes.php 1 patch
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.
app/Http/Controllers/Controller.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -16,9 +16,9 @@  discard block
 block discarded – undo
16 16
      * @param  string $code
17 17
      * @return \Illuminate\Http\JsonResponse
18 18
      */
19
-	public function success($data, $code){
20
-		return response()->json(['data' => $data], $code);
21
-	}
19
+    public function success($data, $code){
20
+        return response()->json(['data' => $data], $code);
21
+    }
22 22
 
23 23
     /**
24 24
      * Return a JSON response for error.
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
      * @param  string $code
28 28
      * @return \Illuminate\Http\JsonResponse
29 29
      */
30
-	public function error($message, $code){
31
-		return response()->json(['message' => $message], $code);
32
-	}
30
+    public function error($message, $code){
31
+        return response()->json(['message' => $message], $code);
32
+    }
33 33
 
34 34
     /**
35 35
      * Check if the user is authorized to perform a given action on a resource.
@@ -42,14 +42,14 @@  discard block
 block discarded – undo
42 42
      */
43 43
     protected function authorizeUser(Request $request, $resource, $arguments = []){
44 44
     	
45
-    	$user 	 = User::find($this->getUserId());
46
-    	$action	 = $this->getAction($request); 
45
+        $user 	 = User::find($this->getUserId());
46
+        $action	 = $this->getAction($request); 
47 47
 
48 48
         // The ability string must match the string defined in App\Providers\AuthServiceProvider\ability()
49 49
         $ability = "{$action}-{$resource}";
50 50
 
51
-    	// return $this->authorizeForUser($user, "{$action}-{$resource}", $data);
52
-    	return Gate::forUser($user)->allows($ability, $arguments);
51
+        // return $this->authorizeForUser($user, "{$action}-{$resource}", $data);
52
+        return Gate::forUser($user)->allows($ability, $arguments);
53 53
     }
54 54
 
55 55
     /**
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
      * @return boolean
73 73
      */
74 74
     protected function getUserId(){
75
-    	return \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId();
75
+        return \LucaDegasperi\OAuth2Server\Facades\Authorizer::getResourceOwnerId();
76 76
     }
77 77
 
78 78
     /**
Please login to merge, or discard this patch.