From b4454f7517070d1f1f3a121e5b8769df5243e974 Mon Sep 17 00:00:00 2001 From: alfred-mk Date: Thu, 24 Oct 2024 20:44:29 +0300 Subject: [PATCH] Added context to FetchVouchers --- internal/handlers/server/accountservice.go | 6 +++--- internal/handlers/ussd/menuhandler.go | 4 ++-- internal/mocks/servicemock.go | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/handlers/server/accountservice.go b/internal/handlers/server/accountservice.go index 58774ce..3e2f91d 100644 --- a/internal/handlers/server/accountservice.go +++ b/internal/handlers/server/accountservice.go @@ -25,7 +25,7 @@ type AccountServiceInterface interface { CreateAccount(ctx context.Context) (*api.OKResponse, error) CheckAccountStatus(ctx context.Context, trackingId string) (*models.TrackStatusResponse, error) TrackAccountStatus(ctx context.Context, publicKey string) (*api.OKResponse, error) - FetchVouchers(publicKey string) (*models.VoucherHoldingResponse, error) + FetchVouchers(ctx context.Context, publicKey string) (*models.VoucherHoldingResponse, error) } type AccountService struct { @@ -174,7 +174,7 @@ func (as *AccountService) CreateAccount(ctx context.Context) (*api.OKResponse, e // FetchVouchers retrieves the token holdings for a given public key from the custodial holdings API endpoint // Parameters: // - publicKey: The public key associated with the account. -func (as *AccountService) FetchVouchers(publicKey string) (*models.VoucherHoldingResponse, error) { +func (as *AccountService) FetchVouchers(ctx context.Context, publicKey string) (*models.VoucherHoldingResponse, error) { file, err := os.Open("sample_tokens.json") if err != nil { return nil, err @@ -245,7 +245,7 @@ func (tas *TestAccountService) CheckAccountStatus(ctx context.Context, trackingI return trackResponse, nil } -func (tas *TestAccountService) FetchVouchers(publicKey string) (*models.VoucherHoldingResponse, error) { +func (tas *TestAccountService) FetchVouchers(ctx context.Context, publicKey string) (*models.VoucherHoldingResponse, error) { return &models.VoucherHoldingResponse{ Ok: true, Result: struct { diff --git a/internal/handlers/ussd/menuhandler.go b/internal/handlers/ussd/menuhandler.go index ec0a5b3..f4d279b 100644 --- a/internal/handlers/ussd/menuhandler.go +++ b/internal/handlers/ussd/menuhandler.go @@ -1035,7 +1035,7 @@ func (h *Handlers) SetDefaultVoucher(ctx context.Context, sym string, input []by } // Fetch vouchers from the API using the public key - vouchersResp, err := h.accountService.FetchVouchers(string(publicKey)) + vouchersResp, err := h.accountService.FetchVouchers(ctx, string(publicKey)) if err != nil { return res, nil } @@ -1089,7 +1089,7 @@ func (h *Handlers) CheckVouchers(ctx context.Context, sym string, input []byte) } // Fetch vouchers from the API using the public key - vouchersResp, err := h.accountService.FetchVouchers(string(publicKey)) + vouchersResp, err := h.accountService.FetchVouchers(ctx, string(publicKey)) if err != nil { return res, nil } diff --git a/internal/mocks/servicemock.go b/internal/mocks/servicemock.go index 6a217ce..de0e99a 100644 --- a/internal/mocks/servicemock.go +++ b/internal/mocks/servicemock.go @@ -34,7 +34,7 @@ func (m *MockAccountService) TrackAccountStatus(ctx context.Context,publicKey st } -func (m *MockAccountService) FetchVouchers(publicKey string) (*models.VoucherHoldingResponse, error) { +func (m *MockAccountService) FetchVouchers(ctx context.Context, publicKey string) (*models.VoucherHoldingResponse, error) { args := m.Called(publicKey) return args.Get(0).(*models.VoucherHoldingResponse), args.Error(1) }