diff --git a/app/Http/Controllers/api/ArtController.php b/app/Http/Controllers/api/ArtController.php index 6615d91..f30336d 100644 --- a/app/Http/Controllers/api/ArtController.php +++ b/app/Http/Controllers/api/ArtController.php @@ -96,7 +96,8 @@ class ArtController extends Controller } $art->is_like = $this->isLiked($art->id); - $art->note = Note::select('id', 'note', 'color_code', 'created_at')->where('user_id', auth()->user()->id)->where('art_id', $id)->get(); + $art->note = Note::select('id', 'note', 'color_code', 'created_at')->where('user_id', auth()->id())->where('art_id', $id)->get(); + $art->highlight = \App\Models\ArtHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code')->where('user_id', auth()->id())->where('art_id', $id)->get(); $art->category = $law?->category?->name; $art->route = array_values($this->route(Art::class, $art)); @@ -109,7 +110,8 @@ class ArtController extends Controller if ($previousArt) { $previousLaw = Law::find($previousArt->law_id); $previousArt->is_like = $this->isLiked($previousArt->id); - $previousArt->note = Note::select('id', 'note', 'color_code')->where('user_id', auth()->user()->id)->where('art_id', $previousArt->id)->get(); + $previousArt->note = Note::select('id', 'note', 'color_code')->where('user_id', auth()->id())->where('art_id', $previousArt->id)->get(); + $previousArt->highlight = \App\Models\ArtHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code')->where('user_id', auth()->id())->where('art_id', $previousArt->id)->get(); $previousArt->category = $previousLaw?->category?->name; $previousArt->route = array_values($this->route(Art::class, $previousArt)); } @@ -123,7 +125,8 @@ class ArtController extends Controller if ($nextArt) { $nextLaw = Law::find($nextArt->law_id); $nextArt->is_like = $this->isLiked($nextArt->id); - $nextArt->note = Note::select('id', 'note', 'color_code')->where('user_id', auth()->user()->id)->where('art_id', $nextArt->id)->get(); + $nextArt->note = Note::select('id', 'note', 'color_code')->where('user_id', auth()->id())->where('art_id', $nextArt->id)->get(); + $nextArt->highlight = \App\Models\ArtHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code')->where('user_id', auth()->id())->where('art_id', $nextArt->id)->get(); $nextArt->category = $nextLaw?->category?->name; $nextArt->route = array_values($this->route(Art::class, $nextArt)); } diff --git a/app/Http/Controllers/api/ArtHighlightController.php b/app/Http/Controllers/api/ArtHighlightController.php new file mode 100644 index 0000000..d891202 --- /dev/null +++ b/app/Http/Controllers/api/ArtHighlightController.php @@ -0,0 +1,58 @@ +validate([ + 'art_id' => 'required', + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + ArtHighlight::create([ + 'user_id' => auth()->id(), + 'art_id' => $validated['art_id'], + 'start_index' => $validated['start_index'], + 'end_index' => $validated['end_index'], + 'selected_text' => $validated['selected_text'], + 'color_code' => $validated['color_code'], + ]); + + return $this->success([], 'موفق', 'هایلایت با موفقیت اضافه شد'); + } + + public function update($id, Request $request) + { + $validated = $request->validate([ + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + $highlight = ArtHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->update($validated); + + return $this->success([], 'بروزرسانی', 'هایلایت با موفقیت بروزرسانی شد'); + } + + public function destroy($id) + { + $highlight = ArtHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->delete(); + + return $this->success([], 'حذف', 'هایلایت با موفقیت حذف شد'); + } +} diff --git a/app/Http/Controllers/api/BylawApiController.php b/app/Http/Controllers/api/BylawApiController.php index ca5c674..2d3c6c1 100644 --- a/app/Http/Controllers/api/BylawApiController.php +++ b/app/Http/Controllers/api/BylawApiController.php @@ -126,6 +126,12 @@ class BylawApiController extends Controller ->where('bylaw_document_id', $bylaw->id) ->get(); + $formatted['highlight'] = \App\Models\BylawHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code') + ->where('user_id', auth()->id()) + ->where('bylaw_document_id', $bylaw->id) + ->get(); + + if (!$formatted['is_locked']) { $eloquentNodes = BylawNode::with('type') ->where('document_id', $bylaw->id) @@ -353,6 +359,11 @@ class BylawApiController extends Controller ->where('bylaw_document_id', $item->id) ->get(); + $formatted['highlight'] = \App\Models\BylawHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code') + ->where('user_id', auth()->id()) + ->where('bylaw_document_id', $item->id) + ->get(); + return $formatted; })->values()->toArray(); diff --git a/app/Http/Controllers/api/BylawHighlightController.php b/app/Http/Controllers/api/BylawHighlightController.php new file mode 100644 index 0000000..8120194 --- /dev/null +++ b/app/Http/Controllers/api/BylawHighlightController.php @@ -0,0 +1,58 @@ +validate([ + 'bylaw_id' => 'required', // Clean request parameter + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + BylawHighlight::create([ + 'user_id' => auth()->id(), + 'bylaw_document_id' => $validated['bylaw_id'], // Mapped to DB column + 'start_index' => $validated['start_index'], + 'end_index' => $validated['end_index'], + 'selected_text' => $validated['selected_text'], + 'color_code' => $validated['color_code'], + ]); + + return $this->success([], 'موفق', 'هایلایت با موفقیت اضافه شد'); + } + + public function update($id, Request $request) + { + $validated = $request->validate([ + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + $highlight = BylawHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->update($validated); + + return $this->success([], 'بروزرسانی', 'هایلایت با موفقیت بروزرسانی شد'); + } + + public function destroy($id) + { + $highlight = BylawHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->delete(); + + return $this->success([], 'حذف', 'هایلایت با موفقیت حذف شد'); + } +} diff --git a/app/Http/Controllers/api/JudicialPrecedentApiController.php b/app/Http/Controllers/api/JudicialPrecedentApiController.php index a7f7541..80f6be5 100644 --- a/app/Http/Controllers/api/JudicialPrecedentApiController.php +++ b/app/Http/Controllers/api/JudicialPrecedentApiController.php @@ -163,21 +163,29 @@ class JudicialPrecedentApiController extends Controller }); })->orderBy('ruling_date', 'asc')->orderBy('id', 'asc')->first(); - // Apply format and add Notes - $formatWithNote = function($item) { + // Apply format and add Notes & Highlights + $formatWithNoteAndHighlight = function($item) { if (!$item) return null; $formatted = $this->formatItem($item); + $formatted['note'] = \App\Models\JudicialPrecedentNote::select('id', 'note', 'color_code', 'created_at') - ->where('user_id', auth()->user()->id) + ->where('user_id', auth()->id()) ->where('judicial_precedent_id', $item->id) ->get(); + + // NEW: Fetch Highlights + $formatted['highlight'] = \App\Models\JudicialPrecedentHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code') + ->where('user_id', auth()->id()) + ->where('judicial_precedent_id', $item->id) + ->get(); + return $formatted; }; $results = array_values(array_filter([ - $previousItem ? $formatWithNote($previousItem) : null, - $formatWithNote($current), - $nextItem ? $formatWithNote($nextItem) : null + $previousItem ? $formatWithNoteAndHighlight($previousItem) : null, + $formatWithNoteAndHighlight($current), + $nextItem ? $formatWithNoteAndHighlight($nextItem) : null ])); return $this->success($results, 'Success', 'Pager Window Details'); diff --git a/app/Http/Controllers/api/JudicialPrecedentHighlightController.php b/app/Http/Controllers/api/JudicialPrecedentHighlightController.php new file mode 100644 index 0000000..21c36d7 --- /dev/null +++ b/app/Http/Controllers/api/JudicialPrecedentHighlightController.php @@ -0,0 +1,58 @@ +validate([ + 'judicial_id' => 'required', + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + JudicialPrecedentHighlight::create([ + 'user_id' => auth()->id(), + 'judicial_precedent_id' => $validated['judicial_id'], + 'start_index' => $validated['start_index'], + 'end_index' => $validated['end_index'], + 'selected_text' => $validated['selected_text'], + 'color_code' => $validated['color_code'], + ]); + + return $this->success([], 'موفق', 'هایلایت با موفقیت اضافه شد'); + } + + public function update($id, Request $request) + { + $validated = $request->validate([ + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + $highlight = JudicialPrecedentHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->update($validated); + + return $this->success([], 'بروزرسانی', 'هایلایت با موفقیت بروزرسانی شد'); + } + + public function destroy($id) + { + $highlight = JudicialPrecedentHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->delete(); + + return $this->success([], 'حذف', 'هایلایت با موفقیت حذف شد'); + } +} diff --git a/app/Http/Controllers/api/LegalOpinionApiController.php b/app/Http/Controllers/api/LegalOpinionApiController.php index fe4e933..1cf3fec 100644 --- a/app/Http/Controllers/api/LegalOpinionApiController.php +++ b/app/Http/Controllers/api/LegalOpinionApiController.php @@ -172,21 +172,29 @@ class LegalOpinionApiController extends Controller } })->orderBy('opinion_date', 'asc')->orderBy('id', 'asc')->first(); - // Apply format and add Notes - $formatWithNote = function($item) { + // Apply format and add Notes & Highlights + $formatWithNoteAndHighlight = function($item) { if (!$item) return null; $formatted = $this->formatItem($item); + $formatted['note'] = \App\Models\LegalOpinionNote::select('id', 'note', 'color_code', 'created_at') - ->where('user_id', auth()->user()->id) + ->where('user_id', auth()->id()) ->where('legal_opinion_id', $item->id) ->get(); + + // NEW: Fetch Highlights + $formatted['highlight'] = \App\Models\LegalOpinionHighlight::select('id', 'start_index', 'end_index', 'selected_text', 'color_code') + ->where('user_id', auth()->id()) + ->where('legal_opinion_id', $item->id) + ->get(); + return $formatted; }; $results = array_values(array_filter([ - $previousItem ? $formatWithNote($previousItem) : null, - $formatWithNote($current), - $nextItem ? $formatWithNote($nextItem) : null + $previousItem ? $formatWithNoteAndHighlight($previousItem) : null, + $formatWithNoteAndHighlight($current), + $nextItem ? $formatWithNoteAndHighlight($nextItem) : null ])); return $this->success($results, 'Success', 'Pager Window Details'); diff --git a/app/Http/Controllers/api/LegalOpinionHighlightController.php b/app/Http/Controllers/api/LegalOpinionHighlightController.php new file mode 100644 index 0000000..3b8a2b3 --- /dev/null +++ b/app/Http/Controllers/api/LegalOpinionHighlightController.php @@ -0,0 +1,58 @@ +validate([ + 'opinion_id' => 'required', + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + LegalOpinionHighlight::create([ + 'user_id' => auth()->id(), + 'legal_opinion_id' => $validated['opinion_id'], + 'start_index' => $validated['start_index'], + 'end_index' => $validated['end_index'], + 'selected_text' => $validated['selected_text'], + 'color_code' => $validated['color_code'], + ]); + + return $this->success([], 'موفق', 'هایلایت با موفقیت اضافه شد'); + } + + public function update($id, Request $request) + { + $validated = $request->validate([ + 'start_index' => 'required|integer', + 'end_index' => 'required|integer', + 'selected_text' => 'nullable|string', + 'color_code' => 'nullable|string', + ]); + + $highlight = LegalOpinionHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->update($validated); + + return $this->success([], 'بروزرسانی', 'هایلایت با موفقیت بروزرسانی شد'); + } + + public function destroy($id) + { + $highlight = LegalOpinionHighlight::where('user_id', auth()->id())->findOrFail($id); + $highlight->delete(); + + return $this->success([], 'حذف', 'هایلایت با موفقیت حذف شد'); + } +} diff --git a/app/Models/ArtHighlight.php b/app/Models/ArtHighlight.php new file mode 100644 index 0000000..be8659a --- /dev/null +++ b/app/Models/ArtHighlight.php @@ -0,0 +1,8 @@ +middleware('auth:sanctum')->group(function () { Route::delete('/folders/{id}/bylaw/{bylaw_id}', [\App\Http\Controllers\api\FolderController::class, 'delete_bylaw']); Route::delete('/folders/{id}/judicial/{judicial_id}', [\App\Http\Controllers\api\FolderController::class, 'delete_judicial']); Route::delete('/folders/{id}/opinion/{opinion_id}', [\App\Http\Controllers\api\FolderController::class, 'delete_opinion']); + + // --- HIGHLIGHTS --- + Route::prefix('highlights')->middleware('auth:sanctum')->group(function () { + // Arts + Route::post('/art', [\App\Http\Controllers\api\ArtHighlightController::class, 'create']); + Route::put('/art/{id}', [\App\Http\Controllers\api\ArtHighlightController::class, 'update']); + Route::delete('/art/{id}', [\App\Http\Controllers\api\ArtHighlightController::class, 'destroy']); + + // Bylaws + Route::post('/bylaw', [\App\Http\Controllers\api\BylawHighlightController::class, 'create']); + Route::put('/bylaw/{id}', [\App\Http\Controllers\api\BylawHighlightController::class, 'update']); + Route::delete('/bylaw/{id}', [\App\Http\Controllers\api\BylawHighlightController::class, 'destroy']); + + // Judicial Precedents + Route::post('/judicial', [\App\Http\Controllers\api\JudicialPrecedentHighlightController::class, 'create']); + Route::put('/judicial/{id}', [\App\Http\Controllers\api\JudicialPrecedentHighlightController::class, 'update']); + Route::delete('/judicial/{id}', [\App\Http\Controllers\api\JudicialPrecedentHighlightController::class, 'destroy']); + + // Legal Opinions + Route::post('/opinion', [\App\Http\Controllers\api\LegalOpinionHighlightController::class, 'create']); + Route::put('/opinion/{id}', [\App\Http\Controllers\api\LegalOpinionHighlightController::class, 'update']); + Route::delete('/opinion/{id}', [\App\Http\Controllers\api\LegalOpinionHighlightController::class, 'destroy']); + }); + + });