- Added new apis
This commit is contained in:
@@ -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));
|
||||
}
|
||||
|
||||
58
app/Http/Controllers/api/ArtHighlightController.php
Normal file
58
app/Http/Controllers/api/ArtHighlightController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\ArtHighlight;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ArtHighlightController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validated = $request->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([], 'حذف', 'هایلایت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
@@ -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();
|
||||
|
||||
|
||||
58
app/Http/Controllers/api/BylawHighlightController.php
Normal file
58
app/Http/Controllers/api/BylawHighlightController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\BylawHighlight;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class BylawHighlightController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validated = $request->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([], 'حذف', 'هایلایت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\JudicialPrecedentHighlight;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class JudicialPrecedentHighlightController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validated = $request->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([], 'حذف', 'هایلایت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
|
||||
58
app/Http/Controllers/api/LegalOpinionHighlightController.php
Normal file
58
app/Http/Controllers/api/LegalOpinionHighlightController.php
Normal file
@@ -0,0 +1,58 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\LegalOpinionHighlight;
|
||||
use App\Traits\BaseApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class LegalOpinionHighlightController extends Controller
|
||||
{
|
||||
use BaseApiResponse;
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
$validated = $request->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([], 'حذف', 'هایلایت با موفقیت حذف شد');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user