Browse Source

ログインユーザ作成 契約管理者作成ルートを追加

develop
sosuke.iwabuchi 2 years ago
parent
commit
63ccd527bb
2 changed files with 20 additions and 4 deletions
  1. +16
    -4
      app/Http/Controllers/Web/LoginUser/CreateController.php
  2. +4
    -0
      app/Http/Controllers/Web/LoginUser/CreateParam.php

+ 16
- 4
app/Http/Controllers/Web/LoginUser/CreateController.php View File

@@ -7,7 +7,9 @@ use App\Exceptions\AppCommonException;
use App\Features\LoginUser; use App\Features\LoginUser;
use App\Http\Controllers\Web\IParam; use App\Http\Controllers\Web\IParam;
use App\Http\Controllers\Web\WebController; use App\Http\Controllers\Web\WebController;
use App\Logic\User\ContractAdminUserManager;
use App\Logic\User\LoginUserManager; use App\Logic\User\LoginUserManager;
use App\Logic\User\UserManager;
use App\Repositories\LoginUserRepository; use App\Repositories\LoginUserRepository;
use Illuminate\Http\JsonResponse; use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request; use Illuminate\Http\Request;
@@ -17,19 +19,20 @@ class CreateController extends WebController


use LoginUser; use LoginUser;


private UserManager $manager;

public function name(): string public function name(): string
{ {
return "ログインユーザー一覧取得";
return "ログインユーザー新規登録";
} }


public function description(): string public function description(): string
{ {
return "ログインユーザー一覧を取得する";
return "ログインユーザーを新規登録する";
} }


public function __construct( public function __construct(
protected CreateParam $param, protected CreateParam $param,
private LoginUserManager $manager
) { ) {
parent::__construct(); parent::__construct();
$this->roleAllow(UserRole::CONTRACT_ADMIN); $this->roleAllow(UserRole::CONTRACT_ADMIN);
@@ -44,11 +47,20 @@ class CreateController extends WebController
{ {
$param = $this->param; $param = $this->param;


// マネージャー起動
if ($param->role === UserRole::CONTRACT_ADMIN) {
if ($this->loginUser()->user()->role === UserRole::SUPER_ADMIN) {
$this->manager = new ContractAdminUserManager();
} else {
$this->unAuthorizedResponse();
}
} else {
$this->manager = new LoginUserManager();
}


try { try {
$this->transaction->beginTransaction(); $this->transaction->beginTransaction();



$currentContract = $this->loginUser()->getCurrentContract(); $currentContract = $this->loginUser()->getCurrentContract();
if (!$currentContract) { if (!$currentContract) {
throw new AppCommonException("認証不正"); throw new AppCommonException("認証不正");


+ 4
- 0
app/Http/Controllers/Web/LoginUser/CreateParam.php View File

@@ -2,14 +2,17 @@


namespace App\Http\Controllers\Web\LoginUser; namespace App\Http\Controllers\Web\LoginUser;


use App\Codes\UserRole;
use App\Http\Controllers\Web\BaseParam; use App\Http\Controllers\Web\BaseParam;
use App\Models\User; use App\Models\User;
use App\Rules\LoginPassword; use App\Rules\LoginPassword;
use Illuminate\Validation\Rules\Enum;


/** /**
* @property string $email * @property string $email
* @property string $name * @property string $name
* @property string $password * @property string $password
* @property ?UserRole $role
*/ */


class CreateParam extends BaseParam class CreateParam extends BaseParam
@@ -21,6 +24,7 @@ class CreateParam extends BaseParam
User::COL_NAME_EMAIL => $this->str(['email:dns']), User::COL_NAME_EMAIL => $this->str(['email:dns']),
User::COL_NAME_NAME => $this->str(), User::COL_NAME_NAME => $this->str(),
User::COL_NAME_PASSWORD => $this->str([new LoginPassword()]), User::COL_NAME_PASSWORD => $this->str([new LoginPassword()]),
User::COL_NAME_ROLE => $this->enum([new Enum(UserRole::class)], true),
]; ];
} }
} }

Loading…
Cancel
Save