feat(expense): create and display expenses

This commit is contained in:
2021-11-26 01:51:13 +01:00
parent 82d86fb33f
commit 53b0b8c9a2
6 changed files with 71 additions and 24 deletions

View File

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