Spaces:
Running
Running
File size: 7,404 Bytes
907b200 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 | <?php
namespace App\Http\Controllers\Api;
use App\Http\Requests\Screen\ScreenRequest;
use App\Http\Requests\Screen\TargetLookupRequest;
use App\Models\ScreeningResult;
use App\Models\TargetLookup;
use App\Jobs\RunTargetLookupJob;
use App\Jobs\RunScreeningJob;
use App\Services\ScreeningService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
class ScreeningController extends BaseController
{
public function __construct(protected ScreeningService $screeningService) {}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// POST /api/drug-repurposing/targets β upstream POST /api/v1/disease-targets
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
public function targets(TargetLookupRequest $request): JsonResponse
{
$input = $request->validated();
$lookup = TargetLookup::create([
'user_id' => Auth::id(),
'input' => $input,
'status' => 'pending',
]);
RunTargetLookupJob::dispatch($lookup);
return $this->successResponse('Target lookup queued successfully', [
'job_id' => $lookup->id,
'status' => $lookup->status,
]);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// POST /api/drug-repurposing/screen β upstream POST /api/v1/screen
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
public function screen(ScreenRequest $request): JsonResponse
{
$input = $request->validated();
$result = ScreeningResult::create([
'user_id' => Auth::id(),
'input' => $input,
'status' => 'pending',
]);
RunScreeningJob::dispatch($result);
return $this->successResponse('Screening queued successfully', [
'job_id' => $result->id,
'status' => $result->status,
]);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GET /api/v1/screen/history/targets
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
public function historyTargets(Request $request): JsonResponse
{
$perPage = min((int) $request->query('per_page', 15), 100);
$paginator = TargetLookup::where('user_id', Auth::id())
->orderBy('created_at', 'desc')
->paginate($perPage, ['id', 'input', 'output', 'status', 'created_at']);
return $this->successResponse('Target lookup history retrieved successfully', [
'data' => $paginator->items(),
'pagination' => [
'current_page' => $paginator->currentPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
'last_page' => $paginator->lastPage(),
'has_more' => $paginator->hasMorePages(),
],
]);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GET /api/v1/screen/history/screening
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
public function historyScreening(Request $request): JsonResponse
{
$perPage = min((int) $request->query('per_page', 15), 100);
$paginator = ScreeningResult::where('user_id', Auth::id())
->orderBy('created_at', 'desc')
->paginate($perPage, ['id', 'input', 'output', 'status', 'created_at']);
return $this->successResponse('Screening history retrieved successfully', [
'data' => $paginator->items(),
'pagination' => [
'current_page' => $paginator->currentPage(),
'per_page' => $paginator->perPage(),
'total' => $paginator->total(),
'last_page' => $paginator->lastPage(),
'has_more' => $paginator->hasMorePages(),
],
]);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GET /api/v1/screen/targets/{id}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
public function statusTargets(int $id): JsonResponse
{
$lookup = TargetLookup::where('id', $id)
->where('user_id', Auth::id())
->first();
if (!$lookup) {
return $this->errorResponse('Target lookup not found or unauthorized', 404);
}
return $this->successResponse('Target lookup history retrieved successfully', [
'id' => $lookup->id,
'input' => $lookup->input,
'output' => $lookup->output,
'status' => $lookup->status,
]);
}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
// GET /api/v1/screen/{id}
// ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
public function statusScreening(int $id): JsonResponse
{
$result = ScreeningResult::where('id', $id)
->where('user_id', Auth::id())
->first();
if (!$result) {
return $this->errorResponse('Screening result not found or unauthorized', 404);
}
return $this->successResponse('Screening history retrieved successfully', [
'id' => $result->id,
'input' => $result->input,
'output' => $result->output,
'status' => $result->status,
]);
}
}
|