mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-10-16 17:33:45 +00:00
New converters for #180 (Category and some other stuff)
This commit is contained in:
@@ -9,6 +9,7 @@ use FireflyIII\Models\Category;
|
||||
use FireflyIII\Models\TransactionJournal;
|
||||
use FireflyIII\Models\TransactionType;
|
||||
use FireflyIII\Repositories\Shared\ComponentRepository;
|
||||
use FireflyIII\User;
|
||||
use Illuminate\Support\Collection;
|
||||
|
||||
/**
|
||||
@@ -18,6 +19,19 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
class SingleCategoryRepository extends ComponentRepository implements SingleCategoryRepositoryInterface
|
||||
{
|
||||
/** @var User */
|
||||
private $user;
|
||||
|
||||
/**
|
||||
* BillRepository constructor.
|
||||
*
|
||||
* @param User $user
|
||||
*/
|
||||
public function __construct(User $user)
|
||||
{
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -87,6 +101,23 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Find a category
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function find(int $categoryId) : Category
|
||||
{
|
||||
$category = $this->user->categories()->find($categoryId);
|
||||
if (is_null($category)) {
|
||||
$category = new Category;
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -146,7 +177,6 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
->get(TransactionJournal::QUERYFIELDS);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -206,7 +236,7 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
*/
|
||||
public function store(array $data)
|
||||
{
|
||||
$newCategory = new Category(
|
||||
$newCategory = Category::firstOrCreateEncrypted(
|
||||
[
|
||||
'user_id' => $data['user'],
|
||||
'name' => $data['name'],
|
||||
@@ -231,6 +261,4 @@ class SingleCategoryRepository extends ComponentRepository implements SingleCate
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@@ -14,6 +14,7 @@ use Illuminate\Support\Collection;
|
||||
*/
|
||||
interface SingleCategoryRepositoryInterface
|
||||
{
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
*
|
||||
@@ -54,6 +55,14 @@ interface SingleCategoryRepositoryInterface
|
||||
*/
|
||||
public function earnedPerDay(Category $category, Carbon $start, Carbon $end);
|
||||
|
||||
/**
|
||||
* Find a category
|
||||
*
|
||||
* @param int $categoryId
|
||||
*
|
||||
* @return Category
|
||||
*/
|
||||
public function find(int $categoryId) : Category;
|
||||
|
||||
/**
|
||||
* @param Category $category
|
||||
|
Reference in New Issue
Block a user