فهرست منبع

Merge branch 'master' of ssh://git.mixtech.dev.br:22622/Bar/bartender

ljoaquim 5 ماه پیش
والد
کامیت
3440dd729e
3فایلهای تغییر یافته به همراه6 افزوده شده و 32 حذف شده
  1. 2 2
      controllers/ProductController.php
  2. 3 29
      middlewares/CorsControl.php
  3. 1 1
      migrations/migrations_v1.sql

+ 2 - 2
controllers/ProductController.php

@@ -36,7 +36,7 @@ class ProductController
             if (isset($body['product_name'], $body['product_price'], $body['category_id'])) {
                 $created = $this->model->createProduct(
                     $body['product_name'],
-                    (float)$body['product_price'],
+                    $body['product_price'],
                     (int)$body['category_id'],
                     $companyId
                 );
@@ -53,7 +53,7 @@ class ProductController
             if (isset($body['update_product_id'])) {
                 $productId = (int)$body['update_product_id'];
                 $productName = $body['product_name'] ?? null;
-                $productPrice = isset($body['product_price']) ? (float)$body['product_price'] : null;
+                $productPrice = $body['product_price'] ?? null;
 
                 if ($productName === null && $productPrice === null) {
                     return ResponseLib::sendFail("Missing product_name or product_price for update", [], "E_VALIDATE")->withStatus(400);

+ 3 - 29
middlewares/CorsControl.php

@@ -9,45 +9,19 @@ class CorsControl
 {
     public function __invoke(ServerRequestInterface $request, $next)
     {
-        // 1) Configurações CORS completamente abertas:
-        $corsHeaders = [
-            'Access-Control-Allow-Origin'      => '0.0.0.0',
-            'Access-Control-Allow-Methods'     => 'GET, POST, PUT, PATCH, DELETE, OPTIONS',
-            'Access-Control-Allow-Headers'     => 'Content-Type, Authorization, X-Requested-With, Accept, Origin',
-            'Access-Control-Allow-Credentials' => 'true',
-            'Access-Control-Max-Age'           => '86400', // cache de preflight por 24h
-        ];
-
-        // 2) Responde direto a preflight
         if ($request->getMethod() === 'OPTIONS') {
-            return new Response(204, $corsHeaders);
+            return new Response(204);
         }
 
-        // 3) Se o “next” vier como string (nome de classe), instancia‑o:
         if (is_string($next) && class_exists($next)) {
             $instance = new $next();
-
-            // se tiver __invoke, use-o
             if (is_callable($instance)) {
                 $next = $instance;
-            }
-            // caso seu controller siga outro padrão PSR-15, adapte aqui:
-            // elseif (method_exists($instance, 'handle')) {
-            //     $next = [$instance, 'handle'];
-            // }
-            else {
+            } else {
                 throw new \RuntimeException("Controller “{$next}” não é callable");
             }
         }
 
-        // 4) Chama o próximo handler (agora garantidamente callable)
-        $response = $next($request);
-
-        // 5) Injeta os headers CORS na resposta
-        foreach ($corsHeaders as $h => $v) {
-            $response = $response->withHeader($h, $v);
-        }
-
-        return $response;
+        return $next($request);
     }
 }

+ 1 - 1
migrations/migrations_v1.sql

@@ -54,7 +54,7 @@ CREATE TABLE "product" (
     "company_id" INTEGER NOT NULL,
     "category_id" INTEGER NOT NULL,
     "product_name" TEXT NOT NULL,
-    "product_price" REAL NOT NULL,
+    "product_price" TEXT NOT NULL,
     "product_flag" TEXT NOT NULL,    
     FOREIGN KEY ("category_id") REFERENCES "category" ("category_id"),
     FOREIGN KEY ("company_id") REFERENCES "company" ("company_id")