mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-12 15:35:15 +00:00
Stuff for categories.
This commit is contained in:
61
app/Repositories/Category/CategoryRepository.php
Normal file
61
app/Repositories/Category/CategoryRepository.php
Normal file
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
|
||||
use FireflyIII\Models\Category;
|
||||
|
||||
/**
|
||||
* Class CategoryRepository
|
||||
*
|
||||
* @package FireflyIII\Repositories\Category
|
||||
*/
|
||||
class CategoryRepository implements CategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function destroy(Category $category)
|
||||
{
|
||||
$category->delete();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
$newCategory = new Category(
|
||||
[
|
||||
'user_id' => $data['user'],
|
||||
'name' => $data['name'],
|
||||
]
|
||||
);
|
||||
$newCategory->save();
|
||||
|
||||
return $newCategory;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function update(Category $category, array $data)
|
||||
{
|
||||
// update the account:
|
||||
$category->name = $data['name'];
|
||||
$category->save();
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
}
|
34
app/Repositories/Category/CategoryRepositoryInterface.php
Normal file
34
app/Repositories/Category/CategoryRepositoryInterface.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace FireflyIII\Repositories\Category;
|
||||
use FireflyIII\Models\Category;
|
||||
/**
|
||||
* Interface CategoryRepositoryInterface
|
||||
*
|
||||
* @package FireflyIII\Repositories\Category
|
||||
*/
|
||||
interface CategoryRepositoryInterface
|
||||
{
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
* @return boolean
|
||||
*/
|
||||
public function destroy(Category $category);
|
||||
|
||||
/**
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function store(array $data);
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
* @param array $data
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function update(Category $category, array $data);
|
||||
|
||||
}
|
Reference in New Issue
Block a user