Retrieving single recipe

This commit is contained in:
Artur Nowakowski 2020-01-07 20:38:23 +01:00
parent 11471894f7
commit 892e42ba33
3 changed files with 13 additions and 0 deletions

View File

@ -29,4 +29,15 @@ class RecipesController extends Controller
return response()->json(['success' => true, 'data' => ['recipes' => $recipes]], 200);
}
public function get(int $id)
{
$recipe = $this->recipesRepository->get($id);
if(empty($recipe['name'])){
return response()->json(['success' => true, 'error' => 'Recipe not found'], 404);
}
return response()->json(['success' => true, 'data' => ['recipe' => $recipe]], 200);
}
}

View File

@ -9,4 +9,5 @@ interface RecipesRepositoryInterface
{
public function create(Collection $data);
public function paginate(array $filters);
public function get(int $id);
}

View File

@ -17,6 +17,7 @@ Route::prefix('product')->group(function () {
Route::prefix('recipe')->group(function () {
Route::post('/', 'RecipesController@add')->middleware(['jwt.auth']);
Route::get('/', 'RecipesController@index');
Route::get('/{id}', 'RecipesController@get');
});
Route::post('calculate', 'ProductsController@calculate');