Browse Source

fix and add ud transportation

jauhar54 2 years ago
parent
commit
56eaaab09d

+ 3
- 3
app/Http/Controllers/Api/V1/PointLogController.php View File

22
 
22
 
23
     public function getAll()
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
         if($query){
27
         if($query){
28
             $result = $query;
28
             $result = $query;
45
     
45
     
46
     public function getNonEvent()
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
         if($query){
50
         if($query){
51
             $result = $query;
51
             $result = $query;
68
 
68
 
69
     public function getWithEvent()
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
         if($query){
73
         if($query){
74
             $result = $query;
74
             $result = $query;

+ 101
- 2
app/Http/Controllers/Api/V1/TransportationController.php View File

87
             return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
87
             return $this->resSuccess(null, $res_status, $msg, $status_msg, null);
88
         }
88
         }
89
     }
89
     }
90
-
90
+    
91
     public function postStore(Request $request)
91
     public function postStore(Request $request)
92
     {
92
     {
93
         $post = $request->all();
93
         $post = $request->all();
96
         /**digunakan untuk set rule validator */
96
         /**digunakan untuk set rule validator */
97
         $rules = [
97
         $rules = [
98
             'gambar' => 'required',
98
             'gambar' => 'required',
99
+            'user_id' => 'required',
99
             // 'gambar' => 'required|file|max:1000',
100
             // 'gambar' => 'required|file|max:1000',
100
         ];
101
         ];
101
         /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
102
         /**digunakan untuk set message dari validatornya yang akan keluar gimna, :attribue itu udah langsung mendeteksi inputtan dari name="attribue" */
121
             $query->transportation_identity     = $request->transportation_identity;
122
             $query->transportation_identity     = $request->transportation_identity;
122
             $query->transportation_type         = $request->transportation_type;
123
             $query->transportation_type         = $request->transportation_type;
123
             $query->transportation_photo        = Helper::base64_to_image($request->gambar, 'transportation');
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
             $query->save();
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
             if($query){
132
             if($query){
127
                 $result = $query;
133
                 $result = $query;
128
     
134
     
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
     public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
245
     public function resSuccess($param = null, $status = null, $msg = null, $status_msg = null, $result = null)
147
     {
246
     {
148
         $response['response'] = array(
247
         $response['response'] = array(

+ 1
- 5
app/Http/Controllers/Api/V1/UserController.php View File

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

+ 32
- 0
database/migrations/2022_04_11_130837_add_is_approved_to_timelines_table.php View File

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
+}

Loading…
Cancel
Save