Completed
Push — master ( c8ea4b...c4213a )
by Sherif
02:51
created
Database/Migrations/2016_01_24_123631_initialize_notifications.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -12,77 +12,77 @@
 block discarded – undo
12 12
 	 */
13 13
 	public function up()
14 14
 	{
15
-        /**
16
-         * Delete previous permissions.
17
-         */
15
+		/**
16
+		 * Delete previous permissions.
17
+		 */
18 18
 		DB::table('permissions')->whereIn('model', ['notifications'])->delete();
19 19
 
20 20
 		/**
21
-         * Insert the permissions related to this module.
22
-         */
23
-        DB::table('permissions')->insert(
24
-        	[
25
-        		/**
26
-        		 * Logs model permissions.
27
-        		 */
28
-	        	[
29
-	        	'name'       => 'find',
30
-	        	'model'      => 'notifications',
31
-	        	'created_at' => \DB::raw('NOW()'),
32
-	        	'updated_at' => \DB::raw('NOW()')
33
-	        	],
34
-	        	[
35
-	        	'name'       => 'search',
36
-	        	'model'      => 'notifications',
37
-	        	'created_at' => \DB::raw('NOW()'),
38
-	        	'updated_at' => \DB::raw('NOW()')
39
-	        	],
40
-	        	[
41
-	        	'name'       => 'list',
42
-	        	'model'      => 'notifications',
43
-	        	'created_at' => \DB::raw('NOW()'),
44
-	        	'updated_at' => \DB::raw('NOW()')
45
-	        	],
46
-	        	[
47
-	        	'name'       => 'findby',
48
-	        	'model'      => 'notifications',
49
-	        	'created_at' => \DB::raw('NOW()'),
50
-	        	'updated_at' => \DB::raw('NOW()')
51
-	        	],
52
-	        	[
53
-	        	'name'       => 'first',
54
-	        	'model'      => 'notifications',
55
-	        	'created_at' => \DB::raw('NOW()'),
56
-	        	'updated_at' => \DB::raw('NOW()')
57
-	        	],
58
-	        	[
59
-	        	'name'       => 'paginate',
60
-	        	'model'      => 'notifications',
61
-	        	'created_at' => \DB::raw('NOW()'),
62
-	        	'updated_at' => \DB::raw('NOW()')
63
-	        	],
64
-	        	[
65
-	        	'name'       => 'paginateby',
66
-	        	'model'      => 'notifications',
67
-	        	'created_at' => \DB::raw('NOW()'),
68
-	        	'updated_at' => \DB::raw('NOW()')
69
-	        	],
70
-	        	[
71
-	        	'name'       => 'notified',
72
-	        	'model'      => 'notifications',
73
-	        	'created_at' => \DB::raw('NOW()'),
74
-	        	'updated_at' => \DB::raw('NOW()')
75
-	        	],
76
-	        	[
77
-	        	'name'       => 'notifyall',
78
-	        	'model'      => 'notifications',
79
-	        	'created_at' => \DB::raw('NOW()'),
80
-	        	'updated_at' => \DB::raw('NOW()')
81
-	        	],
82
-        	]
83
-        );
21
+		 * Insert the permissions related to this module.
22
+		 */
23
+		DB::table('permissions')->insert(
24
+			[
25
+				/**
26
+				 * Logs model permissions.
27
+				 */
28
+				[
29
+				'name'       => 'find',
30
+				'model'      => 'notifications',
31
+				'created_at' => \DB::raw('NOW()'),
32
+				'updated_at' => \DB::raw('NOW()')
33
+				],
34
+				[
35
+				'name'       => 'search',
36
+				'model'      => 'notifications',
37
+				'created_at' => \DB::raw('NOW()'),
38
+				'updated_at' => \DB::raw('NOW()')
39
+				],
40
+				[
41
+				'name'       => 'list',
42
+				'model'      => 'notifications',
43
+				'created_at' => \DB::raw('NOW()'),
44
+				'updated_at' => \DB::raw('NOW()')
45
+				],
46
+				[
47
+				'name'       => 'findby',
48
+				'model'      => 'notifications',
49
+				'created_at' => \DB::raw('NOW()'),
50
+				'updated_at' => \DB::raw('NOW()')
51
+				],
52
+				[
53
+				'name'       => 'first',
54
+				'model'      => 'notifications',
55
+				'created_at' => \DB::raw('NOW()'),
56
+				'updated_at' => \DB::raw('NOW()')
57
+				],
58
+				[
59
+				'name'       => 'paginate',
60
+				'model'      => 'notifications',
61
+				'created_at' => \DB::raw('NOW()'),
62
+				'updated_at' => \DB::raw('NOW()')
63
+				],
64
+				[
65
+				'name'       => 'paginateby',
66
+				'model'      => 'notifications',
67
+				'created_at' => \DB::raw('NOW()'),
68
+				'updated_at' => \DB::raw('NOW()')
69
+				],
70
+				[
71
+				'name'       => 'notified',
72
+				'model'      => 'notifications',
73
+				'created_at' => \DB::raw('NOW()'),
74
+				'updated_at' => \DB::raw('NOW()')
75
+				],
76
+				[
77
+				'name'       => 'notifyall',
78
+				'model'      => 'notifications',
79
+				'created_at' => \DB::raw('NOW()'),
80
+				'updated_at' => \DB::raw('NOW()')
81
+				],
82
+			]
83
+		);
84 84
 
85
-        /**
85
+		/**
86 86
 		 * Assign the permissions to the admin group.
87 87
 		 */
88 88
 		$permissionIds = DB::table('permissions')->whereIn('model', ['notifications'])->select('id')->lists('id');
Please login to merge, or discard this patch.
src/Kernel.php 1 patch
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,44 +7,44 @@
 block discarded – undo
7 7
 class Kernel extends HttpKernel
8 8
 {
9 9
 
10
-    /**
11
-     * The application's global HTTP middleware stack.
12
-     *
13
-     * These middleware are run during every request to your application.
14
-     *
15
-     * @var array
16
-     */
17
-    protected $middleware = [
18
-        \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
19
-    ];
10
+	/**
11
+	 * The application's global HTTP middleware stack.
12
+	 *
13
+	 * These middleware are run during every request to your application.
14
+	 *
15
+	 * @var array
16
+	 */
17
+	protected $middleware = [
18
+		\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
19
+	];
20 20
 
21
-    /**
22
-     * The application's global HTTP middleware stack.
23
-     *
24
-     * @var array
25
-     */
26
-    protected $middlewareGroups = [
27
-        'web' => [
28
-            \App\Http\Middleware\EncryptCookies::class,
29
-            \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
30
-            \Illuminate\Session\Middleware\StartSession::class,
31
-            \Illuminate\View\Middleware\ShareErrorsFromSession::class,
32
-            //\App\Http\Middleware\VerifyCsrfToken::class,
33
-        ],
34
-        'api' => [
35
-            'throttle:60,1',
36
-        ],
37
-    ];
21
+	/**
22
+	 * The application's global HTTP middleware stack.
23
+	 *
24
+	 * @var array
25
+	 */
26
+	protected $middlewareGroups = [
27
+		'web' => [
28
+			\App\Http\Middleware\EncryptCookies::class,
29
+			\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
30
+			\Illuminate\Session\Middleware\StartSession::class,
31
+			\Illuminate\View\Middleware\ShareErrorsFromSession::class,
32
+			//\App\Http\Middleware\VerifyCsrfToken::class,
33
+		],
34
+		'api' => [
35
+			'throttle:60,1',
36
+		],
37
+	];
38 38
 
39
-    /**
40
-     * The application's route middleware.
41
-     *
42
-     * @var array
43
-     */
44
-    protected $routeMiddleware = [
45
-        'auth' => \App\Http\Middleware\Authenticate::class,
46
-        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
47
-        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
48
-        'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
49
-    ];
39
+	/**
40
+	 * The application's route middleware.
41
+	 *
42
+	 * @var array
43
+	 */
44
+	protected $routeMiddleware = [
45
+		'auth' => \App\Http\Middleware\Authenticate::class,
46
+		'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
47
+		'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
48
+		'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
49
+	];
50 50
 }
Please login to merge, or discard this patch.
src/Modules/Core/AbstractRepositories/AbstractRepositoryContainer.php 1 patch
Indentation   +28 added lines, -28 removed lines patch added patch discarded remove patch
@@ -4,34 +4,34 @@
 block discarded – undo
4 4
 
5 5
 abstract class AbstractRepositoryContainer implements RepositoryContainerInterface
6 6
 {
7
-    /**
8
-     * Construct the repository class name based on
9
-     * the method name called, search in the 
10
-     * given namespaces for the class and 
11
-     * return an instance.
12
-     * 
13
-     * @param  string $name the called method name
14
-     * @param  array  $arguments the method arguments
15
-     * @return object
16
-     */
7
+	/**
8
+	 * Construct the repository class name based on
9
+	 * the method name called, search in the 
10
+	 * given namespaces for the class and 
11
+	 * return an instance.
12
+	 * 
13
+	 * @param  string $name the called method name
14
+	 * @param  array  $arguments the method arguments
15
+	 * @return object
16
+	 */
17 17
 	public function __call($name, $arguments)
18
-    {
19
-    	foreach ($this->getRepoNameSpace() as $repoNameSpace) 
20
-    	{
21
-            $class      = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository';
22
-    		if (class_exists($class)) 
23
-    		{
24
-        		return \App::make($class);
25
-    		}
26
-    	}
27
-    }
18
+	{
19
+		foreach ($this->getRepoNameSpace() as $repoNameSpace) 
20
+		{
21
+			$class      = rtrim($repoNameSpace, '\\') . '\\' . ucfirst(str_singular($name)) . 'Repository';
22
+			if (class_exists($class)) 
23
+			{
24
+				return \App::make($class);
25
+			}
26
+		}
27
+	}
28 28
 
29
-     /**
30
-     * Abstract methods that return the necessary 
31
-     * information (repositories namespaces)
32
-     * needed to preform the previous actions.
33
-     * 
34
-     * @return array
35
-     */
36
-    abstract protected function getRepoNameSpace();
29
+	 /**
30
+	  * Abstract methods that return the necessary 
31
+	  * information (repositories namespaces)
32
+	  * needed to preform the previous actions.
33
+	  * 
34
+	  * @return array
35
+	  */
36
+	abstract protected function getRepoNameSpace();
37 37
 }
38 38
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Notifications/Repositories/NotificationRepository.php 1 patch
Indentation   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -11,28 +11,28 @@
 block discarded – undo
11 11
 	 */
12 12
 	protected function getModel()
13 13
 	{
14
-        $apiVersion = \Request::header('api-version') ?: 1;
14
+		$apiVersion = \Request::header('api-version') ?: 1;
15 15
 		return 'App\Modules\Notifications\Notification';
16 16
 	}
17 17
 
18 18
 	/**
19
-     * Set the notification notified to true.
20
-     * 
21
-     * @param  integer  $id
22
-     * @return object
23
-     */
24
-    public function notified($id)
25
-    {
26
-        return $this->save(['id' => $id, 'notified' => 1]);
27
-    }
19
+	 * Set the notification notified to true.
20
+	 * 
21
+	 * @param  integer  $id
22
+	 * @return object
23
+	 */
24
+	public function notified($id)
25
+	{
26
+		return $this->save(['id' => $id, 'notified' => 1]);
27
+	}
28 28
 
29
-    /**
30
-     * Set the notification notified to all.
31
-     * 
32
-     * @return void
33
-     */
34
-    public function notifyAll()
35
-    {
36
-        \Core::notifications()->update(false, ['notified' => 1], 'notified');
37
-    }
29
+	/**
30
+	 * Set the notification notified to all.
31
+	 * 
32
+	 * @return void
33
+	 */
34
+	public function notifyAll()
35
+	{
36
+		\Core::notifications()->update(false, ['notified' => 1], 'notified');
37
+	}
38 38
 }
