From f504c50c9b96f87ff2d8371c99ca5f3841d9bb5c Mon Sep 17 00:00:00 2001 From: vasya Date: Sun, 22 Mar 2026 19:13:21 +0300 Subject: [PATCH] =?UTF-8?q?=D0=BF=D0=BE=D0=BF=D1=8B=D1=82=D0=BA=D0=B0=20?= =?UTF-8?q?=D1=83=D0=BD=D0=B8=D1=84=D0=B8=D1=86=D0=B8=D1=80=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=82=D1=8C=20=D1=80=D0=B0=D0=B1=D0=BE=D1=82=D1=83=20?= =?UTF-8?q?=D1=81=20api=20=D1=87=D0=B5=D1=80=D0=B5=D0=B7=20=D0=B8=D1=81?= =?UTF-8?q?=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D0=BD=D0=B8?= =?UTF-8?q?=D0=B5=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=D0=B0,=20=D1=84=D0=BE?= =?UTF-8?q?=D1=80=D0=BC=D0=B8=D1=80=D1=83=D1=8E=D1=89=D0=B5=D0=B3=D0=BE=20?= =?UTF-8?q?=D0=BE=D1=82=D0=B2=D0=B5=D1=82=20=D0=BD=D0=B0=20api=20=D0=B7?= =?UTF-8?q?=D0=B0=D0=BF=D1=80=D0=BE=D1=81.=20=D0=92=20=D0=BF=D0=B0=D1=80?= =?UTF-8?q?=D0=B0=D0=B4=D0=B8=D0=B3=D0=BC=D0=B5=20=D0=BB=D0=B0=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=B5=D0=BB=D1=8C=20=D0=BF=D0=BE=D0=B4=D1=80=D0=B0=D0=B7?= =?UTF-8?q?=D1=83=D0=BC=D0=B5=D0=B2=D0=B0=D0=B5=D1=82=D1=81=D1=8F=20=D0=B8?= =?UTF-8?q?=D1=81=D0=BF=D0=BE=D0=BB=D1=8C=D0=B7=D0=BE=D0=B2=D0=B0=D1=82?= =?UTF-8?q?=D1=8C=20Resource,=20=D0=BD=D0=BE=20=D0=BA=D0=B0=D0=BA=20=D0=BF?= =?UTF-8?q?=D0=BE=20=D0=BC=D0=BD=D0=B5,=20=D0=B5=D0=B3=D0=BE=20=D1=84?= =?UTF-8?q?=D1=83=D0=BD=D0=BA=D1=86=D0=B8=D0=BE=D0=BD=D0=B0=D0=BB=20=D0=BD?= =?UTF-8?q?=D0=B5=D1=81=D0=BA=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D1=83=D0=B6?= =?UTF-8?q?=D0=B5,=20=D1=87=D0=B5=D0=BC=20=D1=85=D0=BE=D1=82=D0=B5=D0=BB?= =?UTF-8?q?=D0=BE=D1=81=D1=8C=20=D0=B1=D1=8B.=20=D0=94=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B0=D1=82=D0=BE=D1=87=D0=BD=D0=BE=20=D1=81=D1=8B=D1=80=D0=B0?= =?UTF-8?q?=D1=8F=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8?= =?UTF-8?q?=D1=8F,=20=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE=20=D0=BB=D1=83=D1=87?= =?UTF-8?q?=D1=88=D0=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DTO/ApiResponseDto.php | 27 ++++++++++++++ app/Providers/ApiResponderProvider.php | 27 ++++++++++++++ app/Services/ApiResponder.php | 51 ++++++++++++++++++++++++++ 3 files changed, 105 insertions(+) create mode 100644 app/DTO/ApiResponseDto.php create mode 100644 app/Providers/ApiResponderProvider.php create mode 100644 app/Services/ApiResponder.php diff --git a/app/DTO/ApiResponseDto.php b/app/DTO/ApiResponseDto.php new file mode 100644 index 0000000..2e3df80 --- /dev/null +++ b/app/DTO/ApiResponseDto.php @@ -0,0 +1,27 @@ +message, $this->statusCode, $this->data, $this->meta); + } + + // public static function success() + // { + // return new self($message, $data, $statusCode = 200); + // } + + // public static function error() + // { + // return new self($message, $data, $statusCode = 400); + // } + +} diff --git a/app/Providers/ApiResponderProvider.php b/app/Providers/ApiResponderProvider.php new file mode 100644 index 0000000..f25152b --- /dev/null +++ b/app/Providers/ApiResponderProvider.php @@ -0,0 +1,27 @@ +app->bind(ApiResponder::class, function($app){ + return new ApiResponder(); + }); + } + + /** + * Bootstrap services. + */ + public function boot(): void + { + // + } +} diff --git a/app/Services/ApiResponder.php b/app/Services/ApiResponder.php new file mode 100644 index 0000000..857e014 --- /dev/null +++ b/app/Services/ApiResponder.php @@ -0,0 +1,51 @@ +buildResponse(); + } + + public function error() + { + return $this->buildResponse(); + } + + public function setDto(ApiResponseDto $dto) + { + $this->dto = $dto; + } + + // public function fromDTO(ApiResponseDto $dto) + // { + // return $dto; + // } + + #Гаврилов + //СБОР СТАТИСТИКИ ПО ВЫЗЫВАЕМЫМ API ЕНДПОИНТАМ. ВНЕСТИ В TODO ПРОЕКТА + private function setStatistics() + { + } + +#Гаврилов +//ДОБАВЬ ЛОГИРОВАНИЕ ОШИБОК В TRY CATCH В .LOG ФАЙЛ + + private function buildResponse(): JsonResponse + { + //echo '
'; var_dump((array)$this->dto); echo'
'; + //return (array) $this->dto; + return response()->json((array) $this->dto); + } +} -- 2.52.0