idempotency key usage fix
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"github.com/tech/sendico/ledger/storage"
|
||||
"github.com/tech/sendico/pkg/api/routers/gsresponse"
|
||||
"github.com/tech/sendico/pkg/merrors"
|
||||
"github.com/tech/sendico/pkg/mutil/mzap"
|
||||
moneyv1 "github.com/tech/sendico/pkg/proto/common/money/v1"
|
||||
ledgerv1 "github.com/tech/sendico/pkg/proto/ledger/v1"
|
||||
"go.uber.org/zap"
|
||||
@@ -27,6 +28,7 @@ func (s *Service) getBalanceResponder(_ context.Context, req *ledgerv1.GetBalanc
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger := s.logger.With(mzap.ObjRef("ledger_account_ref", accountRef))
|
||||
|
||||
// Get account to verify it exists
|
||||
account, err := s.storage.Accounts().Get(ctx, accountRef)
|
||||
@@ -34,7 +36,7 @@ func (s *Service) getBalanceResponder(_ context.Context, req *ledgerv1.GetBalanc
|
||||
if err == storage.ErrAccountNotFound {
|
||||
return nil, merrors.NoData("account not found")
|
||||
}
|
||||
s.logger.Warn("failed to get account", zap.Error(err))
|
||||
logger.Warn("failed to get account", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to get account")
|
||||
}
|
||||
|
||||
@@ -53,7 +55,7 @@ func (s *Service) getBalanceResponder(_ context.Context, req *ledgerv1.GetBalanc
|
||||
LastUpdated: timestamppb.Now(),
|
||||
}, nil
|
||||
}
|
||||
s.logger.Warn("failed to get balance", zap.Error(err))
|
||||
logger.Warn("failed to get balance", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to get balance")
|
||||
}
|
||||
|
||||
@@ -82,6 +84,7 @@ func (s *Service) getJournalEntryResponder(_ context.Context, req *ledgerv1.GetE
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger := s.logger.With(mzap.ObjRef("entry_ref", entryRef))
|
||||
|
||||
// Get journal entry
|
||||
entry, err := s.storage.JournalEntries().Get(ctx, entryRef)
|
||||
@@ -89,14 +92,14 @@ func (s *Service) getJournalEntryResponder(_ context.Context, req *ledgerv1.GetE
|
||||
if err == storage.ErrJournalEntryNotFound {
|
||||
return nil, merrors.NoData("journal entry not found")
|
||||
}
|
||||
s.logger.Warn("failed to get journal entry", zap.Error(err))
|
||||
logger.Warn("failed to get journal entry", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to get journal entry")
|
||||
}
|
||||
|
||||
// Get posting lines for this entry
|
||||
lines, err := s.storage.PostingLines().ListByJournalEntry(ctx, entryRef)
|
||||
if err != nil {
|
||||
s.logger.Warn("failed to get posting lines", zap.Error(err))
|
||||
logger.Warn("failed to get posting lines", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to get posting lines")
|
||||
}
|
||||
|
||||
@@ -140,6 +143,7 @@ func (s *Service) getStatementResponder(_ context.Context, req *ledgerv1.GetStat
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
logger := s.logger.With(mzap.ObjRef("ledger_account_ref", accountRef))
|
||||
|
||||
// Verify account exists
|
||||
_, err = s.storage.Accounts().Get(ctx, accountRef)
|
||||
@@ -147,7 +151,7 @@ func (s *Service) getStatementResponder(_ context.Context, req *ledgerv1.GetStat
|
||||
if err == storage.ErrAccountNotFound {
|
||||
return nil, merrors.NoData("account not found")
|
||||
}
|
||||
s.logger.Warn("failed to get account", zap.Error(err))
|
||||
logger.Warn("failed to get account", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to get account")
|
||||
}
|
||||
|
||||
@@ -167,11 +171,12 @@ func (s *Service) getStatementResponder(_ context.Context, req *ledgerv1.GetStat
|
||||
return nil, merrors.InvalidArgument(fmt.Sprintf("invalid cursor: %v", err))
|
||||
}
|
||||
}
|
||||
logger = logger.With(zap.Int("limit", limit), zap.Int("offset", offset))
|
||||
|
||||
// Get posting lines for account
|
||||
postingLines, err := s.storage.PostingLines().ListByAccount(ctx, accountRef, limit+1, offset)
|
||||
if err != nil {
|
||||
s.logger.Warn("failed to get posting lines", zap.Error(err))
|
||||
logger.Warn("failed to get posting lines", zap.Error(err))
|
||||
return nil, merrors.Internal("failed to get posting lines")
|
||||
}
|
||||
|
||||
@@ -189,18 +194,22 @@ func (s *Service) getStatementResponder(_ context.Context, req *ledgerv1.GetStat
|
||||
|
||||
entries := make([]*ledgerv1.JournalEntryResponse, 0)
|
||||
for entryRefHex := range entryMap {
|
||||
entryRef, _ := parseObjectID(entryRefHex)
|
||||
entryRef, err := parseObjectID(entryRefHex)
|
||||
if err != nil {
|
||||
s.logger.Warn("invalid journal entry ref in posting lines", zap.String("entry_ref", entryRefHex), zap.Error(err))
|
||||
return nil, err
|
||||
}
|
||||
|
||||
entry, err := s.storage.JournalEntries().Get(ctx, entryRef)
|
||||
if err != nil {
|
||||
s.logger.Warn("failed to get journal entry for statement", zap.Error(err), zap.String("entryRef", entryRefHex))
|
||||
logger.Warn("failed to get journal entry for statement", zap.Error(err), zap.String("entry_ref", entryRefHex))
|
||||
continue
|
||||
}
|
||||
|
||||
// Get all lines for this entry
|
||||
lines, err := s.storage.PostingLines().ListByJournalEntry(ctx, entryRef)
|
||||
if err != nil {
|
||||
s.logger.Warn("failed to get posting lines for entry", zap.Error(err), zap.String("entryRef", entryRefHex))
|
||||
logger.Warn("failed to get posting lines for entry", zap.Error(err), zap.String("entry_ref", entryRefHex))
|
||||
continue
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user