Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions app/controllers/CategoryController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

include 'Controller.php';
include '../../models/Category.php';


class CategoryController extends Controller{
function save($obj) {
$category = new Category();
return $category->save($obj);
}
function update($obj){
$category = new Category();
return $category->update($obj);
}

function delete($obj){
$category = new Category();
return $category->delete($obj);
}

function find($id = null){
$category = new Category();
return $category->find($id);
}

function findAll(){
$category = new Category();
return $category->findAll();
}
}
32 changes: 32 additions & 0 deletions app/controllers/ProductController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

include 'Controller.php';
include '../../models/Product.php';


class ProductController extends Controller{
function save($obj) {
$product = new Product();
return $product->save($obj);
}

/*function update($obj){
$product = new User();
return $product->update($obj);
}

function delete($obj){
$product = new User();
return $product->delete($obj);
}*/

function find($id = null){
$product = new Product();
return $product->find($id);
}

function findAll(){
$product = new Product();
return $product->findAll();
}
}
42 changes: 42 additions & 0 deletions app/models/Category.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<?php

include 'Model.php';

class Category extends Model {
private $id = null;
private $name;

public function __serialize(): array {
$serialize = [
'name' => $this->name,
];
if ($this->id) $serialize['id'] = $this->id;
return $serialize;
}

public function save($obj): array{
$category = new Category();
$category->id = null;
$category->name = $obj->name;
return $category->model_save();
}

public function update($obj): array {
$category = new Category();
$category->id = $obj->id;
$category->name = $obj->name;
return $category->model_update();
}

public function delete($obj): array {
$category = new Category();
$category->id = $obj->id;
return $category->model_delete();
}

public function find($id = null): array {
$category = new Category();
$category->id = $id;
return $category->model_find();
}
}
38 changes: 38 additions & 0 deletions app/models/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

include 'Model.php';

class Product extends Model {
private $id = null;
private $name;
private $description;
private $image;
private $category;

public function __serialize(): array {
$serialize = [
'name' => $this->name,
'description' => $this->description,
'image' => $this->image,
'category' => $this->category,
];
if ($this->id) $serialize['id'] = $this->id;
return $serialize;
}

public function save($obj): array{
$product = new Product();
$product->id = null;
$product->name = $obj->name;
$product->description = $obj->description;
$product->image = $obj->image;
$product->category = $obj->category;
return $product->model_save();
}

public function find($id = null): array {
$product = new Product();
$product->id = $id;
return $product->model_find();
}
}
11 changes: 11 additions & 0 deletions app/routes/category/delete.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

include '../../controllers/CategoryController.php';

$data = file_get_contents('php://input');
$obj = json_decode($data);

if(!empty($data)){
$categoryController = new CategoryController();
echo json_encode($categoryController->delete($obj));
}
13 changes: 13 additions & 0 deletions app/routes/category/find.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

include '../../controllers/CategoryController.php';

$categoryController = new CategoryController();

$id = isset($_GET['id']) ? $_GET['id'] : null;

header('Content-Type: application/json');

$category = $categoryController->find($id);

echo json_encode($category);
11 changes: 11 additions & 0 deletions app/routes/category/save.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

include '../../controllers/CategoryController.php';

$data = file_get_contents('php://input');
$obj = json_decode($data);

if(!empty($data)){
$categoryController = new CategoryController();
echo json_encode($categoryController->save($obj));
}
15 changes: 15 additions & 0 deletions app/routes/category/update.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

include '../../controllers/CategoryController.php';

$data = file_get_contents('php://input');
$obj = json_decode($data);

$categoryController = new CategoryController();

$categorys = $categoryController->update($obj);

if(!empty($data)){
$categoryController = new CategoryController();
echo json_encode($categoryController->update($obj));
}
13 changes: 13 additions & 0 deletions app/routes/product/find.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

include '../../controllers/ProductController.php';

$userController = new ProductController();

$id = isset($_GET['id']) ? $_GET['id'] : null;

header('Content-Type: application/json');

$product = $productController->find($id);

echo json_encode($product);
12 changes: 12 additions & 0 deletions app/routes/product/save.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

include '../../controllers/ProductController.php';

$data = file_get_contents('php://input');
$obj = json_decode($data);

if(!empty($data)){
$productController = new ProductController();
echo json_encode($productController->save($obj));
var_dump($obj);
}