Please login to merge, or discard this patch.
src/Modules/Reporting/Http/Controllers/ReportsController.php 1 patch
Indentation   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -8,16 +8,16 @@
 block discarded – undo
8 8
 class ReportsController extends BaseApiController
9 9
 {
10 10
 	/**
11
-     * The name of the model that is used by the base api controller 
12
-     * to preform actions like (add, edit ... etc).
13
-     * @var string
14
-     */
15
-    protected $model            = 'reports';
11
+	 * The name of the model that is used by the base api controller 
12
+	 * to preform actions like (add, edit ... etc).
13
+	 * @var string
14
+	 */
15
+	protected $model            = 'reports';
16 16
 
17
-    /**
18
-     * List of all route actions that the base api controller
19
-     * will skip permissions check for them.
20
-     * @var array
21
-     */
22
-    protected $skipPermissionCheck = ['find', 'first'];
17
+	/**
18
+	 * List of all route actions that the base api controller
19
+	 * will skip permissions check for them.
20
+	 * @var array
21
+	 */
22
+	protected $skipPermissionCheck = ['find', 'first'];
23 23
 }
Please login to merge, or discard this patch.
src/Exceptions/Handler.php 1 patch
Indentation   +71 added lines, -71 removed lines patch added patch discarded remove patch
@@ -10,79 +10,79 @@
 block discarded – undo
