зеркало из https://github.com/nextcloud/cookbook.git
Fixes dailyDozen part of issue #1
This commit is contained in:
Родитель
46f906ba12
Коммит
cae094c903
|
@ -17,6 +17,7 @@ return [
|
|||
['name' => 'recipe#add', 'url' => '/add', 'verb' => 'POST'],
|
||||
['name' => 'recipe#delete', 'url' => '/delete', 'verb' => 'DELETE'],
|
||||
['name' => 'recipe#update', 'url' => '/update', 'verb' => 'POST'],
|
||||
['name' => 'recipe#get', 'url' => '/get', 'verb' => 'GET'],
|
||||
['name' => 'recipe#keywords', 'url' => '/keywords', 'verb' => 'GET'],
|
||||
['name' => 'recipe#find', 'url' => '/find', 'verb' => 'GET'],
|
||||
['name' => 'recipe#test', 'url' => '/test', 'verb' => 'GET'],
|
||||
|
|
|
@ -13,26 +13,26 @@ use OCP\AppFramework\Controller;
|
|||
use OCA\Cookbook\Service\RecipeService;
|
||||
|
||||
class PageController extends Controller {
|
||||
private $userId;
|
||||
private $userId;
|
||||
private $service;
|
||||
|
||||
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, $UserId, IConfig $config){
|
||||
parent::__construct($AppName, $request);
|
||||
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, $UserId, IConfig $config){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
|
||||
$this->service = new RecipeService($root, $UserId, $db, $config);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* CAUTION: the @Stuff turns off security checks; for this page no admin is
|
||||
* required and no CSRF check. If you don't know what CSRF is, read
|
||||
* it up in the docs or you might create a security hole. This is
|
||||
* basically the only required method to add this exemption, don't
|
||||
* add it to any other method if you don't exactly know what it does
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
/**
|
||||
* CAUTION: the @Stuff turns off security checks; for this page no admin is
|
||||
* required and no CSRF check. If you don't know what CSRF is, read
|
||||
* it up in the docs or you might create a security hole. This is
|
||||
* basically the only required method to add this exemption, don't
|
||||
* add it to any other method if you don't exactly know what it does
|
||||
*
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function index() {
|
||||
$view_data = [
|
||||
'all_recipes' => $this->service->getAllRecipesInSearchIndex(),
|
||||
|
@ -43,11 +43,11 @@ class PageController extends Controller {
|
|||
|
||||
return new TemplateResponse('cookbook', 'index', $view_data); // templates/index.php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function recipe() {
|
||||
if(!isset($_GET['id'])) {
|
||||
return new DataResponse('Paramater "id" is required', 400);
|
||||
|
@ -63,11 +63,11 @@ class PageController extends Controller {
|
|||
return new DataResponse($e->getMessage(), 502);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function edit() {
|
||||
if(!isset($_GET['id'])) {
|
||||
return new DataResponse('Paramater "id" is required', 400);
|
||||
|
@ -83,11 +83,11 @@ class PageController extends Controller {
|
|||
return new DataResponse($e->getMessage(), 502);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function recipes() {
|
||||
$view_data = [
|
||||
'recipes' => $this->service->findRecipesInSearchIndex(isset($_GET['keywords']) ? $_GET['keywords'] : '')
|
||||
|
|
|
@ -14,17 +14,17 @@ use OCP\AppFramework\Controller;
|
|||
use OCA\Cookbook\Service\RecipeService;
|
||||
|
||||
class RecipeController extends Controller {
|
||||
private $userId;
|
||||
private $userId;
|
||||
|
||||
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, IConfig $config, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
public function __construct($AppName, IDBConnection $db, IRootFolder $root, IRequest $request, IConfig $config, $UserId){
|
||||
parent::__construct($AppName, $request);
|
||||
$this->userId = $UserId;
|
||||
|
||||
$this->service = new RecipeService($root, $UserId, $db, $config);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function all() {
|
||||
|
@ -32,17 +32,17 @@ class RecipeController extends Controller {
|
|||
|
||||
return new DataResponse($data, Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function test() {
|
||||
return new DataResponse('OK', Http::STATUS_OK);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function keywords() {
|
||||
|
@ -52,7 +52,7 @@ class RecipeController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function config() {
|
||||
|
@ -60,12 +60,12 @@ class RecipeController extends Controller {
|
|||
$this->service->setUserFolderPath($_POST['folder']);
|
||||
$this->service->rebuildSearchIndex();
|
||||
}
|
||||
|
||||
|
||||
return new DataResponse('OK', Http::STATUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function find() {
|
||||
|
@ -73,9 +73,9 @@ class RecipeController extends Controller {
|
|||
|
||||
return new DataResponse($data, Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function add() {
|
||||
|
@ -89,21 +89,33 @@ class RecipeController extends Controller {
|
|||
return new DataResponse($e->getMessage(), 502);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function get() {
|
||||
$id = $_GET['id'];
|
||||
|
||||
$json = $this->service->getRecipeById($id);
|
||||
|
||||
return new DataResponse($json, Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function update() {
|
||||
$json = $_POST;
|
||||
|
||||
$this->service->addRecipe($json);
|
||||
$file = $this->service->addRecipe($json);
|
||||
|
||||
return new DataResponse($json, Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
|
||||
return new DataResponse($file->getContent(), Http::STATUS_OK, [ 'Content-Type' => 'application/json' ]);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function delete() {
|
||||
|
@ -118,17 +130,17 @@ class RecipeController extends Controller {
|
|||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function reindex() {
|
||||
$this->service->rebuildSearchIndex();
|
||||
|
||||
|
||||
return new DataResponse('Search index rebuilt successfully', Http::STATUS_OK);
|
||||
}
|
||||
|
||||
/**
|
||||
* @NoAdminRequired
|
||||
* @NoAdminRequired
|
||||
* @NoCSRFRequired
|
||||
*/
|
||||
public function image() {
|
||||
|
@ -145,6 +157,6 @@ class RecipeController extends Controller {
|
|||
} catch(\Exception $e) {
|
||||
return new DataResponse($e->getMessage(), Http::STATUS_NOT_FOUND);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -59,7 +59,7 @@ class RecipeService {
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
private function checkRecipe($json) {
|
||||
public function checkRecipe($json) {
|
||||
if(!$json) { throw new \Exception('Recipe array was null'); }
|
||||
if(!isset($json['name']) || !$json['name']) { throw new \Exception('Field "name" is required'); }
|
||||
|
||||
|
@ -73,14 +73,18 @@ class RecipeService {
|
|||
// Make sure that "dailyDozen" is a comma-separated string
|
||||
if(isset($json['dailyDozen'])) {
|
||||
if(is_array($json['dailyDozen'])) {
|
||||
$json['dailyDozen'] = implode(',', array_keys($json['dailyDozen']));
|
||||
if(!isset($json['dailyDozen'][0])) {
|
||||
$json['dailyDozen'] = array_keys($json['dailyDozen']);
|
||||
}
|
||||
|
||||
$json['dailyDozen'] = implode(',', $json['dailyDozen']);
|
||||
} else if(!is_string($json['dailyDozen'])) {
|
||||
$json['dailyDozen'] = [];
|
||||
$json['dailyDozen'] = '';
|
||||
} else {
|
||||
$json['dailyDozen'] = str_replace('/[^a-zA-Z,]/', '');
|
||||
$json['dailyDozen'] = preg_replace('/[^a-zA-Z,]/', '', $json['dailyDozen']);
|
||||
}
|
||||
} else {
|
||||
$json['dailyDozen'] = [];
|
||||
$json['dailyDozen'] = '';
|
||||
}
|
||||
|
||||
// Make sure that "image" is a string of the highest resolution image available
|
||||
|
@ -151,7 +155,7 @@ class RecipeService {
|
|||
$json['recipeIngredient'] = [];
|
||||
}
|
||||
|
||||
$json['recipeIngredients'] = array_filter($json['recipeIngredients']);
|
||||
$json['recipeIngredient'] = array_filter($json['recipeIngredient']);
|
||||
|
||||
// Make sure that "recipeInstructions" is an array of strings
|
||||
if(isset($json['recipeInstructions'])) {
|
||||
|
@ -359,7 +363,7 @@ class RecipeService {
|
|||
if(!$json || !isset($json['name']) || !$json['name']) { throw new \Exception('Recipe name not found'); }
|
||||
|
||||
$json = $this->checkRecipe($json);
|
||||
|
||||
|
||||
$folder = $this->getFolderForUser();
|
||||
$file = null;
|
||||
$filename = $json['name'] . '.json';
|
||||
|
|
|
@ -39,6 +39,8 @@
|
|||
<fieldset>
|
||||
<label>Daily dozen</label>
|
||||
|
||||
<?php echo 'DUDE: ' . $_['dailyDozen']; ?>
|
||||
|
||||
<ul>
|
||||
<?php foreach($daily_dozen as $id => $ingredient) { ?>
|
||||
<?php $has_ingredient = strpos($_['dailyDozen'], $id) !== false; ?>
|
||||
|
|
Загрузка…
Ссылка в новой задаче