New converters for #180 (Category and some other stuff)

This commit is contained in:
James Cole
2016-04-01 13:23:12 +02:00
parent 429ef80fb9
commit 5e78cc02bd
10 changed files with 78 additions and 18 deletions

View File

@@ -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;
}
}

View File

@@ -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