10 10
 
11 11
 class Handler extends ExceptionHandler
12 12
 {
13
-    /**
14
-     * A list of the exception types that should not be reported.
15
-     *
16
-     * @var array
17
-     */
18
-    protected $dontReport = [
19
-        HttpException::class,
20
-        ModelNotFoundException::class,
21
-    ];
13
+	/**
14
+	 * A list of the exception types that should not be reported.
15
+	 *
16
+	 * @var array
17
+	 */
18
+	protected $dontReport = [
19
+		HttpException::class,
20
+		ModelNotFoundException::class,
21
+	];
22 22
 
23
-    /**
24
-     * Report or log an exception.
25
-     *
26
-     * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
27
-     *
28
-     * @param  \Exception  $e
29
-     * @return void
30
-     */
31
-    public function report(Exception $e)
32
-    {
33
-        return parent::report($e);
34
-    }
23
+	/**
24
+	 * Report or log an exception.
25
+	 *
26
+	 * This is a great spot to send exceptions to Sentry, Bugsnag, etc.
27
+	 *
28
+	 * @param  \Exception  $e
29
+	 * @return void
30
+	 */
31
+	public function report(Exception $e)
32
+	{
33
+		return parent::report($e);
34
+	}
35 35
 
36
-    /**
37
-     * Render an exception into an HTTP response.
38
-     *
39
-     * @param  \Illuminate\Http\Request  $request
40
-     * @param  \Exception  $e
41
-     * @return \Illuminate\Http\Response
42
-     */
43
-    public function render($request, Exception $e)
44
-    {
45
-        if ($e instanceof ModelNotFoundException) {
46
-            $e = new NotFoundHttpException($e->getMessage(), $e);
47
-        }
36
+	/**
37
+	 * Render an exception into an HTTP response.
38
+	 *
39
+	 * @param  \Illuminate\Http\Request  $request
40
+	 * @param  \Exception  $e
41
+	 * @return \Illuminate\Http\Response
42
+	 */
43
+	public function render($request, Exception $e)
44
+	{
45
+		if ($e instanceof ModelNotFoundException) {
46
+			$e = new NotFoundHttpException($e->getMessage(), $e);
47
+		}
48 48
 
49
-        if ($request->wantsJson())
50
-        {
51
-            if ($e instanceof \Illuminate\Database\QueryException) 
52
-            {
53
-                $error = \ErrorHandler::dbQueryError();
54
-                return \Response::json($error['message'], $error['status']);
55
-            }
56
-            else if ($e instanceof \predis\connection\connectionexception) 
57
-            {
58
-                $error = \ErrorHandler::redisNotRunning();
59
-                return \Response::json($error['message'], $error['status']);
60
-            }
61
-            else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) 
62
-            {
63
-                $error = \ErrorHandler::tokenExpired();
64
-                return \Response::json($error['message'], $error['status']);
65
-            } 
66
-            else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) 
67
-            {
68
-                $error = \ErrorHandler::noPermissions();
69
-                return \Response::json($error['message'], $error['status']);
70
-            }
71
-            else if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) 
72
-            {
73
-                $error = \ErrorHandler::unAuthorized();
74
-                return \Response::json($error['message'], $error['status']);
75
-            }
76
-            else if ($e instanceof HttpException) 
77
-            {
78
-                return \Response::json($e->getMessage(), $e->getStatusCode());   
79
-            }
80
-            else
81
-            {
82
-                return parent::render($request, $e);
83
-            }
84
-        }
49
+		if ($request->wantsJson())
50
+		{
51
+			if ($e instanceof \Illuminate\Database\QueryException) 
52
+			{
53
+				$error = \ErrorHandler::dbQueryError();
54
+				return \Response::json($error['message'], $error['status']);
55
+			}
56
+			else if ($e instanceof \predis\connection\connectionexception) 
57
+			{
58
+				$error = \ErrorHandler::redisNotRunning();
59
+				return \Response::json($error['message'], $error['status']);
60
+			}
61
+			else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenExpiredException) 
62
+			{
63
+				$error = \ErrorHandler::tokenExpired();
64
+				return \Response::json($error['message'], $error['status']);
65
+			} 
66
+			else if ($e instanceof \Tymon\JWTAuth\Exceptions\TokenInvalidException) 
67
+			{
68
+				$error = \ErrorHandler::noPermissions();
69
+				return \Response::json($error['message'], $error['status']);
70
+			}
71
+			else if ($e instanceof \Tymon\JWTAuth\Exceptions\JWTException) 
72
+			{
73
+				$error = \ErrorHandler::unAuthorized();
74
+				return \Response::json($error['message'], $error['status']);
75
+			}
76
+			else if ($e instanceof HttpException) 
77
+			{
78
+				return \Response::json($e->getMessage(), $e->getStatusCode());   
79
+			}
80
+			else
81
+			{
82
+				return parent::render($request, $e);
83
+			}
84
+		}
85 85
 
