2020-08-22 14:26:48 +00:00
|
|
|
package accounting
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
2021-05-18 08:12:51 +00:00
|
|
|
"fmt"
|
2020-08-22 14:26:48 +00:00
|
|
|
|
2022-12-23 17:35:35 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-api-go/v2/accounting"
|
2022-12-30 14:48:50 +00:00
|
|
|
"github.com/TrueCloudLab/frostfs-node/pkg/services/util/response"
|
2020-08-22 14:26:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceExecutor interface {
|
|
|
|
Balance(context.Context, *accounting.BalanceRequestBody) (*accounting.BalanceResponseBody, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type executorSvc struct {
|
2022-12-30 14:48:50 +00:00
|
|
|
exec ServiceExecutor
|
|
|
|
respSvc *response.Service
|
2020-08-22 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Accounting Service interface.
|
2022-12-30 14:48:50 +00:00
|
|
|
func NewExecutionService(exec ServiceExecutor, respSvc *response.Service) Server {
|
2020-08-22 14:26:48 +00:00
|
|
|
return &executorSvc{
|
2022-12-30 14:48:50 +00:00
|
|
|
exec: exec,
|
|
|
|
respSvc: respSvc,
|
2020-08-22 14:26:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *executorSvc) Balance(ctx context.Context, req *accounting.BalanceRequest) (*accounting.BalanceResponse, error) {
|
|
|
|
respBody, err := s.exec.Balance(ctx, req.GetBody())
|
|
|
|
if err != nil {
|
2021-05-18 08:12:51 +00:00
|
|
|
return nil, fmt.Errorf("could not execute Balance request: %w", err)
|
2020-08-22 14:26:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
resp := new(accounting.BalanceResponse)
|
|
|
|
resp.SetBody(respBody)
|
|
|
|
|
2022-12-30 14:48:50 +00:00
|
|
|
s.respSvc.SetMeta(resp)
|
2020-08-22 14:26:48 +00:00
|
|
|
return resp, nil
|
|
|
|
}
|