diff --git a/backend/app/Http/Controllers/Api/Company/ListController.php b/backend/app/Http/Controllers/Api/Company/ListController.php index b51b22f..edcab12 100644 --- a/backend/app/Http/Controllers/Api/Company/ListController.php +++ b/backend/app/Http/Controllers/Api/Company/ListController.php @@ -3,21 +3,26 @@ namespace App\Http\Controllers\Api\Company; use App\Http\Controllers\Controller; -use App\Http\Requests\Api\Company\List\InvokeRequest; use App\Models\Company; use App\UseCases\Company\ListFilterByIndustryIds; use Illuminate\Http\JsonResponse; +use Illuminate\Http\Request; class ListController extends Controller { /** - * @param InvokeRequest $request + * @param Request $request * @return JsonResponse */ - public function __invoke(InvokeRequest $request): JsonResponse + public function __invoke(Request $request): JsonResponse { - /* @var int[] $industry_ids */ - $industry_ids = $request->validated()['industry_ids']; + $industry_ids_raw = $request->query("industry_ids"); + if ($industry_ids_raw === null) + return response()->json(); + + $industry_ids = is_array($industry_ids_raw) + ? array_map(fn ($industry_id) => (int) $industry_id, $industry_ids_raw) + : [(int) $industry_ids_raw]; $companies = ListFilterByIndustryIds::run($industry_ids); diff --git a/backend/app/Http/Controllers/Api/PressRelease/RecommendController.php b/backend/app/Http/Controllers/Api/PressRelease/RecommendController.php index 279e526..672e2c8 100644 --- a/backend/app/Http/Controllers/Api/PressRelease/RecommendController.php +++ b/backend/app/Http/Controllers/Api/PressRelease/RecommendController.php @@ -41,9 +41,15 @@ public function __invoke(Request $request): JsonResponse /* @var PressRelease $press_release */ return [ - "id" => $press_release->id, "title" => $press_release->title, - "summary" => $press_release->summary + "summary" => $press_release->summary, + "url" => route( + "press-release.redirect", + [ + "company_id" => $press_release->company_id, + "release_id" => $press_release->release_id + ] + ) ]; }) ->toArray() diff --git a/backend/app/Http/Controllers/Api/PressRelease/ViewController.php b/backend/app/Http/Controllers/Web/PressRelease/RedirectController.php similarity index 50% rename from backend/app/Http/Controllers/Api/PressRelease/ViewController.php rename to backend/app/Http/Controllers/Web/PressRelease/RedirectController.php index 9a32a7c..3bc87cc 100644 --- a/backend/app/Http/Controllers/Api/PressRelease/ViewController.php +++ b/backend/app/Http/Controllers/Web/PressRelease/RedirectController.php @@ -1,6 +1,6 @@ get("company_id"); - $release_id = $request->get("release_id"); - - $press_release = FindByIdsAction::run(company_id: $company_id, release_id: $release_id); + $press_release = FindByIdsAction::run(company_id: (int) $company_id, release_id: (int) $release_id); if (!$press_release) - throw new HttpJsonResponseException( - 400, - "notfound", - "PressRelease Not Found", - compact("company_id", "release_id") - ); + abort(404); /* @var Keyword $keyword */ - foreach ($press_release->keywords() as $keyword) { + foreach ($press_release->keywords()->get() as $keyword) { ViewHistoryUpdateOrCreateAction::run($user_id, $keyword->id); } - return response()->json(["result" => "ok"]); + $company_id_str = str_pad($company_id, 9, 0, STR_PAD_LEFT); + $release_id_str = str_pad($release_id, 9, 0, STR_PAD_LEFT); + return response()->redirectTo("https://prtimes.jp/main/html/rd/p/$release_id_str.$company_id_str.html"); } } diff --git a/backend/app/Http/Requests/Api/Company/List/InvokeRequest.php b/backend/app/Http/Requests/Api/Company/List/InvokeRequest.php deleted file mode 100644 index 9dcdb39..0000000 --- a/backend/app/Http/Requests/Api/Company/List/InvokeRequest.php +++ /dev/null @@ -1,22 +0,0 @@ - - */ - public function rules(): array - { - return [ - "industry_ids" => ["required", "array"], - "industry_ids.*" => ["integer", "min:1", "max:16"], - ]; - } -} diff --git a/backend/routes/api.php b/backend/routes/api.php index 9608cf6..6070154 100644 --- a/backend/routes/api.php +++ b/backend/routes/api.php @@ -12,8 +12,7 @@ Route::middleware("auth:sanctum")->group(function () { - Route::post("/press-release/view", PressRelease\ViewController::class); Route::get("/press-release/recommend", PressRelease\RecommendController::class); - Route::post("/company/list", Company\ListController::class); + Route::get("/company/list", Company\ListController::class); }); \ No newline at end of file diff --git a/backend/routes/web.php b/backend/routes/web.php index 6ff812e..fdf9a6f 100644 --- a/backend/routes/web.php +++ b/backend/routes/web.php @@ -4,3 +4,7 @@ use Illuminate\Support\Facades\Route; +Route::middleware("auth")->group(function () { + + Route::get("/press-release/redirect/{company_id}/{release_id}", PressRelease\RedirectController::class)->name("press-release.redirect"); +}); \ No newline at end of file