Sfoglia il codice sorgente

fix: HTTP status final

Fernando 4 mesi fa
parent
commit
c9d7b5cef3

+ 1 - 1
controllers/CategoryCreateController.php

@@ -26,7 +26,7 @@ class CategoryCreateController
              ->key('category_name', v::stringType()->notEmpty()->alnum(' '))
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = $body['company_id'];

+ 1 - 1
controllers/CategoryDeleteController.php

@@ -26,7 +26,7 @@ class CategoryDeleteController
              ->key('category_name', v::stringType()->notEmpty()->alnum(' '))
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = $body['company_id'];

+ 1 - 1
controllers/CategoryGetController.php

@@ -25,7 +25,7 @@ class CategoryGetController
             v::key('company_id', v::intType()->positive())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];

+ 1 - 1
controllers/CategoryUpdateFlagController.php

@@ -27,7 +27,7 @@ class CategoryUpdateFlagController
              ->key('category_flag', v::stringType()->notEmpty())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = $body['company_id'];

+ 1 - 1
controllers/DescriptionCreateController.php

@@ -20,7 +20,7 @@ class DescriptionCreateController
              ->key('description_text', v::stringType()->notEmpty())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $model = new DescriptionModel();

+ 1 - 1
controllers/DescriptionUpdateController.php

@@ -20,7 +20,7 @@ class DescriptionUpdateController
              ->key('description_text', v::stringType()->notEmpty())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $productId = (int) $body['product_id'];

+ 1 - 1
controllers/LoginController.php

@@ -20,7 +20,7 @@ class LoginController
              ->key('password', v::stringType()->notEmpty())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $username = $body['username'];

+ 2 - 2
controllers/OrderCreateController.php

@@ -33,7 +33,7 @@ class OrderCreateController
              ->key('status_status', v::stringType()->notEmpty()->in(['Aberta', 'Finalizada', 'Cancelada']))
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $tableId = (int) $body['table_id'];
@@ -47,7 +47,7 @@ class OrderCreateController
         $userId = $this->getUserIdByUserName($userName, $companyId);
 
         if (!$userId) {
-            return ResponseLib::sendFail("User '{$userName}' Not Found", [], "E_USER_NOT_FOUND")->withStatus(404);
+            return ResponseLib::sendFail("User '{$userName}' Not Found", [], "E_USER_NOT_FOUND")->withStatus(204);
         }
 
         $statusId = $this->model->getStatusIdByName($statusStatus);

+ 2 - 2
controllers/OrderDeleteController.php

@@ -26,7 +26,7 @@ class OrderDeleteController
                 ->key('company_id', v::intType()->positive())
                 ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
     
         $orderId = (int) $body['order_id'];
@@ -37,6 +37,6 @@ class OrderDeleteController
     
         return $deleted
             ? ResponseLib::sendOk(['deleted' => true, 'hard' => $hardDelete])
-            : ResponseLib::sendFail("Failed to Delete Order or Order Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Delete Order or Order Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/OrderGetController.php

@@ -30,7 +30,7 @@ class OrderGetController
                 ->key('table_id', v::optional(v::intType()->positive()), false) // Adicionado table_id como opcional
                 ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];
@@ -74,6 +74,6 @@ class OrderGetController
             return ResponseLib::sendOk($orders);
         }
 
-        return ResponseLib::sendFail("No Orders Found for the Given Criteria", [], "E_DATABASE")->withStatus(404);
+        return ResponseLib::sendFail("No Orders Found for the Given Criteria", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 1 - 1
controllers/OrderItemCreateController.php

@@ -28,7 +28,7 @@ class OrderItemCreateController
               ->key('kitchen_note', v::optional(v::stringType()), false)
               ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];

+ 2 - 2
controllers/OrderItemDeleteController.php

@@ -27,7 +27,7 @@ class OrderItemDeleteController
                 ->key('company_id', v::intType()->positive()) 
                 ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $orderItemId = (int) $body['order_item_id'];
@@ -37,6 +37,6 @@ class OrderItemDeleteController
 
         return $deleted
             ? ResponseLib::sendOk(['deleted' => true])
-            : ResponseLib::sendFail("Failed to Delete Order Item or Item Not Found for this Company", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Delete Order Item or Item Not Found for this Company", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/OrderItemGetController.php

@@ -32,7 +32,7 @@ class OrderItemGetController
                 }
             }
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];
@@ -55,6 +55,6 @@ class OrderItemGetController
             return ResponseLib::sendOk($orderItems);
         }
 
-        return ResponseLib::sendFail("No Order Items Found for the Given Data", [], "E_DATABASE")->withStatus(404);
+        return ResponseLib::sendFail("No Order Items Found for the Given Data", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/OrderUpdateController.php

@@ -29,7 +29,7 @@ class OrderUpdateController
                 ->key('status_status', v::stringType()->notEmpty()->in(['Aberta', 'Finalizada', 'Cancelada']), true) // Adicione aqui todos os status possíveis para atualização
                 ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];
