From 209b1f2530aa10b130ca4134bc469342018a8691 Mon Sep 17 00:00:00 2001 From: "m.razaghi" Date: Thu, 16 Jul 2026 14:58:11 +0330 Subject: [PATCH] Fixed api issue --- .../Controllers/api/BylawNoteController.php | 17 +++++++++-------- .../api/JudicialPrecedentNoteController.php | 11 +++++------ .../api/LegalOpinionNoteController.php | 12 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/app/Http/Controllers/api/BylawNoteController.php b/app/Http/Controllers/api/BylawNoteController.php index 1408db2..64d728a 100644 --- a/app/Http/Controllers/api/BylawNoteController.php +++ b/app/Http/Controllers/api/BylawNoteController.php @@ -14,19 +14,19 @@ class BylawNoteController extends Controller public function create(Request $request) { $validated = $request->validate([ - 'bylaw_document_id' => 'required', + 'bylaw_id' => 'required', // Cleaned up for the frontend! 'note' => 'required', 'color_code' => 'nullable', ]); BylawNote::query()->create([ - 'user_id' => auth()->user()->id, - 'bylaw_document_id' => $validated['bylaw_document_id'], + 'user_id' => auth()->id(), + 'bylaw_document_id' => $validated['bylaw_id'], // Maps perfectly to the DB 'note' => $validated['note'], 'color_code' => $validated['color_code'], ]); - return $this->success([], 'با موفقیت اضافه شد'); + return $this->success([], 'موفق', 'یادداشت با موفقیت اضافه شد'); } public function update($id, Request $request) @@ -36,20 +36,21 @@ class BylawNoteController extends Controller 'color_code' => 'nullable', ]); - $note = BylawNote::findOrFail($id); + $note = BylawNote::where('user_id', auth()->id())->findOrFail($id); + $note->update([ 'note' => $validated['note'], 'color_code' => $validated['color_code'], ]); - return $this->success([], 'بروز شد'); + return $this->success([], 'بروزرسانی', 'یادداشت با موفقیت بروزرسانی شد'); } public function destroy($id) { - $note = BylawNote::findOrFail($id); + $note = BylawNote::where('user_id', auth()->id())->findOrFail($id); $note->delete(); - return $this->success([], 'حذف شد'); + return $this->success([], 'حذف', 'یادداشت با موفقیت حذف شد'); } } diff --git a/app/Http/Controllers/api/JudicialPrecedentNoteController.php b/app/Http/Controllers/api/JudicialPrecedentNoteController.php index 5634ea0..44a1afd 100644 --- a/app/Http/Controllers/api/JudicialPrecedentNoteController.php +++ b/app/Http/Controllers/api/JudicialPrecedentNoteController.php @@ -14,19 +14,19 @@ class JudicialPrecedentNoteController extends Controller public function create(Request $request) { $validated = $request->validate([ - 'judicial_precedent_id' => 'required', + 'judicial_id' => 'required', // Cleaned up! 'note' => 'required', 'color_code' => 'nullable', ]); JudicialPrecedentNote::query()->create([ 'user_id' => auth()->id(), - 'judicial_precedent_id' => $validated['judicial_precedent_id'], + 'judicial_precedent_id' => $validated['judicial_id'], // Maps to DB 'note' => $validated['note'], 'color_code' => $validated['color_code'], ]); - return $this->success([], 'با موفقیت اضافه شد'); + return $this->success([], 'موفق', 'یادداشت با موفقیت اضافه شد'); } public function update($id, Request $request) @@ -36,7 +36,6 @@ class JudicialPrecedentNoteController extends Controller 'color_code' => 'nullable', ]); - // SECURITY FIX: Only allow the owner of the note to update it $note = JudicialPrecedentNote::where('user_id', auth()->id())->findOrFail($id); $note->update([ @@ -44,7 +43,7 @@ class JudicialPrecedentNoteController extends Controller 'color_code' => $validated['color_code'], ]); - return $this->success([], 'بروز شد'); + return $this->success([], 'بروزرسانی', 'یادداشت با موفقیت بروزرسانی شد'); } public function destroy($id) @@ -52,6 +51,6 @@ class JudicialPrecedentNoteController extends Controller $note = JudicialPrecedentNote::where('user_id', auth()->id())->findOrFail($id); $note->delete(); - return $this->success([], 'حذف شد'); + return $this->success([], 'حذف', 'یادداشت با موفقیت حذف شد'); } } diff --git a/app/Http/Controllers/api/LegalOpinionNoteController.php b/app/Http/Controllers/api/LegalOpinionNoteController.php index 81ae189..7a6a56f 100644 --- a/app/Http/Controllers/api/LegalOpinionNoteController.php +++ b/app/Http/Controllers/api/LegalOpinionNoteController.php @@ -14,19 +14,19 @@ class LegalOpinionNoteController extends Controller public function create(Request $request) { $validated = $request->validate([ - 'legal_opinion_id' => 'required', + 'opinion_id' => 'required', // Cleaned up! 'note' => 'required', 'color_code' => 'nullable', ]); LegalOpinionNote::query()->create([ - 'user_id' => auth()->id(), // Cleaner way to get the user ID - 'legal_opinion_id' => $validated['legal_opinion_id'], + 'user_id' => auth()->id(), + 'legal_opinion_id' => $validated['opinion_id'], // Maps to DB 'note' => $validated['note'], 'color_code' => $validated['color_code'], ]); - return $this->success([], 'با موفقیت اضافه شد'); + return $this->success([], 'موفق', 'یادداشت با موفقیت اضافه شد'); } public function update($id, Request $request) @@ -43,7 +43,7 @@ class LegalOpinionNoteController extends Controller 'color_code' => $validated['color_code'], ]); - return $this->success([], 'بروز شد'); + return $this->success([], 'بروزرسانی', 'یادداشت با موفقیت بروزرسانی شد'); } public function destroy($id) @@ -51,6 +51,6 @@ class LegalOpinionNoteController extends Controller $note = LegalOpinionNote::where('user_id', auth()->id())->findOrFail($id); $note->delete(); - return $this->success([], 'حذف شد'); + return $this->success([], 'حذف', 'یادداشت با موفقیت حذف شد'); } }