From d76d88971dfadf4628693247b4a3864664871f4f Mon Sep 17 00:00:00 2001 From: casper Date: Thu, 1 Feb 2024 21:41:48 +0100 Subject: [PATCH] feat add from limit --- example.config.yaml | 1 + internal/core/entity/config.go | 7 ++++--- internal/core/service/sync/sync.go | 13 ++++++++++++- internal/driven/ynab/ynab.go | 4 ++-- 4 files changed, 19 insertions(+), 6 deletions(-) diff --git a/example.config.yaml b/example.config.yaml index 64c1ff8..d630dad 100644 --- a/example.config.yaml +++ b/example.config.yaml @@ -4,6 +4,7 @@ accounts: - bunq_account_name: "Your bunq account name" ynab_budget_name: "Your YNAB budget name" ynab_account_name: "Your YNAB account name" + from: "2024-01-13" # optional start date - bunq_account_name: "Your bunq account name 2" ynab_budget_name: "Your YNAB budget name 2" ynab_account_name: "Your YNAB account name 2" diff --git a/internal/core/entity/config.go b/internal/core/entity/config.go index 06e7615..9014caf 100644 --- a/internal/core/entity/config.go +++ b/internal/core/entity/config.go @@ -10,7 +10,8 @@ type Config struct { // ConfigAccount is the configuration for a single account. // This is what will get synced. type ConfigAccount struct { - BunqAccountName string `yaml:"bunq_account_name"` - YnabBudgetName string `yaml:"ynab_budget_name"` - YnabAccountName string `yaml:"ynab_account_name"` + BunqAccountName string `yaml:"bunq_account_name"` + YnabBudgetName string `yaml:"ynab_budget_name"` + YnabAccountName string `yaml:"ynab_account_name"` + From *string `yaml:"from"` } diff --git a/internal/core/service/sync/sync.go b/internal/core/service/sync/sync.go index 41f473b..a2f3d08 100644 --- a/internal/core/service/sync/sync.go +++ b/internal/core/service/sync/sync.go @@ -3,11 +3,11 @@ package sync import ( "context" "fmt" + "log/slog" "time" "github.com/bad33ndj3/bunq2ynab/internal/core/entity" "github.com/pkg/errors" - "log/slog" ) type Service interface { @@ -70,6 +70,17 @@ func (c *Client) Sync(ctx context.Context, from time.Time) error { slog.Info("----------------------------------------") slog.Info("Syncing account", slog.String("account", account.BunqAccountName)) + if account.From != nil { + limitFrom, err := time.Parse(time.DateOnly, *account.From) + if err != nil { + return errors.Wrap(err, "parsing from date") + } + + if limitFrom.After(from) { + from = limitFrom + } + } + var transactions []*entity.Transaction for _, transaction := range ba.Transactions { if transaction.Date.Before(from) { diff --git a/internal/driven/ynab/ynab.go b/internal/driven/ynab/ynab.go index f3e9df6..26face2 100644 --- a/internal/driven/ynab/ynab.go +++ b/internal/driven/ynab/ynab.go @@ -107,7 +107,7 @@ func accountToDomain(account *account.Account) *entity.Account { func (c *Client) GetBudgetByName(name string) (*entity.Budget, error) { sm, err := c.yn.Budget().GetBudgets() if err != nil { - return nil, err + return nil, errors.Wrap(err, "getting budgets") } for i := range sm { @@ -116,7 +116,7 @@ func (c *Client) GetBudgetByName(name string) (*entity.Budget, error) { } } - return nil, errors.New("budget not found") + return nil, errors.Wrapf(errors.New("budget not found"), "budget name: %s", name) } func (c *Client) GetAllCategories(