@@ -48,6 +48,6 @@ class OrderUpdateController
 
         return $updated
             ? ResponseLib::sendOk(['updated' => true])
-            : ResponseLib::sendFail("Failed to Update Order Status or Order Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Update Order Status or Order Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 1 - 1
controllers/ProductCreateController.php

@@ -37,7 +37,7 @@ class ProductCreateController
         }
 
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = $body['company_id'];

+ 2 - 2
controllers/ProductDeleteController.php

@@ -26,7 +26,7 @@ class ProductDeleteController
              ->key('product_name', v::stringType()->notEmpty()->alnum(' '))
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];
@@ -36,6 +36,6 @@ class ProductDeleteController
 
         return $deleted
             ? ResponseLib::sendOk(['deleted' => true])
-            : ResponseLib::sendFail("Failed to Delete Product or Product Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Delete Product or Product Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 1 - 1
controllers/ProductGetController.php

@@ -26,7 +26,7 @@ class ProductGetController
              ->key('show_description', v::optional(v::boolType()), false)
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];

+ 2 - 2
controllers/ProductUpdateController.php

@@ -30,7 +30,7 @@ class ProductUpdateController
              ->key('product_is_kitchen', v::optional(v::boolType()), false)
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $hasProductName = isset($body['product_name']) && $body['product_name'] !== null;
@@ -57,6 +57,6 @@ class ProductUpdateController
 
         return $updated
             ? ResponseLib::sendOk(['updated' => true])
-            : ResponseLib::sendFail("Failed to Update Product or Product Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Update Product or Product Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 1 - 1
controllers/RegisterController.php

@@ -22,7 +22,7 @@ class RegisterController
              ->key('role_id', v::intType()->positive())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $username = $body['username'];

+ 1 - 1
controllers/TableCreateController.php

@@ -28,7 +28,7 @@ class TableCreateController
              ->key('status_id', v::intVal()->positive())
              ->assert($body);
         } catch (NestedValidationException $e) {
-            return ResponseLib::sendFail($e->getMessages(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail($e->getMessages(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];

+ 2 - 2
controllers/TableDeleteController.php

@@ -30,13 +30,13 @@ class TableDeleteController
              ->key('company_id', v::intType()->positive())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $deleted = $this->model->deleteTableByNumber((string)$tableNumber, (int)$companyId);
 
         return $deleted
             ? ResponseLib::sendOk(['deleted' => true])
-            : ResponseLib::sendFail("Table Not Found or Already Deleted", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Table Not Found or Already Deleted", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/TableGetController.php

@@ -26,7 +26,7 @@ class TableGetController
             v::key('company_id', v::intType()->positive())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = $body['company_id'];
@@ -37,6 +37,6 @@ class TableGetController
             return ResponseLib::sendOk($tables);
         }
 
-        return ResponseLib::sendFail("Table Not Found", [], "E_DATABASE")->withStatus(404);
+        return ResponseLib::sendFail("Table Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/TableUpdateController.php

@@ -28,7 +28,7 @@ class TableUpdateController
              ->key('status_status', v::stringType()->notEmpty())
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $tableNumber = $body['table_number'];
@@ -45,6 +45,6 @@ class TableUpdateController
 
         return $updated
             ? ResponseLib::sendOk(['updated' => true])
-            : ResponseLib::sendFail("Failed to Update Status or Table Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Update Status or Table Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/UserDeleteController.php

@@ -26,7 +26,7 @@ class UserDeleteController
              ->key('user_name', v::stringType()->notEmpty()->alnum(' _'))  // permite espaço e underline
              ->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];
@@ -36,6 +36,6 @@ class UserDeleteController
 
         return $deleted
             ? ResponseLib::sendOk(['deleted' => true])
-            : ResponseLib::sendFail("Failed to Delete User or User Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("Failed to Delete User or User Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }

+ 2 - 2
controllers/UserGetController.php

@@ -24,7 +24,7 @@ class UserGetController
         try {
             v::key('company_id', v::intType()->positive())->assert($body);
         } catch (ValidationException $e) {
-            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(422);
+            return ResponseLib::sendFail("Validation failed: " . $e->getFullMessage(), [], "E_VALIDATE")->withStatus(401);
         }
 
         $companyId = (int) $body['company_id'];
@@ -32,6 +32,6 @@ class UserGetController
 
         return $users
             ? ResponseLib::sendOk($users)
-            : ResponseLib::sendFail("User Not Found", [], "E_DATABASE")->withStatus(404);
+            : ResponseLib::sendFail("User Not Found", [], "E_DATABASE")->withStatus(204);
     }
 }