Skip to content

Commit

Permalink
refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
ytake committed Apr 5, 2015
1 parent 2567d8e commit 1e10700
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
4 changes: 3 additions & 1 deletion app/Exceptions/RecipeNotFoundException.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<?php
namespace App\Exceptions;

use Symfony\Component\HttpKernel\Exception\HttpException;

/**
* Class RecipeNotFoundException
* @package App\Exceptions
* @author yuuki.takezawa<yuuki.takezawa@comnect.jp.net>
*/
class RecipeNotFoundException extends \Exception
class RecipeNotFoundException extends HttpException
{

}
7 changes: 6 additions & 1 deletion app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,15 @@ public function recipe($recipeId = null)
* @Get("category/{categoryId}",as="home.category")
* @param $categoryId
* @return \Illuminate\View\View
* @throws \App\Exceptions\RecipeNotFoundException
*/
public function category($categoryId)
{
$categories = $this->service->getCategories($categoryId);
try {
$categories = $this->service->getCategories($categoryId);
} catch(\App\Exceptions\RecipeNotFoundException $e) {
throw $e;
}
$this->title($categories['category']->description);
$this->description($categories['category']->description);
return view('home.category.index', $categories);
Expand Down
4 changes: 4 additions & 0 deletions app/Services/RecipeService.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,14 @@ public function getRecipe($recipeId)
/**
* @param $categoryId
* @return array
* @throws RecipeNotFoundException
*/
public function getCategories($categoryId)
{
$category = $this->category->getCategory($categoryId);
if(!$category) {
throw new RecipeNotFoundException(404);
}
return [
'category' => $category,
'list' => $this->recipe->getRecipesFromCategory($categoryId)
Expand Down

0 comments on commit 1e10700

Please sign in to comment.