mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-09-29 18:20:01 +00:00
Continued working on category controller [skip ci]
This commit is contained in:
@@ -40,7 +40,7 @@ interface BudgetRepositoryInterface
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function destroy($data);
|
||||
public function destroy($budgetId);
|
||||
|
||||
/**
|
||||
* @param $budgetId
|
||||
|
@@ -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);
|
||||
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
@@ -27,6 +27,8 @@ class StorageServiceProvider extends ServiceProvider
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$this->app->bind(
|
||||
'Firefly\Storage\Account\AccountRepositoryInterface',
|
||||
'Firefly\Storage\Account\EloquentAccountRepository'
|
||||
|
Reference in New Issue
Block a user