Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f504c50c9b |
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Dto;
|
||||
|
||||
class ApiResponseDto
|
||||
{
|
||||
public function __construct(
|
||||
public readonly ?string $message = null,
|
||||
// public readonly ?int $statusCode = 200,
|
||||
public readonly mixed $data = null,
|
||||
public readonly mixed $meta = null,
|
||||
)
|
||||
{
|
||||
// return new self($this->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);
|
||||
// }
|
||||
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use App\Services\ApiResponder;
|
||||
|
||||
class ApiResponderProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->bind(ApiResponder::class, function($app){
|
||||
return new ApiResponder();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services;
|
||||
|
||||
use App\Dto\ApiResponseDto;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
|
||||
class ApiResponder{
|
||||
public $dto;
|
||||
|
||||
|
||||
public function __construct(
|
||||
)
|
||||
{}
|
||||
|
||||
public function success(): JsonResponse
|
||||
{
|
||||
return $this->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 '<pre>'; var_dump((array)$this->dto); echo'</pre>';
|
||||
//return (array) $this->dto;
|
||||
return response()->json((array) $this->dto);
|
||||
}
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
@import url('./../variables.css');
|
||||
|
||||
#form-valid-err-container{
|
||||
|
||||
background: red;
|
||||
padding: 5px;
|
||||
border-radius: 5px;
|
||||
|
||||
&.form-valid-err--hide{
|
||||
display: none;
|
||||
}
|
||||
&.form-valid-err--visible{
|
||||
display: block;
|
||||
}
|
||||
}
|
||||
@@ -1,30 +0,0 @@
|
||||
import React, { useEffect, useState } from "react";
|
||||
|
||||
/**
|
||||
* Объект с данными для отображения в блоке с ошибками
|
||||
*/
|
||||
export interface FormValidErrObject
|
||||
{
|
||||
fieldName: string | null,
|
||||
fieldErrors: string[] | []
|
||||
}
|
||||
|
||||
export default function FormValidErr ( {visible, validErrorsObj}: {visible: boolean, validErrorsObj: FormValidErrObject[]} )
|
||||
{
|
||||
const [blockVisible, setBlockVisible] = useState<boolean>(false);
|
||||
useEffect ( () => {
|
||||
setBlockVisible(visible)
|
||||
}, [visible]);
|
||||
return (
|
||||
<div id="form-valid-err-container" className={`form-valid-err--${blockVisible ? "visible" : 'hide'}`}>
|
||||
<ul>
|
||||
{ validErrorsObj.map( (validErrObj: FormValidErrObject, index: number) => (
|
||||
<li key={index}>
|
||||
<b>{ validErrObj.fieldName }</b>:
|
||||
<span>{ validErrObj.fieldErrors }</span>
|
||||
</li>
|
||||
)) }
|
||||
</ul>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user