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"
|
2020-08-22 14:26:48 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
type ServiceExecutor interface {
|
|
|
|
Balance(context.Context, *accounting.BalanceRequestBody) (*accounting.BalanceResponseBody, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
type executorSvc struct {
|
|
|
|
exec ServiceExecutor
|
|
|
|
}
|
|
|
|
|
|
|
|
// NewExecutionService wraps ServiceExecutor and returns Accounting Service interface.
|
2021-03-15 10:53:08 +00:00
|
|
|
func NewExecutionService(exec ServiceExecutor) Server {
|
2020-08-22 14:26:48 +00:00
|
|
|
return &executorSvc{
|
2020-10-22 11:12:35 +00:00
|
|
|
exec: exec,
|
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)
|
|
|
|
|
|
|
|
return resp, nil
|
|
|
|
}
|