updated apis

This commit is contained in:
m.razaghi
2026-07-14 00:10:53 +03:30
parent 39e85df27a
commit a173f17cae
11 changed files with 304 additions and 102 deletions

View File

@@ -146,38 +146,38 @@ class JudicialPrecedentApiController extends Controller
$current = JudicialPrecedent::find($id);
if (!$current) {
return $this->failed([], [
'title' => 'خطا',
'message' => 'رأی وحدت رویه مورد نظر یافت نشد.'
], 404);
return $this->failed([], ['title' => 'خطا', 'message' => 'رأی وحدت رویه مورد نظر یافت نشد.'], 404);
}
$previousItem = JudicialPrecedent::where(function ($query) use ($current) {
$query->where('ruling_date', '<', $current->ruling_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('ruling_date', '=', $current->ruling_date)
->where('id', '<', $current->id);
$subQuery->where('ruling_date', '=', $current->ruling_date)->where('id', '<', $current->id);
});
})
->orderBy('ruling_date', 'desc')
->orderBy('id', 'desc')
->first();
})->orderBy('ruling_date', 'desc')->orderBy('id', 'desc')->first();
$nextItem = JudicialPrecedent::where(function ($query) use ($current) {
$query->where('ruling_date', '>', $current->ruling_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('ruling_date', '=', $current->ruling_date)
->where('id', '>', $current->id);
$subQuery->where('ruling_date', '=', $current->ruling_date)->where('id', '>', $current->id);
});
})
->orderBy('ruling_date', 'asc')
->orderBy('id', 'asc')
->first();
})->orderBy('ruling_date', 'asc')->orderBy('id', 'asc')->first();
// Apply format and add Notes
$formatWithNote = 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('judicial_precedent_id', $item->id)
->get();
return $formatted;
};
$results = array_values(array_filter([
$previousItem ? $this->formatItem($previousItem) : null,
$this->formatItem($current),
$nextItem ? $this->formatItem($nextItem) : null
$previousItem ? $formatWithNote($previousItem) : null,
$formatWithNote($current),
$nextItem ? $formatWithNote($nextItem) : null
]));
return $this->success($results, 'Success', 'Pager Window Details');