領収証発行サービス
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

75 Zeilen
1.8KB

  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\LoginUserManager;
  9. use App\Repositories\LoginUserRepository;
  10. use Illuminate\Http\JsonResponse;
  11. use Illuminate\Http\Request;
  12. class CreateController extends WebController
  13. {
  14. use LoginUser;
  15. public function name(): string
  16. {
  17. return "ログインユーザー一覧取得";
  18. }
  19. public function description(): string
  20. {
  21. return "ログインユーザー一覧を取得する";
  22. }
  23. public function __construct(
  24. protected CreateParam $param,
  25. private LoginUserManager $manager
  26. ) {
  27. parent::__construct();
  28. $this->roleAllow(UserRole::CONTRACT_ADMIN);
  29. }
  30. protected function getParam(): IParam
  31. {
  32. return $this->param;
  33. }
  34. protected function run(Request $request): JsonResponse
  35. {
  36. $param = $this->param;
  37. try {
  38. $this->transaction->beginTransaction();
  39. $currentContract = $this->loginUser()->getCurrentContract();
  40. if (!$currentContract) {
  41. throw new AppCommonException("認証不正");
  42. }
  43. $messages = $this->manager->initForCreate($currentContract)
  44. ->fill($param->toArray())
  45. ->create();
  46. if (count($messages) !== 0) {
  47. $this->transaction->rollBack();
  48. return $this->validateErrorResponse($messages);
  49. }
  50. $this->transaction->commit();
  51. } catch (Exception $e) {
  52. $this->transaction->rollBack();
  53. throw $e;
  54. }
  55. return $this->successResponse();
  56. }
  57. }