Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
CRAP | |
100.00% |
1 / 1 |
| CompanyResearchController | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
3 | |
100.00% |
1 / 1 |
| status | |
100.00% |
21 / 21 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Http\Controllers\v2\RolePlay; |
| 4 | |
| 5 | use App\Http\Controllers\Controller; |
| 6 | use App\Http\Models\CompanyResearch; |
| 7 | use Illuminate\Http\JsonResponse; |
| 8 | use Illuminate\Http\Request; |
| 9 | |
| 10 | /** |
| 11 | * CompanyResearchController |
| 12 | * |
| 13 | * Provides a polling endpoint for the frontend to check the status of |
| 14 | * a company research record. The main "get or create" logic is handled |
| 15 | * internally by {@see \App\Http\Services\RolePlay\CompanyResearchService} |
| 16 | * through the auto-populate flow. |
| 17 | */ |
| 18 | class CompanyResearchController extends Controller |
| 19 | { |
| 20 | /** |
| 21 | * Check the status of a company research record by URL. |
| 22 | * |
| 23 | * Returns the current processing status and domain. Does NOT return |
| 24 | * the research content itself (that is consumed internally by the |
| 25 | * auto-populate service). |
| 26 | * |
| 27 | * |
| 28 | * @queryParam url string required The website URL to check. Example: https://vengreso.com |
| 29 | * |
| 30 | * @response 200 {"status": "success", "data": {"status": "completed", "domain": "vengreso.com", "updated_at": "2026-04-14T12:00:00+00:00"}} |
| 31 | * @response 200 {"status": "success", "data": {"status": "not_found", "domain": "unknown.com"}} |
| 32 | * @response 422 {"error": "url query parameter required"} |
| 33 | */ |
| 34 | public function status(Request $request): JsonResponse |
| 35 | { |
| 36 | $url = $request->query('url'); |
| 37 | |
| 38 | if (! $url) { |
| 39 | return response()->json(['error' => 'url query parameter required'], 422); |
| 40 | } |
| 41 | |
| 42 | $domain = CompanyResearch::extractDomain($url); |
| 43 | $research = CompanyResearch::where('domain', $domain)->first(); |
| 44 | |
| 45 | if (! $research) { |
| 46 | return response()->json([ |
| 47 | 'status' => 'success', |
| 48 | 'data' => [ |
| 49 | 'status' => 'not_found', |
| 50 | 'domain' => $domain, |
| 51 | ], |
| 52 | ]); |
| 53 | } |
| 54 | |
| 55 | return response()->json([ |
| 56 | 'status' => 'success', |
| 57 | 'data' => [ |
| 58 | 'status' => $research->status, |
| 59 | 'domain' => $research->domain, |
| 60 | 'updated_at' => $research->updated_at?->toIso8601String(), |
| 61 | ], |
| 62 | ]); |
| 63 | } |
| 64 | } |