From 7f772529c6904887826f7b053f1eec9017415d98 Mon Sep 17 00:00:00 2001 From: MuhammadNazhimMaulana Date: Sun, 10 Mar 2024 18:36:12 +0700 Subject: [PATCH] Hotfixing API --- app/Http/Controllers/API/PostController.php | 3 +++ app/Http/Controllers/API/UserController.php | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/API/PostController.php b/app/Http/Controllers/API/PostController.php index 7fe1fa3..16a4108 100644 --- a/app/Http/Controllers/API/PostController.php +++ b/app/Http/Controllers/API/PostController.php @@ -50,6 +50,7 @@ public function store(Request $request) $post->content = $request->content; $post->save(); + DB::commit(); return $this->success($post); }catch(Exception $e){ DB::rollback(); @@ -79,6 +80,7 @@ public function update(int $id, Request $request) $post->content = $request->content; $post->save(); + DB::commit(); return $this->success($post); }catch(Exception $e){ DB::rollback(); @@ -98,6 +100,7 @@ public function delete(int $id) // Delete User $post->delete(); + DB::commit(); return $this->success('Post Deleted'); }catch(Exception $e){ DB::rollback(); diff --git a/app/Http/Controllers/API/UserController.php b/app/Http/Controllers/API/UserController.php index 3fb9361..20c002c 100644 --- a/app/Http/Controllers/API/UserController.php +++ b/app/Http/Controllers/API/UserController.php @@ -7,6 +7,7 @@ use App\Models\User; use App\Traits\ResponseBuilder; use Illuminate\Support\Facades\DB; +use Carbon\Carbon; use Exception; class UserController extends Controller @@ -53,9 +54,10 @@ public function store(Request $request) $user->email = $request->email; $user->gender = $request->gender; $user->short_description = $request->short_description; - $user->date_of_birth = $request->date_of_birth; + $user->date_of_birth = Carbon::createFromDate($request->date_of_birth)->toDateString(); $user->save(); - + + DB::commit(); return $this->success($user); }catch(Exception $e){ DB::rollback(); @@ -90,6 +92,7 @@ public function update(int $id, Request $request) $user->date_of_birth = $request->date_of_birth; $user->save(); + DB::commit(); return $this->success($user); }catch(Exception $e){ DB::rollback(); @@ -118,6 +121,7 @@ public function delete(int $id) // Delete User $user->delete(); + DB::commit(); return $this->success('User Deleted'); }catch(Exception $e){ DB::rollback();