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
110 changes: 110 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# Created by .ignore support plugin (hsz.mobi)
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User.ts-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
frontend/fsp-claim-app/.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Java template
# Compiled class file
*.class

# Log file
*.log

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Maven template
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
.mvn/wrapper/maven-wrapper.jar

.idea/
backend/FspClaimAppService/src/main/resources/bcDev.properties
8 changes: 8 additions & 0 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM php:8.3-apache

COPY --from=composer:latest /usr/bin/composer /usr/local/bin/composer
COPY src/ /var/www/html/

RUN docker-php-ext-install mysqli pdo pdo_mysql
RUN composer dump-autoload
RUN chown -R www-data:www-data /var/www/html
38 changes: 38 additions & 0 deletions backend/db/cookbook.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
CREATE TABLE `connection_test` (
`id` INT(10) NOT NULL
) COLLATE='utf8mb3_general_ci' ENGINE=InnoDB;

INSERT INTO `connection_test` (`id`) VALUES ('1');

CREATE TABLE `recipe` (
`id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
`title` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
`category` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
`description` TEXT NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
`createdAt` DATE NULL DEFAULT NULL,
`deleted` TINYINT(3) NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE,
INDEX `category` (`category`) USING BTREE,
INDEX `createdAt` (`createdAt`) USING BTREE,
INDEX `deleted` (`deleted`) USING BTREE,
FULLTEXT INDEX `title` (`title`),
FULLTEXT INDEX `description` (`description`)
) COLLATE='utf8mb3_general_ci' ENGINE=InnoDB;

CREATE TABLE `ingredient` (
`id` INT(10) NOT NULL AUTO_INCREMENT,
`recipeId` INT(10) NOT NULL,
`ingredientName` VARCHAR(255) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
`unitOfMeasure` VARCHAR(20) NULL DEFAULT NULL COLLATE 'utf8mb3_general_ci',
`amount` DECIMAL(20,6) NULL DEFAULT '0.000000',
`deleted` TINYINT(3) NULL DEFAULT '0',
PRIMARY KEY (`id`) USING BTREE,
INDEX `recipe_id` (`recipeId`) USING BTREE,
INDEX `ingredient_name` (`ingredientName`) USING BTREE,
INDEX `unit_of_measure` (`unitOfMeasure`) USING BTREE,
INDEX `deleted` (`deleted`) USING BTREE,
INDEX `amount` (`amount`) USING BTREE,
FULLTEXT INDEX `ingredient_name_ft` (`ingredientName`)
) COLLATE='utf8mb3_general_ci' ENGINE=InnoDB;


16 changes: 16 additions & 0 deletions backend/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
services:
www:
build:
dockerfile: Dockerfile
ports:
- "4567:80"
db:
image: mysql
restart: unless-stopped
environment:
MYSQL_ROOT_PASSWORD: secret
MYSQL_DATABASE: 'cookbook_db'
ports:
- "3306:3306"
volumes:
- "./db/cookbook.sql:/docker-entrypoint-initdb.d/cookbook.sql"
15 changes: 15 additions & 0 deletions backend/src/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "marekpeters35/cookbook_service",
"description": "cookbook_service",
"authors": [
{
"name": "mpeters",
"email": "marekpeters35@gmail.con"
}
],
"autoload": {
"psr-4": {
"cookbook_service\\": ""
}
}
}
67 changes: 67 additions & 0 deletions backend/src/controller/baseController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
namespace cookbook_service\controller;

abstract class baseController
{
/**
* @param array $data
* @return string
*/
protected function responseJson(array $data) {
http_response_code(200);
$this->setResponseHeader('json');

return json_encode($data);
}

/**
* @param int $statusCode
* @param string $error
* @return string
*/
protected function responseError(int $statusCode, string $error) {
http_response_code($statusCode);
$this->setResponseHeader('json');

return json_encode(['error' => $error]);
}

/**
* @param string $contendTypeShort
* @return $this
*/
protected function setResponseHeader(string $contendTypeShort) {
$contendType = '';

switch (strtolower($contendTypeShort)) {
case 'json':
$contendType = 'application/json';
break;
case 'html':
$contendType = 'text/html';
break;
default:
$contendType = 'text/plain';
break;
}

header('Content-Type: ' . $contendType);
return $this;
}

/**
* @param mixed $var
* @return false|string
*/
public function debugOutVar($var) {
ob_start();
echo '<pre>'.var_dump($var);
echo '</pre>';
$output = ob_get_contents();
ob_end_clean();

$this->setResponseHeader('html');

return $output;
}
}
88 changes: 88 additions & 0 deletions backend/src/controller/incomingController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php
namespace cookbook_service\controller;

use cookbook_service\exception\cookbookException;

class incomingController extends baseController {
/**
* @var recipeController
*/
private $recipeController;
/**
* @var setupController
*/
private $setupController;

function __construct() {
$this->getSetupController()->testConnection();
}

/**
* @throws cookbookException
* @return string
*/
public function routeIncomingRequest() {
// CORS HEADER for external service
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: GET, POST');
header("Access-Control-Allow-Headers: X-Requested-With");

$data = [];
$action = 'nothing';

// Rewrite Post from Angular to $_POST superglobal
$_POST = json_decode(file_get_contents('php://input'), true);

if (isset($_POST['action'])) {
$action = $_POST['action'];
$data = $_POST;
} elseif (isset($_GET['action'])) {
$action = $_GET['action'];
$data = $_GET;
}

return match ($action) {
'halloService' => $this->responseJson(['success'=> true]),
'checkExistRecipes' => $this->getRecipeController()->checkExistRecipes(),
'recipeList' => $this->getRecipeController()->recipeList(),
'recipeDetails' => $this->getRecipeController()->recipeDetails($data),
'createRecipe' => $this->getRecipeController()->createRecipe($data),
'editRecipe' => $this->getRecipeController()->editRecipe($data),
'deleteRecipe' => $this->getRecipeController()->deleteRecipe($data),
'setupExampleRecipes' => $this->getSetupController()->setupExampleRecipes(),
default => $this->responseError(405, 'The given request is not registerd'),
};
}

/**
* @param int $code
* @param string $msg
* @return string
*/
public function error(int $code, string $msg ){
return $this->responseError($code, $msg);
}

/**
* @return recipeController
*/
private function getRecipeController() {
if ($this->recipeController === NULL) {
$this->recipeController = new recipeController();
}

return $this->recipeController;
}

/**
* @return setupController
*/
private function getSetupController() {
if ($this->setupController === NULL) {
$this->setupController = new setupController();
}

return $this->setupController;
}

}
Loading