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

@@ -147,49 +147,46 @@ class LegalOpinionApiController extends Controller
$current = LegalOpinion::find($id);
if (!$current) {
return $this->failed([], [
'title' => 'خطا',
'message' => 'نظریه قانونی مورد نظر یافت نشد.'
], 404);
return $this->failed([], ['title' => 'خطا', 'message' => 'نظریه قانونی مورد نظر یافت نشد.'], 404);
}
$previousItem = LegalOpinion::where(function ($query) use ($current) {
if ($current->opinion_date) {
$query->where('opinion_date', '<', $current->opinion_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('opinion_date', '=', $current->opinion_date)
->where('id', '<', $current->id);
});
$query->where('opinion_date', '<', $current->opinion_date)->orWhere(function ($subQuery) use ($current) {
$subQuery->where('opinion_date', '=', $current->opinion_date)->where('id', '<', $current->id);
});
} else {
$query->whereNull('opinion_date')->where('id', '<', $current->id);
}
})
->orderBy('opinion_date', 'desc')
->orderBy('id', 'desc')
->first();
})->orderBy('opinion_date', 'desc')->orderBy('id', 'desc')->first();
$nextItem = LegalOpinion::where(function ($query) use ($current) {
if ($current->opinion_date) {
$query->where('opinion_date', '>', $current->opinion_date)
->orWhere(function ($subQuery) use ($current) {
$subQuery->where('opinion_date', '=', $current->opinion_date)
->where('id', '>', $current->id);
});
$query->where('opinion_date', '>', $current->opinion_date)->orWhere(function ($subQuery) use ($current) {
$subQuery->where('opinion_date', '=', $current->opinion_date)->where('id', '>', $current->id);
});
} else {
$query->whereNotNull('opinion_date')
->orWhere(function ($subQuery) use ($current) {
$subQuery->whereNull('opinion_date')->where('id', '>', $current->id);
});
$query->whereNotNull('opinion_date')->orWhere(function ($subQuery) use ($current) {
$subQuery->whereNull('opinion_date')->where('id', '>', $current->id);
});
}
})
->orderBy('opinion_date', 'asc')
->orderBy('id', 'asc')
->first();
})->orderBy('opinion_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\LegalOpinionNote::select('id', 'note', 'color_code', 'created_at')
->where('user_id', auth()->user()->id)
->where('legal_opinion_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');