86
-        return parent::render($request, $e);
87
-    }
86
+		return parent::render($request, $e);
87
+	}
88 88
 }
Please login to merge, or discard this patch.
src/Modules/Reporting/Repositories/ReportRepository.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -11,63 +11,63 @@
 block discarded – undo
11 11
 	 */
12 12
 	protected function getModel()
13 13
 	{
14
-        $apiVersion = \Request::header('api-version') ?: 1;
14
+		$apiVersion = \Request::header('api-version') ?: 1;
15 15
 		return 'App\Modules\Reporting\Report';
16 16
 	}
17 17
 
18 18
 	/**
19
-     * Render the given report db view.
20
-     * 
21
-     * @param  integer $id
22
-     * @param  array   $relations
23
-     * @param  array   $columns
24
-     * @return object
25
-     */
26
-    public function find($id, $relations = [], $columns = array('*'))
27
-    {
19
+	 * Render the given report db view.
20
+	 * 
21
+	 * @param  integer $id
22
+	 * @param  array   $relations
23
+	 * @param  array   $columns
24
+	 * @return object
25
+	 */
26
+	public function find($id, $relations = [], $columns = array('*'))
27
+	{
28 28
 		$report = call_user_func_array("{$this->getModel()}::with", array($relations))->find($id, $columns);
29 29
 
30
-        if ( ! $report) 
31
-        {
32
-            $error = $this->errorHandler->notFound('report');
33
-            abort($error['status'], $error['message']);
34
-        }
30
+		if ( ! $report) 
31
+		{
32
+			$error = $this->errorHandler->notFound('report');
33
+			abort($error['status'], $error['message']);
34
+		}
35 35
 
36
-        if ( ! \Core::users()->can($report->view_name, 'reports'))
37
-        {
38
-            $error = $this->errorHandler->noPermissions();
39
-            abort($error['status'], $error['message']);
40
-        }
36
+		if ( ! \Core::users()->can($report->view_name, 'reports'))
37
+		{
38
+			$error = $this->errorHandler->noPermissions();
39
+			abort($error['status'], $error['message']);
40
+		}
41 41
 
42
-        return \DB::table($report->view_name)->get();
43
-    }
42
+		return \DB::table($report->view_name)->get();
43
+	}
44 44
 
