ClearBowl/api/app/Http/Controllers/RecipesController.php

44 lines
1.2 KiB
PHP
Raw Normal View History

2019-12-15 15:45:22 +01:00
<?php
namespace App\Http\Controllers;
use App\Http\Requests\AddRecipeRequest;
use App\Repositories\RecipesRepositoryInterface;
use Illuminate\Http\Request;
class RecipesController extends Controller
{
private $recipesRepository;
public function __construct(RecipesRepositoryInterface $recipesRepository)
{
$this->recipesRepository = $recipesRepository;
}
public function add(AddRecipeRequest $request)
{
$recipe = $this->recipesRepository->create(collect($request->all()));
return response()->json(['success' => true, 'data' => ['recipe' => $recipe]], 200);
}
public function index(Request $request)
{
2019-12-15 21:09:14 +01:00
$filters = $this->getFilters($request);
$recipes = $this->recipesRepository->paginate($filters);
2019-12-15 15:45:22 +01:00
return response()->json(['success' => true, 'data' => ['recipes' => $recipes]], 200);
}
2020-01-07 20:38:23 +01:00
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);
}
2019-12-15 15:45:22 +01:00
}