diff --git a/php/laravel/api/app/Http/Controllers/MessageApiController.php b/php/laravel/api/app/Http/Controllers/MessageApiController.php index 2bf4d09..507d970 100644 --- a/php/laravel/api/app/Http/Controllers/MessageApiController.php +++ b/php/laravel/api/app/Http/Controllers/MessageApiController.php @@ -8,22 +8,50 @@ class MessageApiController extends Controller { - public function index() + public function index(Request $request) { + // SPAの場合でも考え方は同じ + // 処理は、 MessageController を参照 + $tenantid = $request->userinfo['tenants'][0]['id']; + $messages = DB::table('messages') ->select('messages.*') - ->where('tenant_id', "1") + ->where('tenant_id', $tenantid) ->get(); return response()->json($messages); } public function post(Request $request) { - $result = Message::create([ - 'tenant_id' => "1", - 'user_id' => $request->user_id, - 'message' => $request->message, - ]); + $tenant_id = $request->userinfo['tenants'][0]['id']; + $plan_id = $request->userinfo['tenants'][0]['plan_id']; + + // SaaSus SDKを使ってSaaSus APIを叩いて、各種情報を取得し、判断に使う + $client = new \AntiPatternInc\Saasus\Api\Client(); + $pricingApi = $client->getPricingClient(); + $res = $pricingApi->getPricingPlan($plan_id, $pricingApi::FETCH_RESPONSE); + $plan = json_decode($res->getBody(), true); + + $meteringUnitName = "comment_count"; + $res = $pricingApi->getMeteringUnitDateCountByTenantIdAndUnitNameToday($tenant_id, $meteringUnitName, $pricingApi::FETCH_RESPONSE); + $count = json_decode($res->getBody(), true); + + $upper = \AntiPatternInc\Saasus\Api\Lib::findUpperCountByMeteringUnitName($plan, $meteringUnitName); + + $result = ''; + // 現在契約中の料金プランの上限コメント数を超えていたら、投稿できなくする + if ($count['count'] < $upper || $upper === 0) { + $result = Message::create([ + 'tenant_id' => $tenant_id, + 'user_id' => $request->userinfo['tenants'][0]['user_attribute']['username'], + 'message' => $request->message, + ]); + // メータリングAPIで、コメント数に1を足す + $param = new \AntiPatternInc\Saasus\Sdk\Pricing\Model\UpdateMeteringUnitTimestampCountNowParam(); + $param->setMethod('add'); + $param->setCount(1); + $res = $pricingApi->updateMeteringUnitTimestampCountNow($request->userinfo['tenants'][0]['id'], $meteringUnitName, $param, $pricingApi::FETCH_RESPONSE); + } return response()->json($result); } diff --git a/php/laravel/api/app/Http/Controllers/MessageController.php b/php/laravel/api/app/Http/Controllers/MessageController.php index e6ac1af..8f569fd 100644 --- a/php/laravel/api/app/Http/Controllers/MessageController.php +++ b/php/laravel/api/app/Http/Controllers/MessageController.php @@ -15,11 +15,11 @@ class MessageController extends Controller ]; public const TENANT_NAME = 'テナント1'; - public function index() + public function index(Request $request) { - // 現在はtenant_idは1で固定する - $messages = Message::where('tenant_id', "1")->get(); - return view('messageBoard.index', ['messages' => $messages, 'plans' => $this::PLANS, 'tenant_name' => $this::TENANT_NAME]); + // $request->userinfo に各種ユーザ情報、テナント情報が入ってくるので、それを使う + $messages = Message::where('tenant_id', $request->userinfo['tenants'][0]['id'])->get(); + return view('messageBoard.index', ['messages' => $messages, 'plans' => $this::PLANS, 'tenant_name' => $request->userinfo['tenants'][0]['name']]); } public function post(Request $request) @@ -27,12 +27,38 @@ public function post(Request $request) $validated = $request->validate([ 'message' => 'required|max:255' ]); - // 現在はtenant_idは1で固定する - $message = Message::create([ - 'tenant_id' => "1", - 'user_id' => Auth::id(), - 'message' => $request->message, - ]); + + $tenant_id = $request->userinfo['tenants'][0]['id']; + $plan_id = $request->userinfo['tenants'][0]['plan_id']; + + // SaaSus SDKを使ってSaaSus APIを叩いて、各種情報を取得し、判断に使う + $client = new \AntiPatternInc\Saasus\Api\Client(); + $pricingApi = $client->getPricingClient(); + $res = $pricingApi->getPricingPlan($plan_id, $pricingApi::FETCH_RESPONSE); + $plan = json_decode($res->getBody(), true); + + // メータリングのメータ、comment_count(コメント数)を使う + $meteringUnitName = "comment_count"; + $res = $pricingApi->getMeteringUnitDateCountByTenantIdAndUnitNameToday($tenant_id, $meteringUnitName, $pricingApi::FETCH_RESPONSE); + // 今回は、1日ごとの上限コメント数として扱う + $count = json_decode($res->getBody(), true); + + $upper = \AntiPatternInc\Saasus\Api\Lib::findUpperCountByMeteringUnitName($plan, $meteringUnitName); + + // 現在契約中の料金プランの上限コメント数を超えていたら、投稿できなくする + if ($count['count'] < $upper || $upper === 0) { + $message = Message::create([ + 'tenant_id' => $tenant_id, + 'user_id' => $request->userinfo['tenants'][0]['user_attribute']['username'], + 'message' => $request->message, + ]); + // メータリングAPIで、コメント数に1を足す + $param = new \AntiPatternInc\Saasus\Sdk\Pricing\Model\UpdateMeteringUnitTimestampCountNowParam(); + $param->setMethod('add'); + $param->setCount(1); + $res = $pricingApi->updateMeteringUnitTimestampCountNow($request->userinfo['tenants'][0]['id'], $meteringUnitName, $param, $pricingApi::FETCH_RESPONSE); + } + $request->session()->regenerateToken(); return redirect()->route('board'); } diff --git a/php/laravel/api/composer.json b/php/laravel/api/composer.json index d464d6b..712f4c4 100644 --- a/php/laravel/api/composer.json +++ b/php/laravel/api/composer.json @@ -9,7 +9,8 @@ "guzzlehttp/guzzle": "^7.2", "laravel/framework": "^9.2", "laravel/sanctum": "^2.14.1", - "laravel/tinker": "^2.7" + "laravel/tinker": "^2.7", + "saasus-platform/saasus-sdk-php": "dev-feature/api-request-error-handling" }, "require-dev": { "fakerphp/faker": "^1.9.1", @@ -58,5 +59,11 @@ "sort-packages": true }, "minimum-stability": "dev", - "prefer-stable": true + "prefer-stable": true, + "repositories": { + "saasus-platform/saasus-sdk-php": { + "type": "vcs", + "url": "https://github.com/saasus-platform/saasus-sdk-php" + } + } } diff --git a/php/laravel/api/composer.lock b/php/laravel/api/composer.lock index 0a758bc..9192a76 100644 --- a/php/laravel/api/composer.lock +++ b/php/laravel/api/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0251884cf3eac4cf2b7e26acb218f09d", + "content-hash": "bc38d09e8e62e83368836d27debae110", "packages": [ { "name": "brick/math", @@ -66,6 +66,72 @@ ], "time": "2021-08-15T20:50:18+00:00" }, + { + "name": "clue/stream-filter", + "version": "v1.6.0", + "source": { + "type": "git", + "url": "https://github.com/clue/stream-filter.git", + "reference": "d6169430c7731d8509da7aecd0af756a5747b78e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/clue/stream-filter/zipball/d6169430c7731d8509da7aecd0af756a5747b78e", + "reference": "d6169430c7731d8509da7aecd0af756a5747b78e", + "shasum": "" + }, + "require": { + "php": ">=5.3" + }, + "require-dev": { + "phpunit/phpunit": "^9.3 || ^5.7 || ^4.8.36" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions_include.php" + ], + "psr-4": { + "Clue\\StreamFilter\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Christian Lück", + "email": "christian@clue.engineering" + } + ], + "description": "A simple and modern approach to stream filtering in PHP", + "homepage": "https://github.com/clue/php-stream-filter", + "keywords": [ + "bucket brigade", + "callback", + "filter", + "php_user_filter", + "stream", + "stream_filter_append", + "stream_filter_register" + ], + "support": { + "issues": "https://github.com/clue/stream-filter/issues", + "source": "https://github.com/clue/stream-filter/tree/v1.6.0" + }, + "funding": [ + { + "url": "https://clue.engineering/support", + "type": "custom" + }, + { + "url": "https://github.com/clue", + "type": "github" + } + ], + "time": "2022-02-21T13:15:14+00:00" + }, { "name": "dflydev/dot-access-data", "version": "v3.0.1", @@ -893,6 +959,131 @@ ], "time": "2021-10-06T17:43:30+00:00" }, + { + "name": "jane-php/json-schema-runtime", + "version": "v7.4.0", + "source": { + "type": "git", + "url": "https://github.com/janephp/json-schema-runtime.git", + "reference": "46aed7d2ac26b86e713c45091d18b4a591121143" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/janephp/json-schema-runtime/zipball/46aed7d2ac26b86e713c45091d18b4a591121143", + "reference": "46aed7d2ac26b86e713c45091d18b4a591121143", + "shasum": "" + }, + "require": { + "ext-json": "*", + "league/uri": "^6.0", + "php": "^7.2 || ^8.0", + "php-jsonpointer/php-jsonpointer": "^3.0", + "symfony/serializer": "^4.4 || ^5.0 || ^6.0", + "symfony/yaml": "~4.4.9 || ^5.0 || ^6.0" + }, + "conflict": { + "symfony/framework-bundle": "5.1.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-next": "7-dev" + } + }, + "autoload": { + "psr-4": { + "Jane\\Component\\JsonSchemaRuntime\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joel Wurtz", + "email": "jwurtz@jolicode.com" + }, + { + "name": "Baptiste Leduc", + "email": "baptiste.leduc@gmail.com" + } + ], + "description": "Jane runtime Library", + "support": { + "source": "https://github.com/janephp/json-schema-runtime/tree/v7.4.0" + }, + "time": "2021-12-16T13:26:58+00:00" + }, + { + "name": "jane-php/open-api-runtime", + "version": "v7.4.0", + "source": { + "type": "git", + "url": "https://github.com/janephp/open-api-runtime.git", + "reference": "ce5ed462cba12e88e4072769ec7899556c70bb05" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/janephp/open-api-runtime/zipball/ce5ed462cba12e88e4072769ec7899556c70bb05", + "reference": "ce5ed462cba12e88e4072769ec7899556c70bb05", + "shasum": "" + }, + "require": { + "jane-php/json-schema-runtime": "^7.0", + "php": "^7.2 || ^8.0", + "php-http/client-common": "^2.0", + "php-http/discovery": "^1.6", + "php-http/message-factory": "^1.0.2", + "php-http/multipart-stream-builder": "^1.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "symfony/options-resolver": "^4.4 || ^5.0 || ^6.0" + }, + "require-dev": { + "phpunit/phpunit": "^8.0", + "symfony/serializer": "^4.4 || ^5.0 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-next": "7-dev" + } + }, + "autoload": { + "psr-4": { + "Jane\\Component\\OpenApiRuntime\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joel Wurtz", + "email": "jwurtz@jolicode.com" + }, + { + "name": "Baptiste Leduc", + "email": "baptiste.leduc@gmail.com" + } + ], + "description": "Jane OpenAPI Runtime Library, dependencies and utility class for a library generated by jane/openapi", + "support": { + "source": "https://github.com/janephp/open-api-runtime/tree/v7.4.0" + }, + "time": "2021-12-16T13:26:58+00:00" + }, { "name": "laravel/framework", "version": "v9.5.1", @@ -1595,6 +1786,176 @@ ], "time": "2021-11-21T11:48:40+00:00" }, + { + "name": "league/uri", + "version": "6.7.2", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri.git", + "reference": "d3b50812dd51f3fbf176344cc2981db03d10fe06" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri/zipball/d3b50812dd51f3fbf176344cc2981db03d10fe06", + "reference": "d3b50812dd51f3fbf176344cc2981db03d10fe06", + "shasum": "" + }, + "require": { + "ext-json": "*", + "league/uri-interfaces": "^2.3", + "php": "^7.4 || ^8.0", + "psr/http-message": "^1.0" + }, + "conflict": { + "league/uri-schemes": "^1.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^v3.3.2", + "nyholm/psr7": "^1.5", + "php-http/psr7-integration-tests": "^1.1", + "phpstan/phpstan": "^1.2.0", + "phpstan/phpstan-deprecation-rules": "^1.0", + "phpstan/phpstan-phpunit": "^1.0.0", + "phpstan/phpstan-strict-rules": "^1.1.0", + "phpunit/phpunit": "^9.5.10", + "psr/http-factory": "^1.0" + }, + "suggest": { + "ext-fileinfo": "Needed to create Data URI from a filepath", + "ext-intl": "Needed to improve host validation", + "league/uri-components": "Needed to easily manipulate URI objects", + "psr/http-factory": "Needed to use the URI factory" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "6.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "URI manipulation library", + "homepage": "https://uri.thephpleague.com", + "keywords": [ + "data-uri", + "file-uri", + "ftp", + "hostname", + "http", + "https", + "middleware", + "parse_str", + "parse_url", + "psr-7", + "query-string", + "querystring", + "rfc3986", + "rfc3987", + "rfc6570", + "uri", + "uri-template", + "url", + "ws" + ], + "support": { + "docs": "https://uri.thephpleague.com", + "forum": "https://thephpleague.slack.com", + "issues": "https://github.com/thephpleague/uri/issues", + "source": "https://github.com/thephpleague/uri/tree/6.7.2" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2022-09-13T19:50:42+00:00" + }, + { + "name": "league/uri-interfaces", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/thephpleague/uri-interfaces.git", + "reference": "00e7e2943f76d8cb50c7dfdc2f6dee356e15e383" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/thephpleague/uri-interfaces/zipball/00e7e2943f76d8cb50c7dfdc2f6dee356e15e383", + "reference": "00e7e2943f76d8cb50c7dfdc2f6dee356e15e383", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^2.19", + "phpstan/phpstan": "^0.12.90", + "phpstan/phpstan-phpunit": "^0.12.19", + "phpstan/phpstan-strict-rules": "^0.12.9", + "phpunit/phpunit": "^8.5.15 || ^9.5" + }, + "suggest": { + "ext-intl": "to use the IDNA feature", + "symfony/intl": "to use the IDNA feature via Symfony Polyfill" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "League\\Uri\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Ignace Nyamagana Butera", + "email": "nyamsprod@gmail.com", + "homepage": "https://nyamsprod.com" + } + ], + "description": "Common interface for URI representation", + "homepage": "http://github.com/thephpleague/uri-interfaces", + "keywords": [ + "rfc3986", + "rfc3987", + "uri", + "url" + ], + "support": { + "issues": "https://github.com/thephpleague/uri-interfaces/issues", + "source": "https://github.com/thephpleague/uri-interfaces/tree/2.3.0" + }, + "funding": [ + { + "url": "https://github.com/sponsors/nyamsprod", + "type": "github" + } + ], + "time": "2021-06-28T04:27:21+00:00" + }, { "name": "monolog/monolog", "version": "2.4.0", @@ -1935,63 +2296,632 @@ "issues": "https://github.com/nette/utils/issues", "source": "https://github.com/nette/utils/tree/v3.2.7" }, - "time": "2022-01-24T11:29:14+00:00" + "time": "2022-01-24T11:29:14+00:00" + }, + { + "name": "nikic/php-parser", + "version": "v4.13.2", + "source": { + "type": "git", + "url": "https://github.com/nikic/PHP-Parser.git", + "reference": "210577fe3cf7badcc5814d99455df46564f3c077" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077", + "reference": "210577fe3cf7badcc5814d99455df46564f3c077", + "shasum": "" + }, + "require": { + "ext-tokenizer": "*", + "php": ">=7.0" + }, + "require-dev": { + "ircmaxell/php-yacc": "^0.0.7", + "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + }, + "bin": [ + "bin/php-parse" + ], + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "4.9-dev" + } + }, + "autoload": { + "psr-4": { + "PhpParser\\": "lib/PhpParser" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Nikita Popov" + } + ], + "description": "A PHP parser written in PHP", + "keywords": [ + "parser", + "php" + ], + "support": { + "issues": "https://github.com/nikic/PHP-Parser/issues", + "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2" + }, + "time": "2021-11-30T19:35:32+00:00" + }, + { + "name": "php-http/client-common", + "version": "2.6.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/client-common.git", + "reference": "45db684cd4e186dcdc2b9c06b22970fe123796c0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/client-common/zipball/45db684cd4e186dcdc2b9c06b22970fe123796c0", + "reference": "45db684cd4e186dcdc2b9c06b22970fe123796c0", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "php-http/httplug": "^2.0", + "php-http/message": "^1.6", + "php-http/message-factory": "^1.0", + "psr/http-client": "^1.0", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0", + "symfony/options-resolver": "~4.0.15 || ~4.1.9 || ^4.2.1 || ^5.0 || ^6.0", + "symfony/polyfill-php80": "^1.17" + }, + "require-dev": { + "doctrine/instantiator": "^1.1", + "guzzlehttp/psr7": "^1.4", + "nyholm/psr7": "^1.2", + "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", + "phpspec/prophecy": "^1.10.2", + "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.3" + }, + "suggest": { + "ext-json": "To detect JSON responses with the ContentTypePlugin", + "ext-libxml": "To detect XML responses with the ContentTypePlugin", + "php-http/cache-plugin": "PSR-6 Cache plugin", + "php-http/logger-plugin": "PSR-3 Logger plugin", + "php-http/stopwatch-plugin": "Symfony Stopwatch plugin" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.3.x-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Client\\Common\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Common HTTP Client implementations and tools for HTTPlug", + "homepage": "http://httplug.io", + "keywords": [ + "client", + "common", + "http", + "httplug" + ], + "support": { + "issues": "https://github.com/php-http/client-common/issues", + "source": "https://github.com/php-http/client-common/tree/2.6.0" + }, + "time": "2022-09-29T09:59:43+00:00" + }, + { + "name": "php-http/discovery", + "version": "1.14.3", + "source": { + "type": "git", + "url": "https://github.com/php-http/discovery.git", + "reference": "31d8ee46d0215108df16a8527c7438e96a4d7735" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/discovery/zipball/31d8ee46d0215108df16a8527c7438e96a4d7735", + "reference": "31d8ee46d0215108df16a8527c7438e96a4d7735", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "conflict": { + "nyholm/psr7": "<1.0" + }, + "require-dev": { + "graham-campbell/phpspec-skip-example-extension": "^5.0", + "php-http/httplug": "^1.0 || ^2.0", + "php-http/message-factory": "^1.0", + "phpspec/phpspec": "^5.1 || ^6.1" + }, + "suggest": { + "php-http/message": "Allow to use Guzzle, Diactoros or Slim Framework factories" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.9-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Discovery\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Finds installed HTTPlug implementations and PSR-7 message factories", + "homepage": "http://php-http.org", + "keywords": [ + "adapter", + "client", + "discovery", + "factory", + "http", + "message", + "psr7" + ], + "support": { + "issues": "https://github.com/php-http/discovery/issues", + "source": "https://github.com/php-http/discovery/tree/1.14.3" + }, + "time": "2022-07-11T14:04:40+00:00" + }, + { + "name": "php-http/guzzle7-adapter", + "version": "1.0.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/guzzle7-adapter.git", + "reference": "fb075a71dbfa4847cf0c2938c4e5a9c478ef8b01" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/guzzle7-adapter/zipball/fb075a71dbfa4847cf0c2938c4e5a9c478ef8b01", + "reference": "fb075a71dbfa4847cf0c2938c4e5a9c478ef8b01", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.0", + "php": "^7.2 | ^8.0", + "php-http/httplug": "^2.0", + "psr/http-client": "^1.0" + }, + "provide": { + "php-http/async-client-implementation": "1.0", + "php-http/client-implementation": "1.0", + "psr/http-client-implementation": "1.0" + }, + "require-dev": { + "php-http/client-integration-tests": "^3.0", + "phpunit/phpunit": "^8.0|^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "0.2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Adapter\\Guzzle7\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com" + } + ], + "description": "Guzzle 7 HTTP Adapter", + "homepage": "http://httplug.io", + "keywords": [ + "Guzzle", + "http" + ], + "support": { + "issues": "https://github.com/php-http/guzzle7-adapter/issues", + "source": "https://github.com/php-http/guzzle7-adapter/tree/1.0.0" + }, + "time": "2021-03-09T07:35:15+00:00" + }, + { + "name": "php-http/httplug", + "version": "2.3.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/httplug.git", + "reference": "f640739f80dfa1152533976e3c112477f69274eb" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/httplug/zipball/f640739f80dfa1152533976e3c112477f69274eb", + "reference": "f640739f80dfa1152533976e3c112477f69274eb", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "php-http/promise": "^1.1", + "psr/http-client": "^1.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "friends-of-phpspec/phpspec-code-coverage": "^4.1", + "phpspec/phpspec": "^5.1 || ^6.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "2.x-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Client\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Eric GELOEN", + "email": "geloen.eric@gmail.com" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com", + "homepage": "https://sagikazarmark.hu" + } + ], + "description": "HTTPlug, the HTTP client abstraction for PHP", + "homepage": "http://httplug.io", + "keywords": [ + "client", + "http" + ], + "support": { + "issues": "https://github.com/php-http/httplug/issues", + "source": "https://github.com/php-http/httplug/tree/2.3.0" + }, + "time": "2022-02-21T09:52:22+00:00" + }, + { + "name": "php-http/message", + "version": "1.13.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/message.git", + "reference": "7886e647a30a966a1a8d1dad1845b71ca8678361" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/message/zipball/7886e647a30a966a1a8d1dad1845b71ca8678361", + "reference": "7886e647a30a966a1a8d1dad1845b71ca8678361", + "shasum": "" + }, + "require": { + "clue/stream-filter": "^1.5", + "php": "^7.1 || ^8.0", + "php-http/message-factory": "^1.0.2", + "psr/http-message": "^1.0" + }, + "provide": { + "php-http/message-factory-implementation": "1.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.6", + "ext-zlib": "*", + "guzzlehttp/psr7": "^1.0", + "laminas/laminas-diactoros": "^2.0", + "phpspec/phpspec": "^5.1 || ^6.3 || ^7.1", + "slim/slim": "^3.0" + }, + "suggest": { + "ext-zlib": "Used with compressor/decompressor streams", + "guzzlehttp/psr7": "Used with Guzzle PSR-7 Factories", + "laminas/laminas-diactoros": "Used with Diactoros Factories", + "slim/slim": "Used with Slim Framework PSR-7 implementation" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.10-dev" + } + }, + "autoload": { + "files": [ + "src/filters.php" + ], + "psr-4": { + "Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "HTTP Message related tools", + "homepage": "http://php-http.org", + "keywords": [ + "http", + "message", + "psr-7" + ], + "support": { + "issues": "https://github.com/php-http/message/issues", + "source": "https://github.com/php-http/message/tree/1.13.0" + }, + "time": "2022-02-11T13:41:14+00:00" + }, + { + "name": "php-http/message-factory", + "version": "v1.0.2", + "source": { + "type": "git", + "url": "https://github.com/php-http/message-factory.git", + "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/message-factory/zipball/a478cb11f66a6ac48d8954216cfed9aa06a501a1", + "reference": "a478cb11f66a6ac48d8954216cfed9aa06a501a1", + "shasum": "" + }, + "require": { + "php": ">=5.4", + "psr/http-message": "^1.0" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.0-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Message\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Factory interfaces for PSR-7 HTTP Message", + "homepage": "http://php-http.org", + "keywords": [ + "factory", + "http", + "message", + "stream", + "uri" + ], + "support": { + "issues": "https://github.com/php-http/message-factory/issues", + "source": "https://github.com/php-http/message-factory/tree/master" + }, + "time": "2015-12-19T14:08:53+00:00" + }, + { + "name": "php-http/multipart-stream-builder", + "version": "1.2.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/multipart-stream-builder.git", + "reference": "11c1d31f72e01c738bbce9e27649a7cca829c30e" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/multipart-stream-builder/zipball/11c1d31f72e01c738bbce9e27649a7cca829c30e", + "reference": "11c1d31f72e01c738bbce9e27649a7cca829c30e", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0", + "php-http/discovery": "^1.7", + "php-http/message-factory": "^1.0.2", + "psr/http-factory": "^1.0", + "psr/http-message": "^1.0" + }, + "require-dev": { + "nyholm/psr7": "^1.0", + "php-http/message": "^1.5", + "phpunit/phpunit": "^7.5.15 || ^8.5 || ^9.3" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.x-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Message\\MultipartStream\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Tobias Nyholm", + "email": "tobias.nyholm@gmail.com" + } + ], + "description": "A builder class that help you create a multipart stream", + "homepage": "http://php-http.org", + "keywords": [ + "factory", + "http", + "message", + "multipart stream", + "stream" + ], + "support": { + "issues": "https://github.com/php-http/multipart-stream-builder/issues", + "source": "https://github.com/php-http/multipart-stream-builder/tree/1.2.0" + }, + "time": "2021-05-21T08:32:01+00:00" + }, + { + "name": "php-http/promise", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/php-http/promise.git", + "reference": "4c4c1f9b7289a2ec57cde7f1e9762a5789506f88" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-http/promise/zipball/4c4c1f9b7289a2ec57cde7f1e9762a5789506f88", + "reference": "4c4c1f9b7289a2ec57cde7f1e9762a5789506f88", + "shasum": "" + }, + "require": { + "php": "^7.1 || ^8.0" + }, + "require-dev": { + "friends-of-phpspec/phpspec-code-coverage": "^4.3.2", + "phpspec/phpspec": "^5.1.2 || ^6.2" + }, + "type": "library", + "extra": { + "branch-alias": { + "dev-master": "1.1-dev" + } + }, + "autoload": { + "psr-4": { + "Http\\Promise\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Joel Wurtz", + "email": "joel.wurtz@gmail.com" + }, + { + "name": "Márk Sági-Kazár", + "email": "mark.sagikazar@gmail.com" + } + ], + "description": "Promise used for asynchronous HTTP requests", + "homepage": "http://httplug.io", + "keywords": [ + "promise" + ], + "support": { + "issues": "https://github.com/php-http/promise/issues", + "source": "https://github.com/php-http/promise/tree/1.1.0" + }, + "time": "2020-07-07T09:29:14+00:00" }, { - "name": "nikic/php-parser", - "version": "v4.13.2", + "name": "php-jsonpointer/php-jsonpointer", + "version": "v3.0.2", "source": { "type": "git", - "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "210577fe3cf7badcc5814d99455df46564f3c077" + "url": "https://github.com/raphaelstolt/php-jsonpointer.git", + "reference": "4428f86c6f23846e9faa5a420c4ef14e485b3afb" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/210577fe3cf7badcc5814d99455df46564f3c077", - "reference": "210577fe3cf7badcc5814d99455df46564f3c077", + "url": "https://api.github.com/repos/raphaelstolt/php-jsonpointer/zipball/4428f86c6f23846e9faa5a420c4ef14e485b3afb", + "reference": "4428f86c6f23846e9faa5a420c4ef14e485b3afb", "shasum": "" }, "require": { - "ext-tokenizer": "*", - "php": ">=7.0" + "php": ">=5.4" }, "require-dev": { - "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "friendsofphp/php-cs-fixer": "^1.11", + "phpunit/phpunit": "4.6.*" }, - "bin": [ - "bin/php-parse" - ], "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "2.0.x-dev" } }, "autoload": { - "psr-4": { - "PhpParser\\": "lib/PhpParser" + "psr-0": { + "Rs\\Json": "src/" } }, "notification-url": "https://packagist.org/downloads/", "license": [ - "BSD-3-Clause" + "MIT" ], "authors": [ { - "name": "Nikita Popov" + "name": "Raphael Stolt", + "email": "raphael.stolt@gmail.com", + "homepage": "http://raphaelstolt.blogspot.com/" } ], - "description": "A PHP parser written in PHP", + "description": "Implementation of JSON Pointer (http://tools.ietf.org/html/rfc6901)", + "homepage": "https://github.com/raphaelstolt/php-jsonpointer", "keywords": [ - "parser", - "php" + "json", + "json pointer", + "json traversal" ], "support": { - "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.13.2" + "issues": "https://github.com/raphaelstolt/php-jsonpointer/issues", + "source": "https://github.com/raphaelstolt/php-jsonpointer/tree/master" }, - "time": "2021-11-30T19:35:32+00:00" + "time": "2016-08-29T08:51:01+00:00" }, { "name": "phpoption/phpoption", @@ -2727,6 +3657,71 @@ ], "time": "2021-09-25T23:10:38+00:00" }, + { + "name": "saasus-platform/saasus-sdk-php", + "version": "dev-feature/api-request-error-handling", + "source": { + "type": "git", + "url": "https://github.com/saasus-platform/saasus-sdk-php.git", + "reference": "6d9173ec9ce5a236a9bd0fd4bc7493f1c794961c" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/saasus-platform/saasus-sdk-php/zipball/6d9173ec9ce5a236a9bd0fd4bc7493f1c794961c", + "reference": "6d9173ec9ce5a236a9bd0fd4bc7493f1c794961c", + "shasum": "" + }, + "require": { + "guzzlehttp/guzzle": "^7.4", + "guzzlehttp/promises": "^1.4.0", + "guzzlehttp/psr7": "^1.7.0|^2.0", + "jane-php/open-api-runtime": "^7.3", + "laravel/framework": "^9.2", + "php": ">=8.0.2", + "php-http/guzzle7-adapter": "^1.0" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.10", + "jane-php/open-api-3": "^7.3", + "phpunit/phpunit": "*", + "psr/cache": "^1.0", + "psr/simple-cache": "^1.0" + }, + "type": "library", + "extra": { + "symfony": { + "allow-contrib": "true" + } + }, + "autoload": { + "psr-4": { + "AntiPatternInc\\Saasus\\": "src/", + "AntiPatternInc\\Saasus\\Sdk\\": "generated/" + } + }, + "autoload-dev": { + "psr-4": { + "AntiPatternInc\\Saasus\\Test\\": "test/" + } + }, + "scripts": { + "test": [ + "phpunit test" + ] + }, + "authors": [ + { + "name": "SaaSus Platform", + "email": "saasus@anti-pattern.co.jp" + } + ], + "description": "SaaSus SDK for PHP", + "support": { + "source": "https://github.com/saasus-platform/saasus-sdk-php/tree/feature/api-request-error-handling", + "issues": "https://github.com/saasus-platform/saasus-sdk-php/issues" + }, + "time": "2023-03-04T14:54:20+00:00" + }, { "name": "symfony/console", "version": "v6.0.5", @@ -3584,6 +4579,73 @@ ], "time": "2022-01-02T09:55:41+00:00" }, + { + "name": "symfony/options-resolver", + "version": "v6.0.3", + "source": { + "type": "git", + "url": "https://github.com/symfony/options-resolver.git", + "reference": "51f7006670febe4cbcbae177cbffe93ff833250d" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/options-resolver/zipball/51f7006670febe4cbcbae177cbffe93ff833250d", + "reference": "51f7006670febe4cbcbae177cbffe93ff833250d", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "symfony/deprecation-contracts": "^2.1|^3" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\OptionsResolver\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Provides an improved replacement for the array_replace PHP function", + "homepage": "https://symfony.com", + "keywords": [ + "config", + "configuration", + "options" + ], + "support": { + "source": "https://github.com/symfony/options-resolver/tree/v6.0.3" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-01-02T09:55:41+00:00" + }, { "name": "symfony/polyfill-ctype", "version": "v1.25.0", @@ -4388,6 +5450,107 @@ ], "time": "2022-01-31T19:46:53+00:00" }, + { + "name": "symfony/serializer", + "version": "v6.0.14", + "source": { + "type": "git", + "url": "https://github.com/symfony/serializer.git", + "reference": "d3bea0f239aca9589224a84150066da5495e9e11" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/serializer/zipball/d3bea0f239aca9589224a84150066da5495e9e11", + "reference": "d3bea0f239aca9589224a84150066da5495e9e11", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "symfony/polyfill-ctype": "~1.8" + }, + "conflict": { + "doctrine/annotations": "<1.12", + "phpdocumentor/reflection-docblock": "<3.2.2", + "phpdocumentor/type-resolver": "<1.4.0", + "symfony/dependency-injection": "<5.4", + "symfony/property-access": "<5.4", + "symfony/property-info": "<5.4", + "symfony/uid": "<5.4", + "symfony/yaml": "<5.4" + }, + "require-dev": { + "doctrine/annotations": "^1.12", + "phpdocumentor/reflection-docblock": "^3.2|^4.0|^5.0", + "symfony/cache": "^5.4|^6.0", + "symfony/config": "^5.4|^6.0", + "symfony/dependency-injection": "^5.4|^6.0", + "symfony/error-handler": "^5.4|^6.0", + "symfony/filesystem": "^5.4|^6.0", + "symfony/form": "^5.4|^6.0", + "symfony/http-foundation": "^5.4|^6.0", + "symfony/http-kernel": "^5.4|^6.0", + "symfony/mime": "^5.4|^6.0", + "symfony/property-access": "^5.4|^6.0", + "symfony/property-info": "^5.4|^6.0", + "symfony/uid": "^5.4|^6.0", + "symfony/validator": "^5.4|^6.0", + "symfony/var-dumper": "^5.4|^6.0", + "symfony/var-exporter": "^5.4|^6.0", + "symfony/yaml": "^5.4|^6.0" + }, + "suggest": { + "psr/cache-implementation": "For using the metadata cache.", + "symfony/config": "For using the XML mapping loader.", + "symfony/mime": "For using a MIME type guesser within the DataUriNormalizer.", + "symfony/property-access": "For using the ObjectNormalizer.", + "symfony/property-info": "To deserialize relations.", + "symfony/var-exporter": "For using the metadata compiler.", + "symfony/yaml": "For using the default YAML mapping loader." + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Serializer\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Handles serializing and deserializing data structures, including object graphs, into array structures or other formats like XML and JSON.", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/serializer/tree/v6.0.14" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-10-11T15:20:43+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.0.0", @@ -4816,6 +5979,80 @@ ], "time": "2022-03-02T12:58:14+00:00" }, + { + "name": "symfony/yaml", + "version": "v6.0.16", + "source": { + "type": "git", + "url": "https://github.com/symfony/yaml.git", + "reference": "eb85bd1b0b297e976f3ada52ad239ef80b4dbd0b" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/yaml/zipball/eb85bd1b0b297e976f3ada52ad239ef80b4dbd0b", + "reference": "eb85bd1b0b297e976f3ada52ad239ef80b4dbd0b", + "shasum": "" + }, + "require": { + "php": ">=8.0.2", + "symfony/polyfill-ctype": "^1.8" + }, + "conflict": { + "symfony/console": "<5.4" + }, + "require-dev": { + "symfony/console": "^5.4|^6.0" + }, + "suggest": { + "symfony/console": "For validating YAML files using the lint command" + }, + "bin": [ + "Resources/bin/yaml-lint" + ], + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Yaml\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Loads and dumps YAML files", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/yaml/tree/v6.0.16" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2022-11-25T18:58:46+00:00" + }, { "name": "tijsverkoyen/css-to-inline-styles", "version": "2.2.4", @@ -7789,12 +9026,14 @@ ], "aliases": [], "minimum-stability": "dev", - "stability-flags": [], + "stability-flags": { + "saasus-platform/saasus-sdk-php": 20 + }, "prefer-stable": true, "prefer-lowest": false, "platform": { "php": "^8.0.2" }, "platform-dev": [], - "plugin-api-version": "2.2.0" + "plugin-api-version": "2.3.0" } diff --git a/php/laravel/api/config/logging.php b/php/laravel/api/config/logging.php index fefe088..e0e1230 100644 --- a/php/laravel/api/config/logging.php +++ b/php/laravel/api/config/logging.php @@ -50,7 +50,7 @@ 'channels' => [ 'stack' => [ 'driver' => 'stack', - 'channels' => ['single'], + 'channels' => ['stderr'], 'ignore_exceptions' => false, ], @@ -82,7 +82,7 @@ 'handler_with' => [ 'host' => env('PAPERTRAIL_URL'), 'port' => env('PAPERTRAIL_PORT'), - 'connectionString' => 'tls://'.env('PAPERTRAIL_URL').':'.env('PAPERTRAIL_PORT'), + 'connectionString' => 'tls://' . env('PAPERTRAIL_URL') . ':' . env('PAPERTRAIL_PORT'), ], ], diff --git a/php/laravel/api/config/view.php b/php/laravel/api/config/view.php index 22b8a18..5f332aa 100644 --- a/php/laravel/api/config/view.php +++ b/php/laravel/api/config/view.php @@ -15,6 +15,7 @@ 'paths' => [ resource_path('views'), + resource_path('../vendor/saasus-platform/saasus-sdk-php/src/Laravel/Views'), ], /* diff --git a/php/laravel/api/resources/views/messageBoard/index.blade.php b/php/laravel/api/resources/views/messageBoard/index.blade.php index 31e4a1b..6d5d6a4 100644 --- a/php/laravel/api/resources/views/messageBoard/index.blade.php +++ b/php/laravel/api/resources/views/messageBoard/index.blade.php @@ -29,7 +29,7 @@ @foreach ($messages as $message)

- {{ $message->user->name }} + {{ $message->user_id }} {{ $message->created_at->format('Y/m/d H:i') }} diff --git a/php/laravel/api/routes/api.php b/php/laravel/api/routes/api.php index 6bf1599..370df81 100644 --- a/php/laravel/api/routes/api.php +++ b/php/laravel/api/routes/api.php @@ -15,7 +15,13 @@ | */ -Route::get('/board', 'App\Http\Controllers\MessageApiController@index'); -Route::post('/post', 'App\Http\Controllers\MessageApiController@post'); -Route::get('/plan', 'App\Http\Controllers\PlanApiController@index'); -Route::get('/tenant', 'App\Http\Controllers\TenantApiController@index'); +// 一時コードからIDトークンなどの認証情報を取得するコントローラを登録 +Route::get('/callback', 'AntiPatternInc\Saasus\Laravel\Controllers\CallbackApiController@index'); + +// SaaSus SDK標準のAuth Middlewareを利用する +Route::middleware(\AntiPatternInc\Saasus\Laravel\Middleware\Auth::class)->group(function () { + Route::get('/board', 'App\Http\Controllers\MessageApiController@index'); + Route::post('/post', 'App\Http\Controllers\MessageApiController@post'); + Route::get('/plan', 'App\Http\Controllers\PlanApiController@index'); + Route::get('/tenant', 'App\Http\Controllers\TenantApiController@index'); +}); diff --git a/php/laravel/api/routes/web.php b/php/laravel/api/routes/web.php index f691390..640e04b 100644 --- a/php/laravel/api/routes/web.php +++ b/php/laravel/api/routes/web.php @@ -13,13 +13,20 @@ | */ -Route::middleware('auth')->group(function () { - Route::get('/', function () { - return view('welcome'); - }); +// Route::middleware('auth')->group(function () { +// Route::get('/', function () { +// return view('welcome'); +// }); +// SaaSus SDK標準のAuth Middlewareを利用する +Route::middleware(\AntiPatternInc\Saasus\Laravel\Middleware\Auth::class)->group(function () { Route::get('/dispatch', 'App\Http\Controllers\DispatchController@index')->name('dispatch'); Route::get('/board', 'App\Http\Controllers\MessageController@index')->name('board'); Route::post('/post', 'App\Http\Controllers\MessageController@post')->name('post'); + + Route::redirect('/', '/board'); }); -require __DIR__ . '/auth.php'; +// require __DIR__ . '/auth.php'; + +// SaaSus SDK標準のCallback Controllerを利用して、JWTをCookieやLocal Storageに入れる +Route::get('/callback', 'AntiPatternInc\Saasus\Laravel\Controllers\CallbackController@index'); diff --git a/php/laravel/front/src/pages/board/index.tsx b/php/laravel/front/src/pages/board/index.tsx index 44dacae..3d5d6a8 100644 --- a/php/laravel/front/src/pages/board/index.tsx +++ b/php/laravel/front/src/pages/board/index.tsx @@ -6,13 +6,24 @@ import axios from '@/lib/axios' const Board = () => { const { mutate } = useSWRConfig() - const fetcher = (url: string) => axios.get(url).then((res) => res.data) + const fetcher = (url: string) => { + // Local StorageからJWTを取得し、Bearer tokenとしてヘッダにつけてAPIコールする + const token = localStorage.getItem('SaaSusIdToken') + if (!token) return '' + return axios + .get(url, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) + .then((res) => res.data) + } const { data: tenant_name, error: tenant_error } = useSWR( `/api/tenant`, fetcher ) const { data: messages, error } = useSWR(`/api/board`, fetcher, { - refreshInterval: 3000, + refreshInterval: 5000, }) if (error || tenant_error) return

failed to load
if (!messages || !tenant_name) return
loading...
@@ -22,7 +33,13 @@ const Board = () => { // 再検証をせずに直ちにローカルデータを更新 mutate('/api/board', [...messages, formValue], false) // 更新するために API にリクエストを送信 - await axios.post('/api/post', formValue) + // Local StorageからJWTを取得し、Bearer tokenとしてヘッダにつけてAPIコールする + const token = localStorage.getItem('SaaSusIdToken') + await axios.post('/api/post', formValue, { + headers: { + Authorization: `Bearer ${token}`, + }, + }) } return ( @@ -36,4 +53,4 @@ const Board = () => { ) } -export default Board +export default Board \ No newline at end of file diff --git a/php/laravel/front/src/pages/callback/index.tsx b/php/laravel/front/src/pages/callback/index.tsx new file mode 100644 index 0000000..38290c2 --- /dev/null +++ b/php/laravel/front/src/pages/callback/index.tsx @@ -0,0 +1,30 @@ +import Container from '@mui/material/Container' +import { useRouter } from 'next/router' +import { useEffect } from 'react' +import axios from '@/lib/axios' + +const Callback = () => { + const router = useRouter() + const query = router.query + const code = query.code as string + + const fetchAuthCredentials = async () => { + const res = await axios.get(`/api/callback?code=${code}`) + // 渡ってきたJWTをLocal Storageに保存する + const idToken = res.data.id_token as string + localStorage.setItem('SaaSusIdToken', idToken) + router.replace('/board') + } + + useEffect(() => { + if (router.isReady) { + if (code) { + fetchAuthCredentials() + } + } + }, [query, router]) + + return +} + +export default Callback \ No newline at end of file