From 6d8bfa260279bfd86efd656177adc77167001522 Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 19 Oct 2023 13:24:58 +0700 Subject: [PATCH 1/3] Fix endline --- .../Controllers/ActivityDokumenController.php | 190 +++++++++--------- 1 file changed, 95 insertions(+), 95 deletions(-) diff --git a/app/Http/Controllers/ActivityDokumenController.php b/app/Http/Controllers/ActivityDokumenController.php index f3a1143..999e860 100644 --- a/app/Http/Controllers/ActivityDokumenController.php +++ b/app/Http/Controllers/ActivityDokumenController.php @@ -1,95 +1,95 @@ -json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); - - $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); - return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); - } - - public function delete($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - - $document = ActivityDokumen::find($id); - - if(!$document) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); - - if(file_exists($this->pathActivityDocument.$document->file)) - unlink($this->pathActivityDocument.$document->file); - - $document->delete(); - return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); - } - - public function uploadProjectDokumen(Request $request) - { - if(!$request->hasFile('dokumen')) - return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); - - $activity_id = $request->activity_id; - $document = $request->file('dokumen'); - $name = $document->getClientOriginalName(); - - $result = $document->move($this->pathActivityDocument, $name); - - if(!$result) - return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); - - $data = [ - 'activity_id' => (int)$activity_id, - 'file' => $name, - 'description' => $request->description - ]; - - $result = ActivityDokumen::create($data); - - if(!$result){ - unlink($this->pathActivityDocument.$name); - return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); - } - - return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); - } - - public function searchDocProject(Request $request){ - $payload = $request->all(); - - $dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); - $builder = $dataBuilder['builder']; - $countBuilder = $dataBuilder['count']; - $dataGet = $builder->get(); - $totalRecord = $countBuilder->count(); - - return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); - } - - public function downloadDokumen($id) - { - if(empty($id) || !is_int((int)$id)) - return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); - - $document = ActivityDokumen::find($id); - - if(!$document) - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); - - if(file_exists($this->pathActivityDocument.$document->file)){ - $pathToFile = $this->pathActivityDocument.$document->file; - return response()->download($pathToFile); - } - - return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); - } -} +json(['status'=>'failed','message'=>'activity id is required!','code'=>400], 400); + + $dataDokumen = ActivityDokumen::where("activity_id", $id)->get(); + return response()->json(['status'=>'success','data'=>$dataDokumen,'code'=>200], 200); + } + + public function delete($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); + + $document = ActivityDokumen::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=> 404], 404); + + if(file_exists($this->pathActivityDocument.$document->file)) + unlink($this->pathActivityDocument.$document->file); + + $document->delete(); + return response()->json(['status'=>'success','message'=>'Dokumen deleted successfully!','code'=>200], 200); + } + + public function uploadProjectDokumen(Request $request) + { + if(!$request->hasFile('dokumen')) + return response()->json(['status'=>'failed','message'=>'file is required!','code'=>400], 400); + + $activity_id = $request->activity_id; + $document = $request->file('dokumen'); + $name = $document->getClientOriginalName(); + + $result = $document->move($this->pathActivityDocument, $name); + + if(!$result) + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + + $data = [ + 'activity_id' => (int)$activity_id, + 'file' => $name, + 'description' => $request->description + ]; + + $result = ActivityDokumen::create($data); + + if(!$result){ + unlink($this->pathActivityDocument.$name); + return response()->json(['status'=>'failed','message'=>'Upload failed!','code'=> 500], 500); + } + + return response()->json(['status'=>'success','message'=>'Upload success!','code'=>200], 200); + } + + public function searchDocProject(Request $request){ + $payload = $request->all(); + + $dataBuilder = $this->setUpPayload($payload, 'm_document_activity'); + $builder = $dataBuilder['builder']; + $countBuilder = $dataBuilder['count']; + $dataGet = $builder->get(); + $totalRecord = $countBuilder->count(); + + return response()->json(['status'=>'success','code'=>200,'data'=>$dataGet, 'totalRecord'=>$totalRecord], 200); + } + + public function downloadDokumen($id) + { + if(empty($id) || !is_int((int)$id)) + return response()->json(['status'=>'failed','message'=>'Id is required!','code'=>400], 400); + + $document = ActivityDokumen::find($id); + + if(!$document) + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + + if(file_exists($this->pathActivityDocument.$document->file)){ + $pathToFile = $this->pathActivityDocument.$document->file; + return response()->download($pathToFile); + } + + return response()->json(['status'=>'failed','message'=>'Data not found!','code'=>400], 400); + } +} From 66e72be3a2883ead8e2ab659fac2ab54a18773af Mon Sep 17 00:00:00 2001 From: wahyu Date: Thu, 19 Oct 2023 14:11:48 +0700 Subject: [PATCH 2/3] access creator only --- app/Http/Controllers/ProjectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 46c529d..91fbb3d 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,7 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; - // $builder->where("selfTable.created_by",$this->currentName); + $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -276,7 +276,7 @@ class ProjectController extends Controller 'updated_at', 'updated_by' )->orderBy('id', 'desc') - // ->where("created_by",$this->currentName) + ->where("created_by",$this->currentName) ->get(); $countData = $data->count(); From 736eb9c617e41c4f5c0bd08b962ceaae6551b613 Mon Sep 17 00:00:00 2001 From: wahyu Date: Fri, 20 Oct 2023 11:11:28 +0700 Subject: [PATCH 3/3] disable created by --- app/Http/Controllers/ProjectController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 301dc42..39042ec 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -229,7 +229,7 @@ class ProjectController extends Controller $dataBuilder = $this->setUpPayload($payload, 'm_proyek'); $builder = $dataBuilder['builder']; $countBuilder = $dataBuilder['count']; - $builder->where("selfTable.created_by",$this->currentName); + // $builder->where("selfTable.created_by",$this->currentName); $dataGet = $builder->get(); $totalRecord = $countBuilder->count(); @@ -276,7 +276,7 @@ class ProjectController extends Controller 'updated_at', 'updated_by' )->orderBy('id', 'desc') - ->where("created_by",$this->currentName) + // ->where("created_by",$this->currentName) ->get(); $countData = $data->count();