45
-    /**
46
-     * Render the given report db view based on the given
47
-     * condition.
48
-     *
49
-     * @param  array   $conditions array of conditions
50
-     * @param  array   $relations
51
-     * @param  array   $colunmns
52
-     * @return object
53
-     */
54
-    public function first($conditions, $relations = [], $columns = array('*'))
55
-    {
45
+	/**
46
+	 * Render the given report db view based on the given
47
+	 * condition.
48
+	 *
49
+	 * @param  array   $conditions array of conditions
50
+	 * @param  array   $relations
51
+	 * @param  array   $colunmns
52
+	 * @return object
53
+	 */
54
+	public function first($conditions, $relations = [], $columns = array('*'))
55
+	{
56 56
 		$conditions = $this->constructConditions($conditions);
57 57
 		$report     = call_user_func_array("{$this->getModel()}::with", array($relations))->whereRaw($conditions['conditionString'], $conditions['conditionValues'])->first($columns);
58 58
         
59
-        if ( ! $report) 
60
-        {
61
-            $error = $this->errorHandler->notFound('report');
62
-            abort($error['status'], $error['message']);
63
-        }
59
+		if ( ! $report) 
60
+		{
61
+			$error = $this->errorHandler->notFound('report');
62
+			abort($error['status'], $error['message']);
63
+		}
64 64
         
65
-        if ( ! \Core::users()->can($report->view_name, 'reports'))
66
-        {
67
-            $error = $this->errorHandler->noPermissions();
68
-            abort($error['status'], $error['message']);
69
-        }
65
+		if ( ! \Core::users()->can($report->view_name, 'reports'))
66
+		{
67
+			$error = $this->errorHandler->noPermissions();
68
+			abort($error['status'], $error['message']);
69
+		}
70 70
 		
71
-        return \DB::table($report->view_name)->get();  
72
-    }
71
+		return \DB::table($report->view_name)->get();  
72
+	}
73 73
 }
Please login to merge, or discard this patch.
src/Modules/Core/ErrorHandler.php 1 patch
Indentation   +44 added lines, -44 removed lines patch added patch discarded remove patch
@@ -2,48 +2,48 @@
 block discarded – undo
2 2
 
3 3
 class ErrorHandler
4 4
 {
5
-    public function unAuthorized()
6
-    {
7
-        return ['status' => 401, 'message' => 'Please login before any action'];
8
-    }
9
-
10
-    public function tokenExpired()
11
-    {
12
-        return ['status' => 401, 'message' => 'Login token expired'];
13
-    }
14
-
15
-     public function noPermissions()
16
-    {
17
-        return ['status' => 401, 'message' => 'No permissions'];
18
-    }
19
-
20
-    public function loginFailed()
21
-    {
22
-        return ['status' => 400, 'message' => 'Wrong mail or password'];
23
-    }
24
-
25
-    public function redisNotRunning()
26
-    {
27
-        return ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
28
-    }
29
-
30
-    public function dbQueryError()
31
-    {
32
-        return ['status' => 400, 'message' => 'Please check the given inputes'];
33
-    }
34
-
35
-    public function cannotCreateSetting()
36
-    {
37
-        return ['status' => 400, 'message' => 'Can\'t create setting'];
38
-    }
39
-
40
-    public function cannotUpdateSettingKey()
41
-    {
42
-        return ['status' => 400, 'message' => 'Can\'t update setting key'];
43
-    }
44
-
45
-    public function notFound($text)
46
-    {
47
-        return ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
48
-    }
5
+	public function unAuthorized()
6
+	{
7
+		return ['status' => 401, 'message' => 'Please login before any action'];
8
+	}
9
+
10
+	public function tokenExpired()
11
+	{
12
+		return ['status' => 401, 'message' => 'Login token expired'];
13
+	}
14
+
15
+	 public function noPermissions()
16
+	{
17
+		return ['status' => 401, 'message' => 'No permissions'];
18
+	}
19
+
20
+	public function loginFailed()
21
+	{
22
+		return ['status' => 400, 'message' => 'Wrong mail or password'];
23
+	}
24
+
25
+	public function redisNotRunning()
26
+	{
27
+		return ['status' => 400, 'message' => 'Your redis notification server isn\'t running'];
28
+	}
29
+
30
+	public function dbQueryError()
31
+	{
32
+		return ['status' => 400, 'message' => 'Please check the given inputes'];
33
+	}
34
+
35
+	public function cannotCreateSetting()
36
+	{
37
+		return ['status' => 400, 'message' => 'Can\'t create setting'];
38
+	}
39
+
40
+	public function cannotUpdateSettingKey()
41
+	{
42
+		return ['status' => 400, 'message' => 'Can\'t update setting key'];
43
+	}
44
+
45
+	public function notFound($text)
46
+	{
47
+		return ['status' => 404, 'message' => 'The requested ' . $text . ' not found'];
48
+	}
49 49
 }
