updated apis
This commit is contained in:
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user