領収証発行サービス
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.

87 líneas
2.2KB

  1. <?php
  2. namespace App\Http\Controllers\Web\LoginUser;
  3. use App\Codes\UserRole;
  4. use App\Exceptions\AppCommonException;
  5. use App\Features\LoginUser;
  6. use App\Http\Controllers\Web\IParam;
  7. use App\Http\Controllers\Web\WebController;
  8. use App\Logic\User\ContractAdminUserManager;
  9. use App\Logic\User\LoginUserManager;
  10. use App\Logic\User\UserManager;
  11. use App\Repositories\LoginUserRepository;
  12. use Illuminate\Http\JsonResponse;
  13. use Illuminate\Http\Request;
  14. class CreateController extends WebController
  15. {
  16. use LoginUser;
  17. private UserManager $manager;
  18. public function name(): string
  19. {
  20. return "ログインユーザー新規登録";
  21. }
  22. public function description(): string
  23. {
  24. return "ログインユーザーを新規登録する";
  25. }
  26. public function __construct(
  27. protected CreateParam $param,
  28. ) {
  29. parent::__construct();
  30. $this->roleAllow(UserRole::CONTRACT_ADMIN);
  31. }
  32. protected function getParam(): IParam
  33. {
  34. return $this->param;
  35. }
  36. protected function run(Request $request): JsonResponse
  37. {
  38. $param = $this->param;
  39. // マネージャー起動
  40. if ($param->role === UserRole::CONTRACT_ADMIN) {
  41. if ($this->loginUser()->user()->role === UserRole::SUPER_ADMIN) {
  42. $this->manager = new ContractAdminUserManager();
  43. } else {
  44. $this->unAuthorizedResponse();
  45. }
  46. } else {
  47. $this->manager = new LoginUserManager();
  48. }
  49. try {
  50. $this->transaction->beginTransaction();
  51. $currentContract = $this->loginUser()->getCurrentContract();
  52. if (!$currentContract) {
  53. throw new AppCommonException("認証不正");
  54. }
  55. $messages = $this->manager->initForCreate($currentContract)
  56. ->fill($param->toArray())
  57. ->create();
  58. if (count($messages) !== 0) {
  59. $this->transaction->rollBack();
  60. return $this->validateErrorResponse($messages);
  61. }
  62. $this->transaction->commit();
  63. } catch (Exception $e) {
  64. $this->transaction->rollBack();
  65. throw $e;
  66. }
  67. return $this->successResponse();
  68. }
  69. }