50 50
\ No newline at end of file
Please login to merge, or discard this patch.
src/Modules/Core/Http/Controllers/BaseApiController.php 1 patch
Indentation   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -9,238 +9,238 @@
 block discarded – undo
9 9
 
10 10
 class BaseApiController extends Controller
11 11
 {
12
-    /**
13
-     * The errorHandler implementation.
14
-     * 
15
-     * @var errorHandler
16
-     */
17
-    protected $errorHandler;
18
-
19
-    /**
20
-     * The config implementation.
21
-     * 
22
-     * @var config
23
-     */
24
-    protected $config;
25
-
26
-    /**
27
-     * The model implementation.
28
-     * 
29
-     * @var model
30
-     */
31
-    protected $model;
32
-
33
-    /**
34
-     * Create new BaseApiController instance.
35
-     * 
36
-     * @param errorHandler
37
-     */
38
-    public function __construct(ErrorHandler $errorHandler, CoreConfig $config)
39
-    {
40
-        \Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
12
+	/**
13
+	 * The errorHandler implementation.
14
+	 * 
15
+	 * @var errorHandler
16
+	 */
17
+	protected $errorHandler;
18
+
19
+	/**
20
+	 * The config implementation.
21
+	 * 
22
+	 * @var config
23
+	 */
24
+	protected $config;
25
+
26
+	/**
27
+	 * The model implementation.
28
+	 * 
29
+	 * @var model
30
+	 */
31
+	protected $model;
32
+
33
+	/**
34
+	 * Create new BaseApiController instance.
35
+	 * 
36
+	 * @param errorHandler
37
+	 */
38
+	public function __construct(ErrorHandler $errorHandler, CoreConfig $config)
39
+	{
40
+		\Session::set('timeZoneDiff', \Request::header('time-zone-diff') ?: 0);
41 41
         
42
-        $this->errorHandler        = $errorHandler;
43
-        $this->config              = $config->getConfig();
42
+		$this->errorHandler        = $errorHandler;
43
+		$this->config              = $config->getConfig();
44 44
         
45
-        $this->model               = property_exists($this, 'model') ? $this->model : false;
46
-        $this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
47
-        $this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
48
-        $this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
45
+		$this->model               = property_exists($this, 'model') ? $this->model : false;
46
+		$this->validationRules     = property_exists($this, 'validationRules') ? $this->validationRules : false;
47
+		$this->skipPermissionCheck = property_exists($this, 'skipPermissionCheck') ? $this->skipPermissionCheck : [];
48
+		$this->skipLoginCheck      = property_exists($this, 'skipLoginCheck') ? $this->skipLoginCheck : [];
49 49
         
50
-        $this->relations           = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
51
-        $route                     = explode('@',\Route::currentRouteAction())[1];
52
-        $this->checkPermission(explode('_', snake_case($route))[1]);
53
-    }
54
-
55
-    /**
56
-     * Fetch all records with relations from model repository.
57
-     * 
58
-     * @param  string  $sortBy
59
-     * @param  boolean $desc
60
-     * @return \Illuminate\Http\Response
61
-     */
62
-    public function getIndex() 
63
-    {
64
-        if ($this->model)
65
-        {
66
-            $relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : [];
67
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200);
68
-        }
69
-    }
70
-
71
-    /**
72
-     * Fetch the single object with relations from model repository.
73
-     * 
74
-     * @param  integer $id
75
-     * @return \Illuminate\Http\Response
76
-     */
77
-    public function getFind($id) 
78
-    {
79
-        if ($this->model) 
80
-        {
81
-            $relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
82
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200);
83
-        }
84
-    }
85
-
86
-    /**
87
-     * Paginate all records with relations from model repository
88
-     * that matche the given query.
89
-     * 
90
-     * @param  string  $query
91
-     * @param  integer $perPage
92
-     * @param  string  $sortBy
93
-     * @param  boolean $desc
94
-     * @return \Illuminate\Http\Response
95
-     */
96
-    public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
97
-    {
98
-        if ($this->model) 
99
-        {
100
-            $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
101
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200);
102
-        }
103
-    }
104
-
105
-    /**
106
-     * Fetch records from the storage based on the given
107
-     * condition.
108
-     * 
109
-     * @param  \Illuminate\Http\Request  $request
110
-     * @param  string  $sortBy
111
-     * @param  boolean $desc
112
-     * @return \Illuminate\Http\Response
113
-     */
114
-    public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) 
115
-    {
116
-        if ($this->model) 
117
-        {
118
-            $relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : [];
119
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200);
120
-        }
121
-    }
122
-
123
-    /**
124
-     * Fetch the first record from the storage based on the given
125
-     * condition.
126
-     * 
127
-     * @param  \Illuminate\Http\Request  $request
128
-     * @return \Illuminate\Http\Response
129
-     */
130
-    public function postFirst(Request $request) 
131
-    {
132
-        if ($this->model) 
133
-        {
134
-            $relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : [];
135
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200);
136
-        }
137
-    }
138
-
139
-    /**
140
-     * Paginate all records with relations from model repository.
141
-     * 
142
-     * @param  integer $perPage
143
-     * @param  string  $sortBy
144
-     * @param  boolean $desc
145
-     * @return \Illuminate\Http\Response
146
-     */
147
-    public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
148
-    {
149
-        if ($this->model) 
150
-        {
151
-            $relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
152
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200);
153
-        }
154
-    }
155
-
156
-    /**
157
-     * Fetch all records with relations based on
158
-     * the given condition from storage in pages.
159
-     * 
160
-     * @param  \Illuminate\Http\Request  $request
161
-     * @param  integer $perPage
162
-     * @param  string  $sortBy
163
-     * @param  boolean $desc
164
-     * @return \Illuminate\Http\Response
165
-     */
166
-    public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
167
-    {
168
-        if ($this->model) 
169
-        {
170
-            $relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : [];
171
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200);
172
-        }
173
-    }
174
-
175
-    /**
176
-     * Save the given model to repository.
177
-     * 
178
-     * @param  \Illuminate\Http\Request  $request
179
-     * @return \Illuminate\Http\Response
180
-     */
181
-    public function postSave(Request $request) 
182
-    {
183
-        foreach ($this->validationRules as &$rule) 
184
-        {
185
-            if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
186
-            {
187
-                $rule .= ',deleted_at,NULL';
188
-            }
189
-
190
-            if ($request->has('id')) 
191
-            {
192
-                $rule = str_replace('{id}', $request->get('id'), $rule);
193
-            }
194
-            else
195
-            {
196
-                $rule = str_replace(',{id}', '', $rule);
197
-            }
198
-        }
50
+		$this->relations           = array_key_exists($this->model, $this->config['relations']) ? $this->config['relations'][$this->model] : false;
51
+		$route                     = explode('@',\Route::currentRouteAction())[1];
52
+		$this->checkPermission(explode('_', snake_case($route))[1]);
53
+	}
54
+
55
+	/**
56
+	 * Fetch all records with relations from model repository.
57
+	 * 
58
+	 * @param  string  $sortBy
59
+	 * @param  boolean $desc
60
+	 * @return \Illuminate\Http\Response
61
+	 */
62
+	public function getIndex() 
63
+	{
64
+		if ($this->model)
65
+		{
66
+			$relations = $this->relations && $this->relations['all'] ? $this->relations['all'] : [];
67
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->all($relations), 200);
68
+		}
69
+	}
70
+
71
+	/**
72
+	 * Fetch the single object with relations from model repository.
73
+	 * 
74
+	 * @param  integer $id
75
+	 * @return \Illuminate\Http\Response
76
+	 */
77
+	public function getFind($id) 
78
+	{
79
+		if ($this->model) 
80
+		{
81
+			$relations = $this->relations && $this->relations['find'] ? $this->relations['find'] : [];
82
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->find($id, $relations), 200);
83
+		}
84
+	}
85
+
86
+	/**
87
+	 * Paginate all records with relations from model repository
88
+	 * that matche the given query.
89
+	 * 
90
+	 * @param  string  $query
91
+	 * @param  integer $perPage
92
+	 * @param  string  $sortBy
93
+	 * @param  boolean $desc
94
+	 * @return \Illuminate\Http\Response
95
+	 */
96
+	public function getSearch($query = '', $perPage = 15, $sortBy = 'created_at', $desc = 1) 
97
+	{
98
+		if ($this->model) 
99
+		{
100
+			$relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
101
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->search($query, $perPage, $relations, $sortBy, $desc), 200);
102
+		}
103
+	}
104
+
105
+	/**
106
+	 * Fetch records from the storage based on the given
107
+	 * condition.
108
+	 * 
109
+	 * @param  \Illuminate\Http\Request  $request
110
+	 * @param  string  $sortBy
111
+	 * @param  boolean $desc
112
+	 * @return \Illuminate\Http\Response
113
+	 */
114
+	public function postFindby(Request $request, $sortBy = 'created_at', $desc = 1) 
115
+	{
116
+		if ($this->model) 
117
+		{
118
+			$relations = $this->relations && $this->relations['findBy'] ? $this->relations['findBy'] : [];
119
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->findBy($request->all(), $relations, $sortBy, $desc), 200);
120
+		}
121
+	}
122
+
123
+	/**
124
+	 * Fetch the first record from the storage based on the given
125
+	 * condition.
126
+	 * 
127
+	 * @param  \Illuminate\Http\Request  $request
128
+	 * @return \Illuminate\Http\Response
129
+	 */
130
+	public function postFirst(Request $request) 
131
+	{
132
+		if ($this->model) 
133
+		{
134
+			$relations = $this->relations && $this->relations['first'] ? $this->relations['first'] : [];
135
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->first($request->all(), $relations), 200);
136
+		}
137
+	}
138
+
139
+	/**
140
+	 * Paginate all records with relations from model repository.
141
+	 * 
142
+	 * @param  integer $perPage
143
+	 * @param  string  $sortBy
144
+	 * @param  boolean $desc
145
+	 * @return \Illuminate\Http\Response
146
+	 */
147
+	public function getPaginate($perPage = 15, $sortBy = 'created_at', $desc = 1) 
148
+	{
149
+		if ($this->model) 
150
+		{
151
+			$relations = $this->relations && $this->relations['paginate'] ? $this->relations['paginate'] : [];
152
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginate($perPage, $relations, $sortBy, $desc), 200);
153
+		}
154
+	}
155
+
156
+	/**
157
+	 * Fetch all records with relations based on
158
+	 * the given condition from storage in pages.
159
+	 * 
160
+	 * @param  \Illuminate\Http\Request  $request
161
+	 * @param  integer $perPage
162
+	 * @param  string  $sortBy
163
+	 * @param  boolean $desc
164
+	 * @return \Illuminate\Http\Response
165
+	 */
166
+	public function postPaginateby(Request $request, $perPage = 15, $sortBy = 'created_at', $desc = 1) 
167
+	{
168
+		if ($this->model) 
169
+		{
170
+			$relations = $this->relations && $this->relations['paginateBy'] ? $this->relations['paginateBy'] : [];
171
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->paginateBy($request->all(), $perPage, $relations, $sortBy, $desc), 200);
172
+		}
173
+	}
174
+
175
+	/**
176
+	 * Save the given model to repository.
177
+	 * 
178
+	 * @param  \Illuminate\Http\Request  $request
179
+	 * @return \Illuminate\Http\Response
180
+	 */
181
+	public function postSave(Request $request) 
182
+	{
183
+		foreach ($this->validationRules as &$rule) 
184
+		{
185
+			if (strpos($rule, 'exists') && ! strpos($rule, 'deleted_at,NULL')) 
186
+			{
187
+				$rule .= ',deleted_at,NULL';
188
+			}
189
+
190
+			if ($request->has('id')) 
191
+			{
192
+				$rule = str_replace('{id}', $request->get('id'), $rule);
193
+			}
194
+			else
195
+			{
196
+				$rule = str_replace(',{id}', '', $rule);
197
+			}
198
+		}
199 199
         
200
-        $this->validate($request, $this->validationRules);
201
-
202
-        if ($this->model) 
203
-        {
204
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
205
-        }
206
-    }
207
-
208
-    /**
209
-     * Delete by the given id from model repository.
210
-     * 
211
-     * @param  integer  $id
212
-     * @return \Illuminate\Http\Response
213
-     */
214
-    public function getDelete($id) 
215
-    {
216
-        if ($this->model) 
217
-        {
218
-            return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
219
-        }
220
-    }
221
-
222
-    /**
223
-     * Check if the logged in user can do the given permission.
224
-     * 
225
-     * @param  string $permission
226
-     * @return void
227
-     */
228
-    private function checkPermission($permission)
229
-    {
230
-        $permission = $permission !== 'index' ? $permission : 'list';
231
-        if ($permission == 'method') 
232
-        {
233
-            $error = $this->errorHandler->notFound('method');
234
-            abort($error['status'], $error['message']);
235
-        }
236
-        else if ( ! in_array($permission, $this->skipLoginCheck)) 
237
-        {
238
-            \JWTAuth::parseToken()->authenticate();
239
-            if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
240
-            {
241
-                $error = $this->errorHandler->noPermissions();
242
-                abort($error['status'], $error['message']);
243
-            }
244
-        }
245
-    }
200
+		$this->validate($request, $this->validationRules);
201
+
202
+		if ($this->model) 
203
+		{
204
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->save($request->all()), 200);
205
+		}
206
+	}
207
+
208
+	/**
209
+	 * Delete by the given id from model repository.
210
+	 * 
211
+	 * @param  integer  $id
212
+	 * @return \Illuminate\Http\Response
213
+	 */
214
+	public function getDelete($id) 
215
+	{
216
+		if ($this->model) 
217
+		{
218
+			return \Response::json(call_user_func_array("\Core::{$this->model}", [])->delete($id), 200);
219
+		}
220
+	}
221
+
222
+	/**
223
+	 * Check if the logged in user can do the given permission.
224
+	 * 
225
+	 * @param  string $permission
226
+	 * @return void
227
+	 */
228
+	private function checkPermission($permission)
229
+	{
230
+		$permission = $permission !== 'index' ? $permission : 'list';
231
+		if ($permission == 'method') 
232
+		{
233
+			$error = $this->errorHandler->notFound('method');
234
+			abort($error['status'], $error['message']);
235
+		}
236
+		else if ( ! in_array($permission, $this->skipLoginCheck)) 
237
+		{
238
+			\JWTAuth::parseToken()->authenticate();
239
+			if ( ! in_array($permission, $this->skipPermissionCheck) && ! \Core::users()->can($permission, $this->model))
240
+			{
241
+				$error = $this->errorHandler->noPermissions();
242
+				abort($error['status'], $error['message']);
243
+			}
244
+		}
245
+	}
246 246
 }
Please login to merge, or discard this patch.