Przeglądaj źródła

fix and add ud transportation

jauhar54 2 lat temu
rodzic
commit
56eaaab09d

+ 3
- 3
app/Http/Controllers/Api/V1/PointLogController.php Wyświetl plik

@@ -22,7 +22,7 @@ class PointLogController extends Controller
22 22
 
23 23
     public function getAll()
24 24
     {
25
-        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->get();
25
+        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
26 26
 
27 27
         if($query){
28 28
             $result = $query;
@@ -45,7 +45,7 @@ class PointLogController extends Controller
45 45
     
46 46
     public function getNonEvent()
47 47
     {
48
-        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 0)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->get();
48
+        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 0)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
49 49
 
50 50
         if($query){
51 51
             $result = $query;
@@ -68,7 +68,7 @@ class PointLogController extends Controller
68 68
 
69 69
     public function getWithEvent()
70 70
     {
71
-        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 1)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->get();
71
+        $query = User::select('users.name', 'users.id as user_id', DB::raw('SUM(point_logs.point) as total_point'))->rightJoin('point_logs', 'point_logs.user_id', 'users.id')->where('event_id', '=', 1)->groupBy('point_logs.user_id')->orderBy('total_point', 'desc')->limit(5)->get();
72 72
 
73 73
         if($query){
74 74
             $result = $query;

+ 101
- 2
app/Http/Controllers/Api/V1/TransportationController.php Wyświetl plik

@@ -87,7 +87,7 @@ class TransportationController extends Controller
87 87
             return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
88 88
         }
89 89
     }
90
-
90
+    
91 91
     public function postStore(Request $request)
92 92
     {
93 93
         $post = $request->all();
@@ -96,6 +96,7 @@ class TransportationController extends Controller
96 96
         /**digunakan untuk set rule validator */
97 97
         $rules = [
98 98
             'gambar' => 'required',
99
+            'user_id' => 'required',
99 100
             // 'gambar' => 'required|file|max:1000',
100 101
         ];
101 102
         /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
@@ -121,8 +122,13 @@ class TransportationController extends Controller
121 122
             $query->transportation_identity     = $request->transportation_identity;
122 123
             $query->transportation_type         = $request->transportation_type;
123 124
             $query->transportation_photo        = Helper::base64_to_image($request->gambar, 'transportation');
124
-            $query->user_id                     = 123456;
125
+            $query->user_id                     = Helper::hash(Request::all()['user_id'], 'decode');
125 126
             $query->save();
127
+
128
+            $query->hash_id = Helper::hash($query->id, 'encode');
129
+            $query->user_id = Helper::hash($query->user_id, 'encode');
130
+
131
+
126 132
             if($query){
127 133
                 $result = $query;
128 134
     
@@ -143,6 +149,99 @@ class TransportationController extends Controller
143 149
         }
144 150
     }
145 151
 
152
+    public function postUpdate(Request $request)
153
+    {        
154
+        $post = $request->all();
155
+
156
+        $rules = [
157
+            'id' => 'required',
158
+            'gambar' => 'required',
159
+            'user_id' => 'required',
160
+        ];
161
+
162
+        $validator = Validator::make($post, $rules);
163
+
164
+        if(!$validator->fails()){
165
+            $transportation = Transportation::where('id', Helper::hash(Request::all()['id'], 'decode'))->firstOrFail();
166
+            
167
+            $transportation->name                        = $request->name;
168
+            $transportation->transportation_identity     = $request->transportation_identity;
169
+            $transportation->transportation_type         = $request->transportation_type;
170
+            $transportation->transportation_photo        = Helper::base64_to_image($request->gambar, 'transportation');
171
+            $transportation->user_id                     = Helper::hash(Request::all()['user_id'], 'decode');
172
+            $transportation->save();
173
+
174
+            $transportation->hash_id = Helper::hash($transportation->id, 'encode');
175
+            $transportation->user_id = Helper::hash($transportation->user_id, 'encode');
176
+
177
+            $result = $transportation;
178
+            $res_status = true;
179
+            $msg = 'Berhasil membuat user';
180
+            $status_msg = $msg;
181
+
182
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
183
+
184
+        }else {
185
+
186
+            $res_status = false;
187
+            $msg = 'Gagal Membuat user';
188
+            $status_msg = $validator->errors();
189
+
190
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
191
+        }
192
+    }
193
+
194
+    public function delete()
195
+    {
196
+        $validator = Validator::make(Request::all(), [
197
+            'id' => ['required'],
198
+        ]);
199
+        if(!$validator->fails()){
200
+            $query = Transportation::find(Helper::hash(Request::all()['id'], 'decode'))->detroy();
201
+
202
+            if($query){
203
+                $result = $query;
204
+                $res_status = true;
205
+                $msg = 'Data berhasil dihapus';
206
+                $status_msg = $msg;
207
+
208
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
209
+            }else{
210
+                $result = $query;
211
+                $res_status = false;
212
+                $msg = 'Data gagal dihapus';
213
+                $status_msg = $msg;
214
+
215
+                return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
216
+            }
217
+        }else{
218
+            $res_status = false;
219
+            $msg = 'Data tidak ditemukan';
220
+            $status_msg = $validator->errors();
221
+
222
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
223
+        }
224
+        
225
+
226
+        if($query){
227
+            $result = $query;
228
+
229
+            $res_status = true;
230
+            $msg = 'Mendapatkan Data';
231
+            $status_msg = $msg;
232
+
233
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, $result);
234
+
235
+        }else {
236
+
237
+            $res_status = false;
238
+            $msg = 'Data tidak ditemukan';
239
+            $status_msg = $msg;
240
+
241
+            return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
242
+        }
243
+    }
244
+
146 245
     public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
