diff --git a/Controller/ApiAttributeController.php b/Controller/ApiAttributeController.php index 0768e7b..44ef5d8 100644 --- a/Controller/ApiAttributeController.php +++ b/Controller/ApiAttributeController.php @@ -58,16 +58,15 @@ final class ApiAttributeController extends Controller public function apiLotAttributeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateLotAttributeCreate($request))) { - $response->data['attribute_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } $attribute = $this->createLotAttributeFromRequest($request); $this->createModel($request->header->account, $attribute, LotAttributeMapper::class, 'attribute', $request->getOrigin()); - - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute', 'Attribute successfully created', $attribute); + $this->createStandardCreateResponse($request, $response, $attribute); } /** @@ -137,15 +136,15 @@ final class ApiAttributeController extends Controller public function apiLotAttributeTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateLotAttributeTypeL11nCreate($request))) { - $response->data['attr_type_l11n_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } $attrL11n = $this->createLotAttributeTypeL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, LotAttributeTypeL11nMapper::class, 'attr_type_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); + $this->createStandardCreateResponse($request, $response, $attrL11n); } /** @@ -206,16 +205,15 @@ final class ApiAttributeController extends Controller public function apiLotAttributeTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateLotAttributeTypeCreate($request))) { - $response->data['attr_type_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } $attrType = $this->createLotAttributeTypeFromRequest($request); $this->createModel($request->header->account, $attrType, LotAttributeTypeMapper::class, 'attr_type', $request->getOrigin()); - - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute type', 'Attribute type successfully created', $attrType); + $this->createStandardCreateResponse($request, $response, $attrType); } /** @@ -232,7 +230,7 @@ final class ApiAttributeController extends Controller $attrType = new AttributeType($request->getDataString('name') ?? ''); $attrType->datatype = $request->getDataInt('datatype') ?? 0; $attrType->custom = $request->getDataBool('custom') ?? false; - $attrType->isRequired = (bool) ($request->getData('is_required') ?? false); + $attrType->isRequired = $request->getDataBool('is_required') ?? false; $attrType->validationPattern = $request->getDataString('validation_pattern') ?? ''; $attrType->setL11n($request->getDataString('title') ?? '', $request->getDataString('language') ?? ISO639x1Enum::_EN); $attrType->setFields($request->getDataInt('fields') ?? 0); @@ -277,8 +275,8 @@ final class ApiAttributeController extends Controller public function apiLotAttributeValueCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateLotAttributeValueCreate($request))) { - $response->data['attr_value_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } @@ -295,7 +293,7 @@ final class ApiAttributeController extends Controller ); } - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Attribute value', 'Attribute value successfully created', $attrValue); + $this->createStandardCreateResponse($request, $response, $attrValue); } /** @@ -362,15 +360,15 @@ final class ApiAttributeController extends Controller public function apiLotAttributeValueL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateLotAttributeValueL11nCreate($request))) { - $response->data['attr_value_l11n_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } $attrL11n = $this->createLotAttributeValueL11nFromRequest($request); $this->createModel($request->header->account, $attrL11n, LotAttributeValueL11nMapper::class, 'attr_value_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $attrL11n); + $this->createStandardCreateResponse($request, $response, $attrL11n); } /** diff --git a/Controller/ApiStockTypeController.php b/Controller/ApiStockTypeController.php index 87d4e29..fdef4b6 100644 --- a/Controller/ApiStockTypeController.php +++ b/Controller/ApiStockTypeController.php @@ -22,10 +22,8 @@ use Modules\WarehouseManagement\Models\StockTypeMapper; use phpOMS\Localization\BaseStringL11n; use phpOMS\Localization\ISO639x1Enum; use phpOMS\Message\Http\RequestStatusCode; -use phpOMS\Message\NotificationLevel; use phpOMS\Message\RequestAbstract; use phpOMS\Message\ResponseAbstract; -use phpOMS\Model\Message\FormValidation; /** * Warehouse class. @@ -53,16 +51,15 @@ final class ApiStockTypeController extends Controller public function apiStockTypeCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateStockTypeCreate($request))) { - $response->data['stock_type_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } $stockType = $this->createStockTypeFromRequest($request); $this->createModel($request->header->account, $stockType, StockTypeMapper::class, 'stock_type', $request->getOrigin()); - - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Stock type', 'Stock type successfully created', $stockType); + $this->createStandardCreateResponse($request, $response, $stockType); } /** @@ -120,15 +117,15 @@ final class ApiStockTypeController extends Controller public function apiStockTypeL11nCreate(RequestAbstract $request, ResponseAbstract $response, mixed $data = null) : void { if (!empty($val = $this->validateStockTypeL11nCreate($request))) { - $response->data['stock_type_l11n_create'] = new FormValidation($val); - $response->header->status = RequestStatusCode::R_400; + $response->header->status = RequestStatusCode::R_400; + $this->createInvalidCreateResponse($request, $response, $val); return; } $stockTypeL11n = $this->createStockTypeL11nFromRequest($request); $this->createModel($request->header->account, $stockTypeL11n, StockTypeL11nMapper::class, 'stock_type_l11n', $request->getOrigin()); - $this->fillJsonResponse($request, $response, NotificationLevel::OK, 'Localization', 'Localization successfully created', $stockTypeL11n); + $this->createStandardCreateResponse($request, $response, $stockTypeL11n); } /**