diff --git a/Controller/API/CustomerController.php b/Controller/API/CustomerController.php index 15c45d4..f431159 100644 --- a/Controller/API/CustomerController.php +++ b/Controller/API/CustomerController.php @@ -130,8 +130,8 @@ class CustomerController extends BaseController{ $this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Request'; return; } - $jsonPayload = file_get_contents('php://input'); - $input = json_decode($jsonPayload); + $jsonPayload = file_get_contents('php://input'); + $input = json_decode($jsonPayload); if (! $this->validatePerson($input)) { return $this->unprocessableEntityResponse(); @@ -179,13 +179,19 @@ class CustomerController extends BaseController{ if (strtoupper($this->requestMethod) == $request) { $response = 'true'; } - return $response; } private function validatePerson($input) { - return true; + $validtion = false; + if($input->customer_name_first != null){ + $validtion = true; + if($input->customer_name_last == null) { + $validtion = false; + } + } + return $validtion; } private function unprocessableEntityResponse() @@ -194,6 +200,8 @@ class CustomerController extends BaseController{ $response['body'] = json_encode([ 'error' => 'Invalid input' ]); + $this->strErrorDesc = 'Unprocessable Payload'; + $this->strErrorHeader = 'HTTP/1.1 422 Unprocessable Payload'; return $response; } @@ -201,6 +209,8 @@ class CustomerController extends BaseController{ { $response['status_code_header'] = 'HTTP/1.1 404 Entity Not Found'; $response['body'] = null; + $this->strErrorDesc = 'Request Entity Not Found'; + $this->strErrorHeader = 'HTTP/1.1 422 Entity Not Found'; return $response; } } diff --git a/Model/CustomerModel.php b/Model/CustomerModel.php index a08893d..7ba0d8a 100644 --- a/Model/CustomerModel.php +++ b/Model/CustomerModel.php @@ -88,34 +88,13 @@ class CustomerModel extends Database { public function insertCustomer($jsonPayLoad) { - $rowCount = $this->processStatement("CALL insert_new_customer_proc(?,?,?,?,?,?,?,?,?,?)", - [$jsonPayLoad->customer_name_first, - $jsonPayLoad->last, - $jsonPayLoad->email, - $jsonPayLoad->phone, - $jsonPayLoad->birthday, - $jsonPayLoad->street, - $jsonPayLoad->city, - $jsonPayLoad->state, - $jsonPayLoad->zip, - $jsonPayLoad->loyalty]); + $rowCount = $this->processStatement("CALL insert_new_customer_proc", $jsonPayLoad); return $rowCount; } public function updateCustomer($jsonPayLoad) { - $rowCount = $this->processStatement("CALL update_existing_customer_proc(?,?,?,?,?,?,?,?,?,?,?)", - [$jsonPayLoad->customer_id, - $jsonPayLoad->customer_name_first, - $jsonPayLoad->customer_name_last, - $jsonPayLoad->customer_email, - $jsonPayLoad->customer_phone, - $jsonPayLoad->customer_birthday, - $jsonPayLoad->customer_street, - $jsonPayLoad->address_city, - $jsonPayLoad->address_state, - $jsonPayLoad->address_zip, - $jsonPayLoad->loyalty_member]); + $rowCount = $this->processStatement("CALL update_existing_customer_proc", $jsonPayLoad); return $rowCount; } diff --git a/Model/Database.php b/Model/Database.php index 234734f..237ba9a 100644 --- a/Model/Database.php +++ b/Model/Database.php @@ -15,7 +15,7 @@ class Database { public function __construct() { try { - mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); + mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT); $this->connection = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_DATABASE_NAME); if ( mysqli_connect_errno()) { @@ -59,6 +59,8 @@ class Database { public function processStatement($query = "", $params = []) { try { + $parameters = str_repeat('?,', count($params) - 1) . '?'; + $query += "(".$parameters.")"; $stmt = $this->executeStatement( $query, $params ); $result = $this->connection->affected_rows; $stmt->close(); @@ -72,16 +74,17 @@ class Database { private function executeStatement($query = "", $params = []) { try { - $stmt = $this->connection->prepare( $query ); + $stmt = $this->connection->prepare($query); if($stmt === false) { throw New Exception("Unable to do prepared statement: " . $query); } - if( $params ) { + + /*if( $params ) { $stmt->bind_param(str_repeat("s", count($params)), ...$params); - //$stmt->bind_param("isssssssssi", $params[0],$params[1],$params[2],$params[3],$params[4],$params[5],$params[6],$params[7],$params[8],$params[9],$params[10]); - } - - $stmt->execute(); + }*/ + + $stmt->execute($params); + //$stmt->execute(); return $stmt; } catch(Exception $e) { throw New Exception( $e->getMessage() ); diff --git a/composer.json b/composer.json index d032a11..6e02390 100644 --- a/composer.json +++ b/composer.json @@ -14,6 +14,7 @@ ], "require-dev": { "phpunit/phpunit": "11", - "vitexsoftware/phpunit-skeleton-generator": "*" + "vitexsoftware/phpunit-skeleton-generator": "*", + "php-webdriver/webdriver": "*" } } diff --git a/composer.lock b/composer.lock index e6b08f9..edf9f2b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "242e5f38e4bcb2865e1a959b6ab2eae0", + "content-hash": "cda368583fd799f54642eb879b836eb5", "packages": [], "packages-dev": [ { @@ -242,6 +242,72 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-webdriver/webdriver", + "version": "1.15.1", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "cd52d9342c5aa738c2e75a67e47a1b6df97154e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/cd52d9342c5aa738c2e75a67e47a1b6df97154e8", + "reference": "cd52d9342c5aa738c2e75a67e47a1b6df97154e8", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^7.3 || ^8.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^5.0 || ^6.0 || ^7.0" + }, + "replace": { + "facebook/webdriver": "*" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.20.0", + "ondram/ci-detector": "^4.0", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpunit/phpunit": "^9.3", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^5.0 || ^6.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Exception/TimeoutException.php" + ], + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.", + "homepage": "https://github.com/php-webdriver/php-webdriver", + "keywords": [ + "Chromedriver", + "geckodriver", + "php", + "selenium", + "webdriver" + ], + "support": { + "issues": "https://github.com/php-webdriver/php-webdriver/issues", + "source": "https://github.com/php-webdriver/php-webdriver/tree/1.15.1" + }, + "time": "2023-10-20T12:21:20+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.3", @@ -2052,6 +2118,67 @@ ], "time": "2024-01-29T20:11:03+00:00" }, + { + "name": "symfony/process", + "version": "v7.0.7", + "source": { + "type": "git", + "url": "https://github.com/symfony/process.git", + "reference": "3839e56b94dd1dbd13235d27504e66baf23faba0" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/symfony/process/zipball/3839e56b94dd1dbd13235d27504e66baf23faba0", + "reference": "3839e56b94dd1dbd13235d27504e66baf23faba0", + "shasum": "" + }, + "require": { + "php": ">=8.2" + }, + "type": "library", + "autoload": { + "psr-4": { + "Symfony\\Component\\Process\\": "" + }, + "exclude-from-classmap": [ + "/Tests/" + ] + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Fabien Potencier", + "email": "fabien@symfony.com" + }, + { + "name": "Symfony Community", + "homepage": "https://symfony.com/contributors" + } + ], + "description": "Executes commands in sub-processes", + "homepage": "https://symfony.com", + "support": { + "source": "https://github.com/symfony/process/tree/v7.0.7" + }, + "funding": [ + { + "url": "https://symfony.com/sponsor", + "type": "custom" + }, + { + "url": "https://github.com/fabpot", + "type": "github" + }, + { + "url": "https://tidelift.com/funding/github/packagist/symfony/symfony", + "type": "tidelift" + } + ], + "time": "2024-04-18T09:29:19+00:00" + }, { "name": "symfony/service-contracts", "version": "v3.4.2",