Continued working on category controller [skip ci]

This commit is contained in:
James Cole
2014-07-30 14:45:46 +02:00
parent 04a9ada682
commit 00a767cfc9
22 changed files with 619 additions and 36 deletions

View File

@@ -40,7 +40,7 @@ interface BudgetRepositoryInterface
*
* @return mixed
*/
public function destroy($data);
public function destroy($budgetId);
/**
* @param $budgetId

View File

@@ -14,6 +14,7 @@ interface CategoryRepositoryInterface
* @return mixed
*/
public function get();
public function find($categoryId);
/**
* @param $name
@@ -30,10 +31,19 @@ interface CategoryRepositoryInterface
public function findByName($name);
/**
* @param $name
* @param $data
*
* @return mixed
*/
public function store($name);
public function store($data);
public function update($data);
/**
* @param $data
*
* @return mixed
*/
public function destroy($categoryId);
}

View File

@@ -14,7 +14,12 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
*/
public function get()
{
return \Auth::user()->categories()->orderBy('name','ASC')->get();
return \Auth::user()->categories()->orderBy('name', 'ASC')->get();
}
public function find($categoryId)
{
return \Auth::user()->categories()->find($categoryId);
}
/**
@@ -26,7 +31,7 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
{
$category = $this->findByName($name);
if (!$category) {
return $this->store($name);
return $this->store(['name' => $name]);
}
return $category;
@@ -54,14 +59,39 @@ class EloquentCategoryRepository implements CategoryRepositoryInterface
*
* @return \Category|mixed
*/
public function store($name)
public function store($data)
{
$category = new \Category();
$category->name = $name;
$category = new \Category;
$category->name = $data['name'];
$category->user()->associate(\Auth::user());
$category->save();
return $category;
}
public function update($data)
{
$category = $this->find($data['id']);
if ($category) {
// update account accordingly:
$category->name = $data['name'];
if ($category->validate()) {
$category->save();
}
}
return $category;
}
public function destroy($categoryId)
{
$category = $this->find($categoryId);
if ($category) {
$category->delete();
return true;
}
return false;
}
}

View File

@@ -27,6 +27,8 @@ class StorageServiceProvider extends ServiceProvider
);
$this->app->bind(
'Firefly\Storage\Account\AccountRepositoryInterface',
'Firefly\Storage\Account\EloquentAccountRepository'