Skip to content

Commit

Permalink
Hotfixing API
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhammadNazhimMaulana committed Mar 10, 2024
1 parent b493d38 commit 7f77252
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 3 additions & 0 deletions app/Http/Controllers/API/PostController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down
8 changes: 6 additions & 2 deletions app/Http/Controllers/API/UserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 7f77252

Please sign in to comment.