From 44924e367ae2f4369eec5f03d703258c75cedde3 Mon Sep 17 00:00:00 2001 From: "sosuke.iwabuchi" Date: Thu, 7 Sep 2023 09:01:51 +0900 Subject: [PATCH] =?UTF-8?q?=E5=85=A8=E4=BD=93=E6=95=B4=E5=82=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- app/Events/Model/CreatingEvent.php | 8 ++ .../Controllers/Web/Auth/LoginController.php | 88 +++++++++++++++++++ app/Http/Controllers/Web/Auth/LoginParam.php | 20 +++++ .../Controllers/Web/Auth/LogoutController.php | 35 ++++++++ app/Http/Controllers/Web/Auth/LogoutParam.php | 13 +++ app/Http/Controllers/Web/Auth/Me.php | 26 ++++++ .../Controllers/Web/Auth/MeController.php | 41 +++++++++ app/Http/Controllers/Web/Auth/MeParam.php | 13 +++ app/Http/Controllers/Web/WebController.php | 36 +------- app/Kintone/KintoneAccess.php | 12 +-- app/Kintone/KintoneRecordQuery.php | 2 +- app/Kintone/Models/KintoneModel.php | 23 +++-- app/Listeners/Model/CreatingListener.php | 20 +++++ app/Listeners/Model/UpdatingListener.php | 10 +++ app/Models/BaseModel.php | 75 ++++++++++------ app/Models/User.php | 7 +- app/Providers/EventServiceProvider.php | 2 +- app/Providers/RouteServiceProvider.php | 5 +- clear.sh | 28 ++++++ config/cors.php | 4 +- config/logging.php | 35 +++++++- database/.gitignore | 1 + database/factories/UserFactory.php | 38 ++++++++ .../2014_10_12_000000_create_users_table.php | 6 ++ database/seeders/DatabaseSeeder.php | 22 +++++ routes/api.php | 10 +-- routes/web.php | 7 +- tests/Feature/KintoneAccessTest.php | 9 +- 29 files changed, 495 insertions(+), 104 deletions(-) create mode 100644 app/Events/Model/CreatingEvent.php create mode 100644 app/Http/Controllers/Web/Auth/LoginController.php create mode 100644 app/Http/Controllers/Web/Auth/LoginParam.php create mode 100644 app/Http/Controllers/Web/Auth/LogoutController.php create mode 100644 app/Http/Controllers/Web/Auth/LogoutParam.php create mode 100644 app/Http/Controllers/Web/Auth/Me.php create mode 100644 app/Http/Controllers/Web/Auth/MeController.php create mode 100644 app/Http/Controllers/Web/Auth/MeParam.php create mode 100644 app/Listeners/Model/CreatingListener.php create mode 100644 clear.sh create mode 100644 database/.gitignore create mode 100644 database/factories/UserFactory.php create mode 100644 database/seeders/DatabaseSeeder.php diff --git a/.gitignore b/.gitignore index 51ef087..d37464d 100644 --- a/.gitignore +++ b/.gitignore @@ -17,4 +17,5 @@ yarn-error.log /.fleet /.idea /.vscode -_* \ No newline at end of file +_* +sail \ No newline at end of file diff --git a/app/Events/Model/CreatingEvent.php b/app/Events/Model/CreatingEvent.php new file mode 100644 index 0000000..b5ce6d6 --- /dev/null +++ b/app/Events/Model/CreatingEvent.php @@ -0,0 +1,8 @@ +param; + + $access = Customer::getAccess(); + $query = Customer::getQuery()->where(Customer::FIELD_EMAIL, $param->email); + + $customer = $access->all($query); + + if ($customer->count() !== 1) { + return $this->failedResponse(); + } + + /** + * @var Customer + */ + $customer = $customer->first(); + + $kintoneId = $customer->getRecordId(); + + $user = User::whereKintoneId($kintoneId) + ->first(); + + if ($user instanceof User) { + // すでにユーザー登録されているケース + if ($user->email !== $param->email) { + $user->email = $param->email; + $user->save(); + } + if (Auth::attempt([ + 'email' => $param->email, + 'password' => $param->password, + ])) { + return $this->successResponse($customer->toArray()); + } else { + return $this->failedResponse(); + } + } else { + // 初回ログインのケース + $password = "testtest"; + $user = new User(); + $user->email = $param->email; + $user->kintone_id = $customer->getRecordId(); + $user->password = $password; + $user->save(); + if (Auth::attempt([ + 'email' => $param->email, + 'password' => $password, + ])) { + return $this->successResponse($customer->toArray()); + } else { + return $this->failedResponse(); + } + } + } +} diff --git a/app/Http/Controllers/Web/Auth/LoginParam.php b/app/Http/Controllers/Web/Auth/LoginParam.php new file mode 100644 index 0000000..d7b071c --- /dev/null +++ b/app/Http/Controllers/Web/Auth/LoginParam.php @@ -0,0 +1,20 @@ + $this->str(), + 'password' => $this->str(), + ]; + } +} diff --git a/app/Http/Controllers/Web/Auth/LogoutController.php b/app/Http/Controllers/Web/Auth/LogoutController.php new file mode 100644 index 0000000..a3e2be7 --- /dev/null +++ b/app/Http/Controllers/Web/Auth/LogoutController.php @@ -0,0 +1,35 @@ +successResponse(); + } +} diff --git a/app/Http/Controllers/Web/Auth/LogoutParam.php b/app/Http/Controllers/Web/Auth/LogoutParam.php new file mode 100644 index 0000000..a7a0ae3 --- /dev/null +++ b/app/Http/Controllers/Web/Auth/LogoutParam.php @@ -0,0 +1,13 @@ +find($user->kintone_id); + + return $customer->toArray(); + } +} diff --git a/app/Http/Controllers/Web/Auth/MeController.php b/app/Http/Controllers/Web/Auth/MeController.php new file mode 100644 index 0000000..02fe346 --- /dev/null +++ b/app/Http/Controllers/Web/Auth/MeController.php @@ -0,0 +1,41 @@ +middleware('auth:sanctum'); + } + + protected function run(Request $request): JsonResponse + { + try { + return $this->successResponse($this->me()); + } catch (AppCommonException) { + return $this->failedResponse(); + } + } +} diff --git a/app/Http/Controllers/Web/Auth/MeParam.php b/app/Http/Controllers/Web/Auth/MeParam.php new file mode 100644 index 0000000..73fd307 --- /dev/null +++ b/app/Http/Controllers/Web/Auth/MeParam.php @@ -0,0 +1,13 @@ +run($request); $this->transaction->commit(); - Slack::commit(); return $ret; } catch (GeneralErrorMessageException $e) { $this->transaction->rollBack(); - Slack::commit(); return $this->failedResponse([], $e->getMessage()); } catch (AppCommonException $e) { $this->transaction->rollBack(); - Slack::commit(); logs()->error(sprintf("Appエラー:%s File:%s Line:%d", $e->getMessage(), $e->getFile(), $e->getLine())); return $this->failedResponse(); } catch (ExclusiveException $e) { $this->transaction->rollBack(); - Slack::commit(); logs()->error(sprintf("排他エラー:%s", $e->getMessage())); return $this->exclusiveErrorResponse(); } catch (LogicException $e) { $this->transaction->rollBack(); - Slack::commit(); logs()->error([ sprintf("実装エラー:%s", $e->getMessage()), get_class($e), @@ -204,18 +198,15 @@ abstract class WebController extends BaseController return $this->failedResponse(); } catch (ValidationException $e) { $this->transaction->rollBack(); - Slack::commit(); return $this->validateErrorResponse($e); } catch (HttpException $e) { $this->transaction->rollBack(); - Slack::commit(); if ($e->getStatusCode() === 401) { return $this->unAuthorizedResponse(); } throw e; } catch (Exception $e) { $this->transaction->rollBack(); - Slack::commit(); logs()->error([ sprintf("例外エラー:%s", $e->getMessage()), get_class($e), @@ -319,7 +310,7 @@ abstract class WebController extends BaseController $header = []; $user = Auth::user(); if ($user) { - $header["App-User-Auth"] = sprintf("%d,%d", $user->id, $user->role->value); + $header["App-User-Auth"] = sprintf("%s", $user->id); } else { $header["App-User-Auth"] = 'none'; } @@ -346,31 +337,6 @@ abstract class WebController extends BaseController if (!Auth::check()) { return; } - - $role = Auth::user()->role; - - if (!$this->canAccess($role)) { - abort(401); - } - } - - public function canAccess(UserRole $role) - { - if (is_array($this->roleAllow) && !in_array($role, $this->roleAllow)) { - return false; - } - - if (is_array($this->roleDisallow) && in_array($role, $this->roleDisallow)) { - return false; - } - - return $this->canCustomAccess(); - } - - public function canCustomAccess(): bool - { - - return true; } // 返却用データの登録 diff --git a/app/Kintone/KintoneAccess.php b/app/Kintone/KintoneAccess.php index 22377d2..33fe3c9 100644 --- a/app/Kintone/KintoneAccess.php +++ b/app/Kintone/KintoneAccess.php @@ -22,10 +22,10 @@ class KintoneAccess private int $appId; private const DEFAULT_FIELDS = [ - "レコード番号", - 'RecordNo', "作成日時", "更新日時", + '$id', + '$revision', ]; private array $fields = []; @@ -83,10 +83,9 @@ class KintoneAccess /** * @param integer $id - * @param TValue $result - * @return Response + * @return TValue */ - public function find(int $id, KintoneModel &$result): Response + public function find(int $id) { $response = Http::withHeaders([ @@ -104,9 +103,10 @@ class KintoneAccess throw $e; } } + $result = new $this->appName(); $result->setDataFromRecordResponse($response['record']); - return $response; + return $result; } /** diff --git a/app/Kintone/KintoneRecordQuery.php b/app/Kintone/KintoneRecordQuery.php index 682a3fe..ae3a65c 100644 --- a/app/Kintone/KintoneRecordQuery.php +++ b/app/Kintone/KintoneRecordQuery.php @@ -28,7 +28,7 @@ class KintoneRecordQuery $ret .= " "; } $ret .= $this->order; - logger(sprintf("QUERY[%s]:%s", $this->appName, $ret)); + // logger(sprintf("QUERY[%s]:%s", $this->appName, $ret)); return $ret; } diff --git a/app/Kintone/Models/KintoneModel.php b/app/Kintone/Models/KintoneModel.php index 2449326..81e6731 100644 --- a/app/Kintone/Models/KintoneModel.php +++ b/app/Kintone/Models/KintoneModel.php @@ -63,7 +63,7 @@ abstract class KintoneModel { return new KintoneRecordQuery(static::class); } - protected ?int $recordId = null; + protected ?string $recordId = null; protected ?int $revision = null; @@ -142,7 +142,7 @@ abstract class KintoneModel foreach ($data as $fieldCode => $ele) { $type = data_get($ele, "type"); $value = data_get($ele, "value"); - if ($type === "RECORD_NUMBER") { + if ($type === "__ID__") { $this->recordId = $value; continue; } @@ -259,25 +259,16 @@ abstract class KintoneModel return $this->get($key); } - public function getRecordId(): ?int + public function getRecordId(): ?string { return $this->recordId; } - public function setRecordId(int $recordId): void - { - $this->recordId = $recordId; - } public function getRevision(): ?int { return $this->revision; } - public function setRevision(int $revision): void - { - $this->revision = $revision; - } - public function getUpdatedAt(): ?Carbon { return $this->updatedAt; @@ -287,7 +278,7 @@ abstract class KintoneModel return $this->createdAt; } - public function toArray(): array + public function toArray($column = ['*']): array { if ($this->recordId === null) { throw new LogicException("保存前モデルのシリアライズ検知"); @@ -298,11 +289,17 @@ abstract class KintoneModel 'revision' => $this->revision, ]; + $columnAll = data_get($column, 0) === '*'; + /** * @var string $fieldCode */ foreach ($this->data as $fieldCode => $value) { + if (!$columnAll && !in_array($fieldCode, $column)) { + continue; + } + $type = data_get(static::FIELDS, $fieldCode); $columnName = data_get(static::FIELD_NAMES, $fieldCode, $fieldCode); diff --git a/app/Listeners/Model/CreatingListener.php b/app/Listeners/Model/CreatingListener.php new file mode 100644 index 0000000..329697a --- /dev/null +++ b/app/Listeners/Model/CreatingListener.php @@ -0,0 +1,20 @@ +model instanceof User) { + $event->model->password = Hash::make($event->model->password); + } + } +} diff --git a/app/Listeners/Model/UpdatingListener.php b/app/Listeners/Model/UpdatingListener.php index 2c2a7bc..da8ee48 100644 --- a/app/Listeners/Model/UpdatingListener.php +++ b/app/Listeners/Model/UpdatingListener.php @@ -3,7 +3,9 @@ namespace App\Listeners\Model; use App\Events\Model\UpdatingEvent; +use App\Models\User; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Hash; class UpdatingListener extends ModelListener { @@ -20,6 +22,14 @@ class UpdatingListener extends ModelListener } } + // ログインパスワードのハッシュ化 + if ($event->model instanceof User) { + if ($event->model->isDirty(User::COL_NAME_PASSWORD)) { + $event->model->password = Hash::make($event->model->password); + } + } + + $this->handleEvent($event->model); } } diff --git a/app/Models/BaseModel.php b/app/Models/BaseModel.php index b844c86..de4f382 100644 --- a/app/Models/BaseModel.php +++ b/app/Models/BaseModel.php @@ -2,39 +2,41 @@ namespace App\Models; -use Auth; +use App\Events\Model\CreatedEvent; +use App\Events\Model\CreatingEvent; +use App\Events\Model\DeletedEvent; +use App\Events\Model\UpdatingEvent; +use App\Models\Feature\IModelFeature; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Illuminate\Database\Query\Builder; use Illuminate\Support\Facades\DB; +use Illuminate\Support\Str; -/** - * @property int|null $created_by - */ -abstract class BaseModel extends Model +abstract class BaseModel extends Model implements IModelFeature { use HasFactory; const COL_NAME_ID = ColumnName::ID; - const COL_NAME_CREATED_BY = 'created_by'; - const COL_NAME_CREATED_AT = self::CREATED_AT; - const COL_NAME_UPDATED_AT = self::UPDATED_AT; - - public function __construct(array $attr = []) - { - if (Auth::check()) { - $this->created_by = Auth::id(); - } - - parent::__construct($attr); - } + const COL_NAME_CREATED_BY = ColumnName::CREATED_BY; + const COL_NAME_UPDATED_BY = ColumnName::UPDATED_BY; + const COL_NAME_CREATED_AT = ColumnName::CREATED_AT; + const COL_NAME_UPDATED_AT = ColumnName::UPDATED_AT; + const COL_NAME_DELETED_AT = ColumnName::DELETED_AT; protected $guarded = [ self::COL_NAME_ID, + self::COL_NAME_CREATED_BY, + self::COL_NAME_UPDATED_BY, + self::COL_NAME_CREATED_AT, + self::COL_NAME_UPDATED_AT, + self::COL_NAME_DELETED_AT, ]; - public static function getBuilder(string $name = 'main') + public static function getBuilder(string $name = 'main'): Builder { - return DB::table(static::getTableName(), $name); + return DB::table(static::getTableName(), $name) + ->whereNull($name . "." . static::COL_NAME_DELETED_AT); } public static function getTableName(): string @@ -42,26 +44,49 @@ abstract class BaseModel extends Model return (new static)->getTable(); } - public function copy(BaseModel|User $from) + public static function hasColumn(string $columnName): bool + { + $target = sprintf("%s::COL_NAME_%s", static::class, Str::upper($columnName)); + $ret = defined($target); + return $ret; + } + + + public function copy(IModelFeature $from): static { $data = $from->getAttributeKeys(); foreach ($data as $key) { - if ($key === ColumnName::ID && $this instanceof BaseHistory) { - continue; - } $this->$key = $from->$key; } return $this; } - public function getAttributeKeys() + public function getAttributeKeys(): array { return array_values(array_unique(array_merge(array_keys($this->attributesToArray()), $this->hidden))); } public function isNotSavedModel(): bool { - return data_get($this, self::COL_NAME_ID) === null; + return data_get($this, ColumnName::ID) === null; + } + + protected $dispatchesEvents = [ + 'creating' => CreatingEvent::class, + 'created' => CreatedEvent::class, + 'updating' => UpdatingEvent::class, + 'deleted' => DeletedEvent::class, + ]; + + + // カラムが存在する項目のみfillするようオーバーライド + public function fill(array $atr) + { + $filterd = array_filter($atr, function ($value, $key) { + return static::hasColumn($key); + }, ARRAY_FILTER_USE_BOTH); + + return parent::fill($filterd); } } diff --git a/app/Models/User.php b/app/Models/User.php index 05e5f18..77a62ed 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -2,8 +2,8 @@ namespace App\Models; -use App\Codes\UserRole; use App\Events\Model\CreatedEvent; +use App\Events\Model\CreatingEvent; use App\Events\Model\DeletedEvent; use App\Events\Model\UpdatingEvent; use App\Models\Feature\IModelFeature; @@ -21,7 +21,6 @@ class User extends Authenticatable implements IModelFeature use HasApiTokens, HasFactory, Notifiable, HasUuids, SoftDeletes; const COL_NAME_ID = 'id'; - const COL_NAME_ROLE = 'role'; const COL_NAME_EMAIL = 'email'; const COL_NAME_NAME = 'name'; const COL_NAME_PASSWORD = 'password'; @@ -50,11 +49,9 @@ class User extends Authenticatable implements IModelFeature self::COL_NAME_DELETED_AT, ]; - protected $casts = [ - self::COL_NAME_ROLE => UserRole::class, - ]; protected $dispatchesEvents = [ + 'creating' => CreatingEvent::class, 'created' => CreatedEvent::class, 'updating' => UpdatingEvent::class, 'deleted' => DeletedEvent::class, diff --git a/app/Providers/EventServiceProvider.php b/app/Providers/EventServiceProvider.php index 2d65aac..87a48e4 100644 --- a/app/Providers/EventServiceProvider.php +++ b/app/Providers/EventServiceProvider.php @@ -33,6 +33,6 @@ class EventServiceProvider extends ServiceProvider */ public function shouldDiscoverEvents(): bool { - return false; + return true; } } diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index bc49109..e40d0fa 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -27,7 +27,7 @@ class RouteServiceProvider extends ServiceProvider $this->configureRateLimiting(); $this->routes(function () { - Route::middleware('api') + Route::middleware('web') ->prefix('api') ->group(base_path('routes/api.php')); @@ -44,5 +44,8 @@ class RouteServiceProvider extends ServiceProvider RateLimiter::for('api', function (Request $request) { return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); }); + RateLimiter::for('web', function (Request $request) { + return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip()); + }); } } diff --git a/clear.sh b/clear.sh new file mode 100644 index 0000000..ef1a98b --- /dev/null +++ b/clear.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +cd $(dirname $0) + +SAIL="" +COMMANDS=() + +if [ $# -eq 0 ]; then + SAIL="" + COMMANDS+=("composer install --optimize-autoloader --no-dev") +elif [ $# -eq 1 ] && [ $1 == "sail" ]; then + SAIL="./sail" + NO_DEV="--no-dev" +else + echo "引数不正" + exit 1 +fi + +COMMANDS+=("${SAIL} php artisan config:clear") +COMMANDS+=("${SAIL} php artisan route:clear") +COMMANDS+=("${SAIL} php artisan view:clear") +COMMANDS+=("${SAIL} php artisan event:clear") +COMMANDS+=("${SAIL} php artisan queue:restart") + +for COMMAND in "${COMMANDS[@]}"; do + echo ${COMMAND} + ${COMMAND} +done \ No newline at end of file diff --git a/config/cors.php b/config/cors.php index 8a39e6d..cc63f4f 100644 --- a/config/cors.php +++ b/config/cors.php @@ -19,7 +19,7 @@ return [ 'allowed_methods' => ['*'], - 'allowed_origins' => ['*'], + 'allowed_origins' => ['http://localhost:*', config('app.url')], 'allowed_origins_patterns' => [], @@ -29,6 +29,6 @@ return [ 'max_age' => 0, - 'supports_credentials' => false, + 'supports_credentials' => true, ]; diff --git a/config/logging.php b/config/logging.php index 5aa1dbb..83ac319 100644 --- a/config/logging.php +++ b/config/logging.php @@ -85,7 +85,7 @@ return [ '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'), ], ], @@ -117,6 +117,39 @@ return [ 'emergency' => [ 'path' => storage_path('logs/laravel.log'), ], + 'web' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/web.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 14, + // 'replace_placeholders' => true, + 'permission' => 0666, + ], + + 'batch' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/batch.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 14, + // 'replace_placeholders' => true, + 'permission' => 0666, + ], + 'queue-email' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/email.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 14, + // 'replace_placeholders' => true, + 'permission' => 0666, + ], + 'queue-job' => [ + 'driver' => 'daily', + 'path' => storage_path('logs/job.log'), + 'level' => env('LOG_LEVEL', 'debug'), + 'days' => 14, + // 'replace_placeholders' => true, + 'permission' => 0666, + ], ], ]; diff --git a/database/.gitignore b/database/.gitignore new file mode 100644 index 0000000..9b19b93 --- /dev/null +++ b/database/.gitignore @@ -0,0 +1 @@ +*.sqlite* diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 0000000..a6ecc0a --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,38 @@ + + */ +class UserFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'name' => fake()->name(), + 'email' => fake()->unique()->safeEmail(), + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; + } + + /** + * Indicate that the model's email address should be unverified. + */ + public function unverified(): static + { + return $this->state(fn (array $attributes) => [ + 'email_verified_at' => null, + ]); + } +} diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 818728f..6856d34 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -18,6 +18,9 @@ return new class extends Migration $table->string('email')->unique()->comment('Email'); $table->string('password')->comment('ログインパスワード'); $table->string('kintone_id')->comment('KintoneID'); + + $helper->index(1, ['email']); + $helper->index(2, ['kintone_id']); }); Schema::create('user_histories', function (Blueprint $table) { $helper = new MigrationHelper($table, true); @@ -26,6 +29,9 @@ return new class extends Migration $table->string('email')->comment('Email'); $table->string('password')->comment('ログインパスワード'); $table->string('kintone_id')->comment('KintoneID'); + + $helper->index(1, ['email']); + $helper->index(2, ['kintone_id']); }); } diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php new file mode 100644 index 0000000..a9f4519 --- /dev/null +++ b/database/seeders/DatabaseSeeder.php @@ -0,0 +1,22 @@ +create(); + + // \App\Models\User::factory()->create([ + // 'name' => 'Test User', + // 'email' => 'test@example.com', + // ]); + } +} diff --git a/routes/api.php b/routes/api.php index 889937e..00e6310 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,7 +1,6 @@ get('/user', function (Request $request) { - return $request->user(); -}); + +RouteHelper::post('/login', App\Http\Controllers\Web\Auth\LoginController::class); +RouteHelper::get('/logout', App\Http\Controllers\Web\Auth\LogoutController::class); +RouteHelper::get('/me', App\Http\Controllers\Web\Auth\MeController::class); diff --git a/routes/web.php b/routes/web.php index d259f33..e763da2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,6 @@ where('any', '.*'); diff --git a/tests/Feature/KintoneAccessTest.php b/tests/Feature/KintoneAccessTest.php index e0d2530..92d78c6 100644 --- a/tests/Feature/KintoneAccessTest.php +++ b/tests/Feature/KintoneAccessTest.php @@ -10,11 +10,12 @@ class KintoneAccessTest extends TestCase { public function test_find(): void { - $model = new SeasonTicketContract(); - $access = SeasonTicketContract::getAccess(); - $access->find(505, $model); + /** + * @var SeasonTicketContract + */ + $model = $access->find(505); $this->assertEquals("塩山兼司", $model->getStr(SeasonTicketContract::FIELD_CUSTOMER_NAME)); } @@ -63,7 +64,7 @@ class KintoneAccessTest extends TestCase $this->assertEquals("山下千晶", $model->getStr(Customer::FIELD_CUSTOMER_NAME)); $this->assertEquals("shi.yy16@gmail.com", $model->getStr(Customer::FIELD_EMAIL)); - $array = $model->toArray(); + $array = $model->toArray([Customer::FIELD_CUSTOMER_NAME, Customer::FIELD_EMAIL]); $this->assertEquals("山下千晶", $array['customer_name']); $this->assertEquals("shi.yy16@gmail.com", $array['email']); }