Skip to content

Commit

Permalink
APIにPOSTする方式から、APIサーバー経由でリダイレクトする方法に変更
Browse files Browse the repository at this point in the history
`/api/press-release/view`を廃止。
プレスリリース移管前にAPIにPOSTするのではなく、GETでAPIサーバー経由でリダイレクトする方法に変更。
  • Loading branch information
kyoya0819 committed Aug 29, 2024
1 parent 31faf30 commit 97351bd
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace App\Http\Controllers\Api\PressRelease;
namespace App\Http\Controllers\Web\PressRelease;

use App\Exceptions\HttpJsonResponseException;
use App\Http\Controllers\Controller;
Expand All @@ -9,41 +9,38 @@
use App\UseCases\PressRelease\FindByIdsAction;
use Exception;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class ViewController extends Controller
class RedirectController extends Controller
{
/**
* @param string $company_id
* @param string $release_id
* @param Request $request
* @return JsonResponse
* @return RedirectResponse
* @throws Exception
*/
public function __invoke(Request $request): JsonResponse
public function __invoke(string $company_id, string $release_id, Request $request): RedirectResponse
{
$user_id = Auth::id();
if ($user_id === null || is_string($user_id)) // auth:sanctumで弾いているため最低限の例外
throw new Exception("想定外エラー");

$company_id = $request->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");
}
}
1 change: 0 additions & 1 deletion backend/routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

Route::middleware("auth:sanctum")->group(function () {

Route::post("/press-release/view", PressRelease\ViewController::class);
Route::get("/press-release/recommend", PressRelease\RecommendController::class);

Route::get("/company/list", Company\ListController::class);
Expand Down
4 changes: 4 additions & 0 deletions backend/routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});

0 comments on commit 97351bd

Please sign in to comment.