114 lines
2.9 KiB
PHP
114 lines
2.9 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Api;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\Api\UserInformationHistoryIndexRequest;
|
|
use App\Http\Requests\Api\UserInformationHistoryStoreRequest;
|
|
use App\Http\Requests\Api\UserInformationHistoryUpdateRequest;
|
|
use App\Services\UserInformationHistoryService;
|
|
use App\Exceptions\ApiException;
|
|
use Illuminate\Http\JsonResponse;
|
|
|
|
class UserInformationHistoryController extends Controller
|
|
{
|
|
/**
|
|
* サービスインスタンス
|
|
*/
|
|
protected UserInformationHistoryService $service;
|
|
|
|
/**
|
|
* コンストラクタ
|
|
*/
|
|
public function __construct(UserInformationHistoryService $service)
|
|
{
|
|
$this->service = $service;
|
|
}
|
|
|
|
/**
|
|
* API 7 - 一覧取得
|
|
* GET /api/user-information-history
|
|
*
|
|
* @param UserInformationHistoryIndexRequest $request
|
|
* @return JsonResponse
|
|
*/
|
|
public function index(UserInformationHistoryIndexRequest $request): JsonResponse
|
|
{
|
|
try {
|
|
$result = $this->service->getList($request->validated());
|
|
|
|
return response()->json([
|
|
'result' => 'OK',
|
|
'data' => $result['data'],
|
|
'pagination' => $result['pagination'],
|
|
], 200);
|
|
} catch (ApiException $e) {
|
|
return $e->render();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* API 7 - 単一取得
|
|
* GET /api/user-information-history/{id}
|
|
*
|
|
* @param int $id
|
|
* @return JsonResponse
|
|
*/
|
|
public function show(int $id): JsonResponse
|
|
{
|
|
try {
|
|
$data = $this->service->getById($id);
|
|
|
|
return response()->json([
|
|
'result' => 'OK',
|
|
'data' => $data,
|
|
], 200);
|
|
} catch (ApiException $e) {
|
|
return $e->render();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* API 8 - 新規追加
|
|
* POST /api/user-information-history
|
|
*
|
|
* @param UserInformationHistoryStoreRequest $request
|
|
* @return JsonResponse
|
|
*/
|
|
public function store(UserInformationHistoryStoreRequest $request): JsonResponse
|
|
{
|
|
try {
|
|
$data = $this->service->create($request->validated());
|
|
|
|
return response()->json(array_merge(
|
|
['result' => 'OK'],
|
|
$data
|
|
), 201);
|
|
} catch (ApiException $e) {
|
|
return $e->render();
|
|
}
|
|
}
|
|
|
|
/**
|
|
* API 9 - 更新
|
|
* PUT /api/user-information-history/{id}
|
|
*
|
|
* @param UserInformationHistoryUpdateRequest $request
|
|
* @param int $id
|
|
* @return JsonResponse
|
|
*/
|
|
public function update(UserInformationHistoryUpdateRequest $request, int $id): JsonResponse
|
|
{
|
|
try {
|
|
$data = $this->service->update($id, $request->validated());
|
|
|
|
return response()->json(array_merge(
|
|
['result' => 'OK'],
|
|
$data
|
|
), 200);
|
|
} catch (ApiException $e) {
|
|
return $e->render();
|
|
}
|
|
}
|
|
}
|