瀏覽代碼

feat(incomplete): category route

Fernando 5 月之前
父節點
當前提交
8d30bfff1c
共有 3 個文件被更改,包括 42 次插入0 次删除
  1. 21 0
      controllers/CategoryController.php
  2. 19 0
      models/CategoryModel.php
  3. 2 0
      public/index.php

+ 21 - 0
controllers/CategoryController.php

@@ -0,0 +1,21 @@
+<?php
+
+namespace Controllers;
+
+use Libs\ResponseLib;
+use Psr\Http\Message\ServerRequestInterface;
+
+class CategoryController
+{
+    public function __invoke(ServerRequestInterface $request)
+    {
+        $body = json_decode((string) $request->getBody(), true);
+        $category_id = $body['category_id'];
+        $company_id = $body['company_id'];
+        $category_name = $body['category_name'];
+        $category_is_kitchen = $body['category_is_kitchen'];
+        $category_flag = $body['category_flag'];
+
+        return ResponseLib::sendOk($data);
+    }
+}

+ 19 - 0
models/CategoryModel.php

@@ -0,0 +1,19 @@
+<?php 
+
+namespace Models;
+
+class CategoryModel
+{
+    private \PDO $pdo;
+
+    public function __construct()
+    {
+        // Conecta ao DB usando variável do .env
+        $dbFile = $_ENV['DB_FILE'];
+        $dbPath = __DIR__ . '/../' . $dbFile;
+        $this->pdo = new \PDO("sqlite:" . $dbPath);
+        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
+    }
+
+    
+}

+ 2 - 0
public/index.php

@@ -32,4 +32,6 @@ $app->get('/jwthelloworld', $authJwt,\Controllers\HelloController::class);
 $app->post('/login', \Controllers\LoginController::class);
 $app->post('/register', \Controllers\RegisterController::class);
 
+$app->get('/category', \Controllers\CategoryController::class);
+
 $app->run();