147 246
     {
148 247
         $response['response'] = array(

+ 1
- 5
app/Http/Controllers/Api/V1/UserController.php Wyświetl plik

@@ -82,7 +82,7 @@ class UserController extends Controller
82 82
         }else {
83 83
 
84 84
             $res_status = false;
85
-            $msg = 'Data tidak ditemukan';
85
+            $msg = 'Email atau Password yang anda masukkan salah';
86 86
             $status_msg = $msg;
87 87
 
88 88
             return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
@@ -147,7 +147,6 @@ class UserController extends Controller
147 147
             'gender' => ['required'],
148 148
             'is_have_organization' => ['required'],
149 149
             'organization_id' => [],
150
-            'id_member' => [],
151 150
         ]);
152 151
 
153 152
         if(!$validator->fails()){
@@ -158,7 +157,6 @@ class UserController extends Controller
158 157
                 'gender' => $request->gender,
159 158
                 'is_have_organization' => $request->is_have_organization,
160 159
                 'organization_id' => !empty($request->organization_id)?$request->organization_id:NULL,
161
-                'id_member' => !empty($request->id_member)?$request->id_member:'',
162 160
             ]);
163 161
 
164 162
             $res_status = true;
@@ -186,7 +184,6 @@ class UserController extends Controller
186 184
             'gender' => ['required'],
187 185
             'is_have_organization' => ['required'],
188 186
             'organization_id' => [],
189
-            'id_member' => [],
190 187
         ]);
191 188
 
192 189
         if(!$validator->fails()){
@@ -198,7 +195,6 @@ class UserController extends Controller
198 195
             $profile->gender = $request->gender;
199 196
             $profile->is_have_organization = $request->is_have_organization;
200 197
             $profile->organization_id = !empty($request->organization_id)?$request->organization_id:'';
201
-            $profile->id_member = !empty($request->id_member)?$request->id_member:'';
202 198
 
203 199
             $res_status = true;
204 200
             $msg = 'Berhasil membuat user';

+ 32
- 0
database/migrations/2022_04_11_130837_add_is_approved_to_timelines_table.php Wyświetl plik

@@ -0,0 +1,32 @@
1
+<?php
2
+
3
+use Illuminate\Database\Migrations\Migration;
4
+use Illuminate\Database\Schema\Blueprint;
5
+use Illuminate\Support\Facades\Schema;
6
+
7
+class AddIsApprovedToTimelinesTable extends Migration
8
+{
9
+    /**
10
+     * Run the migrations.
11
+     *
12
+     * @return void
13
+     */
14
+    public function up()
15
+    {
16
+        Schema::table('timelines', function (Blueprint $table) {
17
+            $table->enum('is_approved', ['yes', 'no']);
18
+        });
19
+    }
20
+
21
+    /**
22
+     * Reverse the migrations.
23
+     *
24
+     * @return void
25
+     */
26
+    public function down()
27
+    {
28
+        Schema::table('timelines', function (Blueprint $table) {
29
+            $table->dropColumn('is_approved');
30
+        });
31
+    }
32
+}

Ładowanie…
Anuluj
Zapisz