소스 검색

get all; delete

develop
Robin Thoni 8 년 전
부모
커밋
0365293c94

+ 31
- 0
app/Http/Business/ImagesBusiness.php 파일 보기

@@ -3,11 +3,13 @@
3 3
 namespace App\Http\Business;
4 4
 
5 5
 use App\Http\DBO\ImageUploadDbo;
6
+use Carbon\Carbon;
6 7
 use Exception;
7 8
 use Luticate\Auth\DBO\LuticateUsersDbo;
8 9
 use Luticate\Utils\LuBusiness;
9 10
 use App\Http\DataAccess\ImagesDataAccess;
10 11
 use App\Http\DBO\ImagesDbo;
12
+use Luticate\Utils\LuLog;
11 13
 
12 14
 class ImagesBusiness extends LuBusiness {
13 15
     
@@ -26,6 +28,21 @@ class ImagesBusiness extends LuBusiness {
26 28
         "-" . time() . "." . self::IMAGES_FORMAT;
27 29
     }
28 30
 
31
+    public static function getAllLite($only_mine, LuticateUsersDbo $_user, $page = 0, $perPage = 20000000)
32
+    {
33
+        return ImagesDataAccess::getAllLite($only_mine, $_user, $page, $perPage);
34
+    }
35
+
36
+    public static function getRawById($image_id)
37
+    {
38
+        /**
39
+         * @var $dbo ImagesDbo
40
+         */
41
+        $dbo = self::getById($image_id);
42
+        echo file_get_contents($dbo->getPath());
43
+        exit;
44
+    }
45
+
29 46
     public static function upload(ImageUploadDbo $image, LuticateUsersDbo $_user)
30 47
     {
31 48
         $path = self::generateImagePath($image, $_user);
@@ -33,6 +50,7 @@ class ImagesBusiness extends LuBusiness {
33 50
         $dbo = new ImagesDbo();
34 51
         $dbo->setUserId($_user->getId());
35 52
         $dbo->setPath($path);
53
+        $dbo->setDate(Carbon::now());
36 54
 
37 55
         $image->getImage()->scaleImage(420, 420, true);
38 56
         $image->getImage()->setImageFormat(self::IMAGES_FORMAT);
@@ -43,6 +61,7 @@ class ImagesBusiness extends LuBusiness {
43 61
         }
44 62
         catch (Exception $e)
45 63
         {
64
+            LuLog::log($e);
46 65
             try
47 66
             {
48 67
                 unlink($path);
@@ -58,10 +77,22 @@ class ImagesBusiness extends LuBusiness {
58 77
 
59 78
     public static function del($image_id, LuticateUsersDbo $_user)
60 79
     {
80
+        /**
81
+         * @var $imageDbo ImagesDbo
82
+         */
61 83
         $imageDbo = self::getById($image_id);
62 84
         if ($imageDbo->getUserId() != $_user->getId()) {
63 85
             self::unauthorized("You do not own this image");
64 86
         }
87
+        self::deleteById($imageDbo->getId());
88
+        try
89
+        {
90
+            unlink($imageDbo->getPath());
91
+        }
92
+        catch (Exception $e)
93
+        {
94
+            LuLog::log($e);
95
+        }
65 96
         return true;
66 97
     }
67 98
 }

+ 10
- 0
app/Http/Controller/ImagesController.php 파일 보기

@@ -15,6 +15,16 @@ class ImagesController extends LuController {
15 15
         return new ImagesBusiness();
16 16
     }
17 17
 
18
+    public function getAll($only_mine, LuticateUsersDbo $_user, $page = 0, $perPage = 20000000)
19
+    {
20
+        return ImagesBusiness::getAllLite($only_mine == "true", $_user, $page, $perPage);
21
+    }
22
+
23
+    public function getRawById($image_id)
24
+    {
25
+        return ImagesBusiness::getRawById($image_id);
26
+    }
27
+
18 28
     public function upload(ImageUploadDbo $image, LuticateUsersDbo $_user)
19 29
     {
20 30
         return ImagesBusiness::upload($image, $_user);

+ 37
- 1
app/Http/DBO/ImagesDbo.php 파일 보기

@@ -16,7 +16,9 @@ class ImagesDbo extends LuDbo {
16 16
         return array(
17 17
             "Id" => $this->_id,
18 18
             "UserId" => $this->_userId,
19
-            "Path" => $this->_path
19
+            "Path" => $this->_path,
20
+            "Date" => $this->_date,
21
+            "Name" => $this->_name
20 22
         );
21 23
     }
22 24
 
@@ -32,6 +34,12 @@ class ImagesDbo extends LuDbo {
32 34
         if (isset($json["Path"])) {
33 35
             $dbo->setPath($json["Path"]);
34 36
         }
37
+        if (isset($json["Date"])) {
38
+            $dbo->setDate($json["Date"]);
39
+        }
40
+        if (isset($json["Name"])) {
41
+            $dbo->setName($json["Name"]);
42
+        }
35 43
         return $dbo;
36 44
     }
37 45
 
@@ -41,6 +49,8 @@ class ImagesDbo extends LuDbo {
41 49
         $dbo->setId(42);
42 50
         $dbo->setUserId(42);
43 51
         $dbo->setPath("sample string");
52
+        $dbo->setDate("sample string");
53
+        $dbo->setName("sample string");
44 54
         return $dbo;
45 55
     }
46 56
 
@@ -82,4 +92,30 @@ class ImagesDbo extends LuDbo {
82 92
     {
83 93
         $this->_path = $value;
84 94
     }
95
+
96
+    /**
97
+     * @var timestamp without time zone
98
+     */
99
+    protected $_date;
100
+    public function getDate()
101
+    {
102
+        return $this->_date;
103
+    }
104
+    public function setDate($value)
105
+    {
106
+        $this->_date = $value;
107
+    }
108
+
109
+    /**
110
+     * @var text
111
+     */
112
+    protected $_name;
113
+    public function getName()
114
+    {
115
+        return $this->_name;
116
+    }
117
+    public function setName($value)
118
+    {
119
+        $this->_name = $value;
120
+    }
85 121
 }

+ 7
- 0
app/Http/DataAccess/ImagesDataAccess.php 파일 보기

@@ -2,6 +2,8 @@
2 2
 
3 3
 namespace App\Http\DataAccess;
4 4
 
5
+use App\Http\DataAccess\SP\SpGetImages;
6
+use Luticate\Auth\DBO\LuticateUsersDbo;
5 7
 use Luticate\Utils\LuDataAccess;
6 8
 use App\Http\DataAccess\Models\Images;
7 9
 use App\Http\DBO\ImagesDbo;
@@ -11,4 +13,9 @@ class ImagesDataAccess extends LuDataAccess {
11 13
     {
12 14
         return new Images();
13 15
     }
16
+
17
+    public static function getAllLite($only_mine, LuticateUsersDbo $_user, $page = 0, $perPage = 20000000)
18
+    {
19
+        return SpGetImages::getMultipleJson($only_mine, $_user->getId(), $page, $perPage);
20
+    }
14 21
 }

+ 4
- 0
app/Http/DataAccess/Models/ImagesModel.php 파일 보기

@@ -28,6 +28,8 @@ class ImagesModel extends LuModel
28 28
         $dbo->setId($this->id);
29 29
         $dbo->setUserId($this->user_id);
30 30
         $dbo->setPath($this->path);
31
+        $dbo->setDate($this->date);
32
+        $dbo->setName($this->name);
31 33
 
32 34
         return $dbo;
33 35
     }
@@ -45,6 +47,8 @@ class ImagesModel extends LuModel
45 47
         $model->id = $dbo->getId();
46 48
         $model->user_id = $dbo->getUserId();
47 49
         $model->path = $dbo->getPath();
50
+        $model->date = $dbo->getDate();
51
+        $model->name = $dbo->getName();
48 52
 
49 53
         return $model;
50 54
     }

+ 160
- 0
app/Http/DataAccess/SP/SpGetImages.php 파일 보기

@@ -0,0 +1,160 @@
1
+<?php
2
+
3
+/**
4
+ * AUTO GENERATED BY LUTICATE GENERATOR
5
+ * ANY CHANGES WILL BE OVERWRITTEN
6
+ */
7
+
8
+namespace App\Http\DataAccess\SP;
9
+
10
+use Luticate\Utils\LuSpDbo;
11
+use Luticate\Utils\LuMultipleDbo;
12
+use Luticate\Utils\LuStringUtils;
13
+use Illuminate\Support\Facades\DB;
14
+
15
+class SpGetImages extends LuSpDbo {
16
+
17
+    /**
18
+    * @param $dam
19
+    * @return \App\Http\DataAccess\SP\SpGetImages|null
20
+    */
21
+    protected static function damToDbo($dam)
22
+    {
23
+        if (is_null($dam))
24
+            return null;
25
+        $dbo = new SpGetImages();
26
+
27
+        $dbo->setId(LuStringUtils::convertJsonString($dam->id));
28
+        $dbo->setName(LuStringUtils::convertJsonString($dam->name));
29
+        $dbo->setUserId(LuStringUtils::convertJsonString($dam->user_id));
30
+        $dbo->setDate(LuStringUtils::convertJsonString($dam->date));
31
+
32
+        return $dbo;
33
+    }
34
+
35
+
36
+    /**
37
+    * @param $_only_mine boolean
38
+    * @param $_user_id_me integer
39
+    * @return \App\Http\DataAccess\SP\SpGetImages[];
40
+    */
41
+    public static function execute($_only_mine, $_user_id_me)
42
+    {
43
+        $values = DB::select('SELECT to_json(data.id) AS id, to_json(data.name) AS name, to_json(data.user_id) AS user_id, to_json(data.date) AS date FROM sp_get_images(:_only_mine, :_user_id_me) data', array(":_only_mine" => $_only_mine, ":_user_id_me" => $_user_id_me));
44
+        $dboValues = array();
45
+        foreach ($values as $value)
46
+            $dboValues[] = self::damToDbo($value);
47
+        return $dboValues;
48
+    }
49
+
50
+    /**
51
+    * @param $_only_mine boolean
52
+    * @param $_user_id_me integer
53
+    * @param $page int The page number, 0 based
54
+    * @param $perPage int The number of items per page
55
+    * @return \Luticate\Utils\LuMultipleDbo;
56
+    */
57
+    public static function getMultipleJson($_only_mine, $_user_id_me, $page, $perPage)
58
+    {
59
+        $values = DB::select('SELECT (SELECT count(*) FROM sp_get_images(:_only_mine, :_user_id_me)) as count, (SELECT json_agg(q) FROM (SELECT * FROM sp_get_images(:_only_mine, :_user_id_me) OFFSET (:page::int * :perPage::int) LIMIT :perPage) q) as data',
60
+            array(":_only_mine" => $_only_mine, ":_user_id_me" => $_user_id_me, ":page" => $page, ":perPage" => $perPage));
61
+        $value = $values[0];
62
+        if (is_null($value->data))
63
+        {
64
+            $value->data = '[]';
65
+        }
66
+        $data = LuStringUtils::convertJsonString($value->data);
67
+        return new LuMultipleDbo($value->count, $data);
68
+    }
69
+
70
+    public function jsonSerialize()
71
+    {
72
+        return array(
73
+            "Id" => $this->_id,
74
+            "Name" => $this->_name,
75
+            "UserId" => $this->_userId,
76
+            "Date" => $this->_date
77
+        );
78
+    }
79
+
80
+    public static function jsonDeserialize($json)
81
+    {
82
+        $dbo = new SpGetImages();
83
+        if (isset($json["Id"])) {
84
+            $dbo->setId($json["Id"]);
85
+        }
86
+        if (isset($json["Name"])) {
87
+            $dbo->setName($json["Name"]);
88
+        }
89
+        if (isset($json["UserId"])) {
90
+            $dbo->setUserId($json["UserId"]);
91
+        }
92
+        if (isset($json["Date"])) {
93
+            $dbo->setDate($json["Date"]);
94
+        }
95
+        return $dbo;
96
+    }
97
+
98
+    public static function generateSample()
99
+    {
100
+        $dbo = new SpGetImages();
101
+        $dbo->setId(42);
102
+        $dbo->setName("sample string");
103
+        $dbo->setUserId(42);
104
+        $dbo->setDate("sample string");
105
+        return $dbo;
106
+    }
107
+
108
+
109
+    /**
110
+    * @var integer
111
+    */
112
+    protected $_id;
113
+    public function getId()
114
+    {
115
+        return $this->_id;
116
+    }
117
+    public function setId($value)
118
+    {
119
+        $this->_id = $value;
120
+    }
121
+
122
+    /**
123
+    * @var text
124
+    */
125
+    protected $_name;
126
+    public function getName()
127
+    {
128
+        return $this->_name;
129
+    }
130
+    public function setName($value)
131
+    {
132
+        $this->_name = $value;
133
+    }
134
+
135
+    /**
136
+    * @var integer
137
+    */
138
+    protected $_userId;
139
+    public function getUserId()
140
+    {
141
+        return $this->_userId;
142
+    }
143
+    public function setUserId($value)
144
+    {
145
+        $this->_userId = $value;
146
+    }
147
+
148
+    /**
149
+    * @var timestamp without time zone
150
+    */
151
+    protected $_date;
152
+    public function getDate()
153
+    {
154
+        return $this->_date;
155
+    }
156
+    public function setDate($value)
157
+    {
158
+        $this->_date = $value;
159
+    }
160
+}

+ 4
- 0
app/Http/DataAccess/SP/src/sp_get_images.sql 파일 보기

@@ -0,0 +1,4 @@
1
+
2
+        SELECT i.id, i.name, i.user_id, i.date
3
+        FROM images i
4
+        WHERE (CASE WHEN _only_mine THEN i.user_id = _user_id_me ELSE TRUE END)

+ 3
- 2
app/Http/routes.php 파일 보기

@@ -17,8 +17,9 @@ $image_id = "{image_id:$int}";
17 17
 
18 18
 $route->post("/api/effects/{effect}/apply", "Effects", "apply", Permissions::UPLOAD);
19 19
 
20
+$route->get("/api/images", "Images", "getAll");
21
+$route->get("/api/images/$image_id", "Images", "getRawById");
20 22
 $route->post("/api/images/upload", "Images", "upload", Permissions::UPLOAD);
21
-
22 23
 $route->post("/api/images/$image_id/del", "Images", "del", Permissions::UPLOAD);
23 24
 
24
-//sleep(2);
25
+sleep(2);

+ 12
- 8
public/app/app.js 파일 보기

@@ -26,20 +26,18 @@ angular.module('app', [
26 26
                 }]
27 27
             });
28 28
 
29
-            $stateProvider.state('home', {
29
+            $stateProvider.state('images', {
30 30
                 url:'/',
31 31
                 parent: 'root',
32
-                title: "Home",
33
-                reloadOnSearch: false,
34
-                templateUrl:'views/home.html',
35
-                controller:'HomeController'
32
+                title: "Images",
33
+                templateUrl:'views/images.html',
34
+                controller:'ImagesController'
36 35
             });
37 36
 
38 37
             $stateProvider.state('login', {
39 38
                 url:'/login',
40 39
                 parent: 'root',
41 40
                 title: "Login",
42
-                reloadOnSearch: false,
43 41
                 templateUrl:'views/login.html',
44 42
                 controller:'LoginController'
45 43
             });
@@ -48,7 +46,6 @@ angular.module('app', [
48 46
                 url:'/signUp',
49 47
                 parent: 'root',
50 48
                 title: "Sign Up",
51
-                reloadOnSearch: false,
52 49
                 templateUrl:'views/signup.html',
53 50
                 controller:'SignUpController'
54 51
             });
@@ -57,11 +54,18 @@ angular.module('app', [
57 54
                 url:'/upload',
58 55
                 parent: 'root',
59 56
                 title: "Upload",
60
-                reloadOnSearch: false,
61 57
                 templateUrl:'views/upload.html',
62 58
                 controller:'UploadController'
63 59
             });
64 60
 
61
+            /*$stateProvider.state('images', {
62
+                url:'/images',
63
+                parent: 'root',
64
+                title: "Images",
65
+                templateUrl:'views/images.html',
66
+                controller:'ImagesController'
67
+            });*/
68
+
65 69
             $urlRouterProvider.otherwise('/');
66 70
 
67 71
             $httpProvider.interceptors.push(['luticateAuthCache', '$injector', '$q',

+ 0
- 4
public/app/controllers/home.controller.js 파일 보기

@@ -1,4 +0,0 @@
1
-angular.module('app')
2
-    .controller('HomeController', ['$scope', '$state', '$mdDialog',
3
-        function($scope, $state, $mdDialog) {
4
-    }]);

+ 36
- 0
public/app/controllers/images.controller.js 파일 보기

@@ -0,0 +1,36 @@
1
+angular.module('app')
2
+    .controller('ImagesController', ['$scope', '$state', '$mdDialog', 'ImagesBusiness', 'luticateAuthCache', 'errorDialogMd',
3
+        function($scope, $state, $mdDialog, ImagesBusiness, luticateAuthCache, errorDialogMd) {
4
+
5
+            $scope.luticateAuthCache = luticateAuthCache;
6
+
7
+            var promiseLoad = {
8
+                id: "promiseLoad",
9
+                loaderGroups: ["images"]
10
+            };
11
+            
12
+            $scope.options = {
13
+                page: 0,
14
+                perPage: 30,
15
+                only_mine: luticateAuthCache.getUser() != null
16
+            };
17
+
18
+            $scope.images = [];
19
+
20
+            $scope.reload = function()
21
+            {
22
+                ImagesBusiness.getAll($scope.options, promiseLoad).then(function(data)
23
+                {
24
+                    $scope.images = data;
25
+                }, errorDialogMd.errorDialog);
26
+            };
27
+
28
+            $scope.delete = function(image_id)
29
+            {
30
+                ImagesBusiness.delete({image_id: image_id}, promiseLoad).then(function (data) {
31
+                    $scope.reload();
32
+                }, errorDialogMd.errorDialog);
33
+            };
34
+
35
+            $scope.reload();
36
+    }]);

+ 1
- 1
public/app/controllers/login.controller.js 파일 보기

@@ -20,7 +20,7 @@ angular.module('app')
20 20
                     password: $scope.user.Password
21 21
                 }).then(function(data)
22 22
                 {
23
-                    $state.go("home");
23
+                    $state.go("images");
24 24
                 }, function (error) {
25 25
                     $scope.error = error;
26 26
                 });

+ 1
- 1
public/app/controllers/toolbar.controller.js 파일 보기

@@ -22,7 +22,7 @@ angular.module('app')
22 22
                 $scope.logout = function () {
23 23
                         luticateAuthUsers.logout().then(function(data)
24 24
                         {
25
-                                $state.go("home");
25
+                                $state.go("images");
26 26
                         });
27 27
                 }
28 28
         }]);

+ 1
- 1
public/app/index.html 파일 보기

@@ -49,10 +49,10 @@
49 49
     <!-- Controller -->
50 50
     <script src="controllers/sidebar.controller.js"></script>
51 51
     <script src="controllers/toolbar.controller.js"></script>
52
-    <script src="controllers/home.controller.js"></script>
53 52
     <script src="controllers/login.controller.js"></script>
54 53
     <script src="controllers/signup.controller.js"></script>
55 54
     <script src="controllers/upload.controller.js"></script>
55
+    <script src="controllers/images.controller.js"></script>
56 56
 
57 57
     <!-- Modal Controller -->
58 58
 

+ 0
- 5
public/app/views/home.html 파일 보기

@@ -1,5 +0,0 @@
1
-<div layout="column" layout-fill layout-align="top center">
2
-    <p>
3
-        Welcome to <span class="strike">500px</span> 420px!
4
-    </p>
5
-</div>

+ 14
- 0
public/app/views/images.html 파일 보기

@@ -0,0 +1,14 @@
1
+<div layout="column" layout-fill layout-align="top center">
2
+    <div class="col-xs-12" lu-busy="images">
3
+        <div class="col-xs-12">
4
+            <md-checkbox ng-model="options.only_mine" ng-show="luticateAuthCache.getUser() != null" ng-change="reload()">
5
+                Only my images
6
+            </md-checkbox>
7
+        </div>
8
+        <div ng-repeat="image in images.Data" class="col-xs-3">
9
+            <img ng-src="/api/images/{{image.Id}}" />
10
+            <p>{{image.Name}}</p>
11
+            <button class="btn btn-danger" ng-click="delete(image.Id)" ng-show="image.UserId == luticateAuthCache.getUser().Id">Delete</button>
12
+        </div>
13
+    </div>
14
+</div>

+ 1
- 1
public/app/views/sidebar.html 파일 보기

@@ -1,6 +1,6 @@
1 1
 <md-sidenav layout="column" class="md-sidenav-left md-whiteframe-z2" md-component-id="left" md-is-locked-open="$mdMedia('gt-md')">
2 2
     <md-toolbar class="md-theme-indigo">
3
-        <h1 class="md-toolbar-tools"><a ui-sref="home">420px</a></h1>
3
+        <h1 class="md-toolbar-tools"><a ui-sref="images">420px</a></h1>
4 4
     </md-toolbar>
5 5
     <md-content layout-padding ng-controller="SideBarController">
6 6
         <div lu-busy="sidebar">

+ 2
- 0
public/sdk/Business/images.js 파일 보기

@@ -9,6 +9,8 @@
9 9
 
10 10
         Business.getAll = ImagesDataAccess.getAll;
11 11
 
12
+        Business.delete = ImagesDataAccess.delete;
13
+
12 14
         Business.upload = function(data, promise)
13 15
         {
14 16
             data.image = btoa(data.image);

+ 5
- 0
public/sdk/DataAccess/images.js 파일 보기

@@ -14,6 +14,11 @@
14 14
             return luticateRequest.get(entry_point, data, promise);
15 15
         };
16 16
 
17
+        DataAccess.delete = function(data, promise)
18
+        {
19
+            return luticateRequest.post(entry_point + data.image_id + "/del", null, null, promise);
20
+        };
21
+
17 22
         DataAccess.upload = function(data, promise)
18 23
         {
19 24
             return luticateRequest.post(entry_point + "upload", {image: JSON.stringify(data)}, null, promise);

Loading…
취소
저장