issues/27: filter DTO, strip id from payloads, lifecycle updateAt
This commit is contained in:
committed by
Valeriy Petrov
parent
da5f7bb242
commit
76044381fd
@@ -52,22 +52,17 @@ final class CrudResponder
|
||||
string $entityClass,
|
||||
array $writeGroups,
|
||||
array $readGroups,
|
||||
bool $allowIdFromPayload = false,
|
||||
): JsonResponse {
|
||||
$payload = $this->decodePayload($request);
|
||||
if ($payload === null) {
|
||||
return $this->jsonError('Ожидается JSON-объект в теле запроса', Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
$deserializationPayload = $payload;
|
||||
if (!$allowIdFromPayload) {
|
||||
unset($deserializationPayload['id']);
|
||||
}
|
||||
unset($payload['id']);
|
||||
|
||||
try {
|
||||
/** @var T $entity */
|
||||
$entity = $this->serializer->deserialize(
|
||||
$this->encodePayload($deserializationPayload),
|
||||
$this->encodePayload($payload),
|
||||
$entityClass,
|
||||
'json',
|
||||
[
|
||||
@@ -78,15 +73,6 @@ final class CrudResponder
|
||||
return $this->jsonError('Ошибка десериализации: ' . $e->getMessage(), Response::HTTP_BAD_REQUEST);
|
||||
}
|
||||
|
||||
// По умолчанию публичный CRUD не принимает id от клиента. Если системной
|
||||
// интеграции понадобится внешний id, конкретный вызов должен явно передать true.
|
||||
if ($allowIdFromPayload && isset($payload['id']) && method_exists($entity, 'setId')) {
|
||||
$id = (int) $payload['id'];
|
||||
if ($id > 0) {
|
||||
$entity->setId($id);
|
||||
}
|
||||
}
|
||||
|
||||
if (($validationResponse = $this->validate($entity)) !== null) {
|
||||
return $validationResponse;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user