Skip to content
Snippets Groups Projects
Verified Commit 9f22216e authored by Florian Azizian's avatar Florian Azizian
Browse files

Rename shippingTemplate

parent fc4ef0aa
No related branches found
No related tags found
No related merge requests found
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
* See LICENCE.txt file at the root folder for more details. * See LICENCE.txt file at the root folder for more details.
* This file is part of Maarch software. * This file is part of Maarch software.
* @brief ShippingController * @brief ShippingTemplateController
* @author dev <dev@maarch.org> * @author dev <dev@maarch.org>
* @ingroup core * @ingroup core
*/ */
...@@ -16,12 +16,12 @@ use Entity\models\EntityModel; ...@@ -16,12 +16,12 @@ use Entity\models\EntityModel;
use Group\models\ServiceModel; use Group\models\ServiceModel;
use History\controllers\HistoryController; use History\controllers\HistoryController;
use Respect\Validation\Validator; use Respect\Validation\Validator;
use Shipping\models\ShippingModel; use Shipping\models\ShippingTemplateModel;
use Slim\Http\Request; use Slim\Http\Request;
use Slim\Http\Response; use Slim\Http\Response;
use SrcCore\models\PasswordModel; use SrcCore\models\PasswordModel;
class ShippingController class ShippingTemplateController
{ {
public function get(Request $request, Response $response) public function get(Request $request, Response $response)
{ {
...@@ -29,7 +29,7 @@ class ShippingController ...@@ -29,7 +29,7 @@ class ShippingController
return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']); return $response->withStatus(403)->withJson(['errors' => 'Service forbidden']);
} }
return $response->withJson(['shippings' => ShippingModel::get(['id', 'label', 'description', 'options', 'fee', 'entities'])]); return $response->withJson(['shippings' => ShippingTemplateModel::get(['id', 'label', 'description', 'options', 'fee', 'entities'])]);
} }
public function getById(Request $request, Response $response, array $aArgs) public function getById(Request $request, Response $response, array $aArgs)
...@@ -42,7 +42,7 @@ class ShippingController ...@@ -42,7 +42,7 @@ class ShippingController
return $response->withStatus(400)->withJson(['errors' => 'id is not an integer']); return $response->withStatus(400)->withJson(['errors' => 'id is not an integer']);
} }
$shippingInfo = ShippingModel::getById(['id' => $aArgs['id']]); $shippingInfo = ShippingTemplateModel::getById(['id' => $aArgs['id']]);
if (empty($shippingInfo)) { if (empty($shippingInfo)) {
return $response->withStatus(400)->withJson(['errors' => 'Shipping does not exist']); return $response->withStatus(400)->withJson(['errors' => 'Shipping does not exist']);
} }
...@@ -91,7 +91,7 @@ class ShippingController ...@@ -91,7 +91,7 @@ class ShippingController
$body = $request->getParsedBody(); $body = $request->getParsedBody();
$errors = ShippingController::checkData($body, 'create'); $errors = ShippingTemplateController::checkData($body, 'create');
if (!empty($errors)) { if (!empty($errors)) {
return $response->withStatus(400)->withJson(['errors' => $errors]); return $response->withStatus(400)->withJson(['errors' => $errors]);
} }
...@@ -105,7 +105,7 @@ class ShippingController ...@@ -105,7 +105,7 @@ class ShippingController
$body['entities'] = json_encode($body['entities']); $body['entities'] = json_encode($body['entities']);
$body['account'] = json_encode($body['account']); $body['account'] = json_encode($body['account']);
$id = ShippingModel::create([ $id = ShippingTemplateModel::create([
'label' => $body['label'], 'label' => $body['label'],
'description' => $body['description'], 'description' => $body['description'],
'options' => $body['options'], 'options' => $body['options'],
...@@ -134,7 +134,7 @@ class ShippingController ...@@ -134,7 +134,7 @@ class ShippingController
$body = $request->getParsedBody(); $body = $request->getParsedBody();
$body['id'] = $aArgs['id']; $body['id'] = $aArgs['id'];
$errors = ShippingController::checkData($body, 'update'); $errors = ShippingTemplateController::checkData($body, 'update');
if (!empty($errors)) { if (!empty($errors)) {
return $response->withStatus(500)->withJson(['errors' => $errors]); return $response->withStatus(500)->withJson(['errors' => $errors]);
} }
...@@ -142,7 +142,7 @@ class ShippingController ...@@ -142,7 +142,7 @@ class ShippingController
if (!empty($body['account']['password'])) { if (!empty($body['account']['password'])) {
$body['account']['password'] = PasswordModel::encrypt(['password' => $body['account']['password']]); $body['account']['password'] = PasswordModel::encrypt(['password' => $body['account']['password']]);
} else { } else {
$shippingInfo = ShippingModel::getById(['id' => $aArgs['id'], 'select' => ['account']]); $shippingInfo = ShippingTemplateModel::getById(['id' => $aArgs['id'], 'select' => ['account']]);
$body['account']['password'] = $shippingInfo['account']->password; $body['account']['password'] = $shippingInfo['account']->password;
} }
...@@ -151,7 +151,7 @@ class ShippingController ...@@ -151,7 +151,7 @@ class ShippingController
$body['entities'] = json_encode($body['entities']); $body['entities'] = json_encode($body['entities']);
$body['account'] = json_encode($body['account']); $body['account'] = json_encode($body['account']);
ShippingModel::update($body); ShippingTemplateModel::update($body);
HistoryController::add([ HistoryController::add([
'tableName' => 'shipping_templates', 'tableName' => 'shipping_templates',
...@@ -174,12 +174,12 @@ class ShippingController ...@@ -174,12 +174,12 @@ class ShippingController
return $response->withStatus(400)->withJson(['errors' => 'id is not an integer']); return $response->withStatus(400)->withJson(['errors' => 'id is not an integer']);
} }
$shippingInfo = ShippingModel::getById(['id' => $aArgs['id'], 'select' => ['label']]); $shippingInfo = ShippingTemplateModel::getById(['id' => $aArgs['id'], 'select' => ['label']]);
if (empty($shippingInfo)) { if (empty($shippingInfo)) {
return $response->withStatus(400)->withJson(['errors' => 'Shipping does not exist']); return $response->withStatus(400)->withJson(['errors' => 'Shipping does not exist']);
} }
ShippingModel::delete(['id' => $aArgs['id']]); ShippingTemplateModel::delete(['id' => $aArgs['id']]);
HistoryController::add([ HistoryController::add([
'tableName' => 'shipping_templates', 'tableName' => 'shipping_templates',
...@@ -189,7 +189,7 @@ class ShippingController ...@@ -189,7 +189,7 @@ class ShippingController
'info' => _SHIPPING_DELETED. ' : ' . $shippingInfo['label'] 'info' => _SHIPPING_DELETED. ' : ' . $shippingInfo['label']
]); ]);
$shippings = ShippingModel::get(['select' => ['id', 'label', 'description', 'options', 'fee', 'entities']]); $shippings = ShippingTemplateModel::get(['select' => ['id', 'label', 'description', 'options', 'fee', 'entities']]);
return $response->withJson(['shippings' => $shippings]); return $response->withJson(['shippings' => $shippings]);
} }
...@@ -201,7 +201,7 @@ class ShippingController ...@@ -201,7 +201,7 @@ class ShippingController
if (!Validator::intVal()->validate($aArgs['id'])) { if (!Validator::intVal()->validate($aArgs['id'])) {
$errors[] = 'Id is not a numeric'; $errors[] = 'Id is not a numeric';
} else { } else {
$shippingInfo = ShippingModel::getById(['id' => $aArgs['id']]); $shippingInfo = ShippingTemplateModel::getById(['id' => $aArgs['id']]);
} }
if (empty($shippingInfo)) { if (empty($shippingInfo)) {
$errors[] = 'Shipping does not exist'; $errors[] = 'Shipping does not exist';
......
...@@ -8,14 +8,14 @@ ...@@ -8,14 +8,14 @@
*/ */
/** /**
* @brief Shipping Model * @brief Shipping Template Model
* @author dev@maarch.org * @author dev@maarch.org
* @ingroup core * @ingroup core
*/ */
namespace Shipping\models; namespace Shipping\models;
class ShippingModel extends ShippingModelAbstract class ShippingTemplateModel extends ShippingTemplateModelAbstract
{ {
// Do your stuff in this class // Do your stuff in this class
} }
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
*/ */
/** /**
* @brief Shipping Model Abstract * @brief Shipping Template Model Abstract
* @author dev@maarch.org * @author dev@maarch.org
*/ */
...@@ -17,7 +17,7 @@ namespace Shipping\models; ...@@ -17,7 +17,7 @@ namespace Shipping\models;
use SrcCore\models\ValidatorModel; use SrcCore\models\ValidatorModel;
use SrcCore\models\DatabaseModel; use SrcCore\models\DatabaseModel;
abstract class ShippingModelAbstract abstract class ShippingTemplateModelAbstract
{ {
public static function get(array $aArgs = []) public static function get(array $aArgs = [])
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment