Browse Source

deleteById return; controller abstract

tags/0.1.0
Robin Thoni 8 years ago
parent
commit
1231cd8daf
3 changed files with 18 additions and 3 deletions
  1. 5
    1
      src/Utils/LuBusiness.php
  2. 10
    1
      src/Utils/LuController.php
  3. 3
    1
      src/Utils/LuDataAccess.php

+ 5
- 1
src/Utils/LuBusiness.php View File

@@ -116,10 +116,14 @@ abstract class LuBusiness {
116 116
 
117 117
     /**
118 118
      * @param $id int
119
+     * @return true
119 120
      */
120 121
     public static function deleteById($id)
121 122
     {
122
-        static::getDataAccess()->deleteById($id);
123
+        $res = static::getDataAccess()->deleteById($id);
124
+        if (!$res)
125
+            self::notFound(static::getResourceName() . " not found");
126
+        return true;
123 127
     }
124 128
 
125 129
     /**

+ 10
- 1
src/Utils/LuController.php View File

@@ -4,6 +4,15 @@ namespace Luticate\Utils;
4 4
 
5 5
 use Laravel\Lumen\Routing\Controller as BaseController;
6 6
 
7
-class LuController extends BaseController
7
+abstract class LuController extends BaseController
8 8
 {
9
+    /**
10
+     * @return LuBusiness
11
+     */
12
+    protected abstract function getBusiness();
13
+
14
+    public function getAll($page = 0, $perPage = PHP_INT_MAX)
15
+    {
16
+        return self::getBusiness()->getAll($page, $perPage);
17
+    }
9 18
 }

+ 3
- 1
src/Utils/LuDataAccess.php View File

@@ -41,13 +41,15 @@ abstract class LuDataAccess {
41 41
 
42 42
     /**
43 43
      * @param $id int
44
+     * @return bool
44 45
      */
45 46
     public static function deleteById($id)
46 47
     {
47 48
         $data = self::_getModelById($id);
48 49
         if (is_null($data))
49
-            return;
50
+            return false;
50 51
         $data->delete();
52
+        return true;
51 53
     }
52 54
 
53 55
     /**

Loading…
Cancel
Save