feat(expense): create and display expenses
This commit is contained in:
@@ -3,14 +3,16 @@ package expense
|
||||
import (
|
||||
"nos-comptes/internal/storage/dao"
|
||||
"nos-comptes/internal/storage/model"
|
||||
"nos-comptes/internal/utils"
|
||||
)
|
||||
|
||||
type Service struct {
|
||||
db *Database
|
||||
}
|
||||
|
||||
func (s Service) GetAllExpensesOfAnAccount(accountId string) (interface{}, interface{}) {
|
||||
func (s Service) GetAllExpensesOfAnAccount(accountId string) ([]*Expense, error) {
|
||||
expenses, err := s.db.GetAllExpensesOfAnAccount(accountId)
|
||||
utils.GetLogger().Info(err)
|
||||
if e, ok := err.(*dao.Error); ok {
|
||||
switch {
|
||||
case e.Type == dao.ErrTypeNotFound:
|
||||
@@ -28,6 +30,11 @@ func (s Service) GetAllExpensesOfAnAccount(accountId string) (interface{}, inter
|
||||
return expenses, nil
|
||||
}
|
||||
|
||||
func (s Service) CreateExpense(expense *Expense) error {
|
||||
|
||||
return s.db.CreateExpense(expense)
|
||||
}
|
||||
|
||||
func NewService(database *Database) *Service {
|
||||
return &Service{db: database}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user