Skip to content

Commit

Permalink
refactor(asset-rate): add code validation to the get all asset rates …
Browse files Browse the repository at this point in the history
…by asset codes endpoint 🔨
  • Loading branch information
qnen committed Dec 6, 2024
1 parent 2fdc51e commit da49821
Showing 1 changed file with 14 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,20 @@ func (uc *UseCase) GetAllAssetRatesByAssetCode(ctx context.Context, organization

logger.Infof("Trying to get asset rate by source asset code: %s and target asset codes: %v", fromAssetCode, filter.ToAssetCodes)

if err := pkg.ValidateCode(fromAssetCode); err != nil {
mopentelemetry.HandleSpanError(&span, "Failed to validate 'from' asset code", err)

return nil, pkg.ValidateBusinessError(err, reflect.TypeOf(assetrate.AssetRate{}).Name())
}

for _, toAssetCode := range filter.ToAssetCodes {
if err := pkg.ValidateCode(toAssetCode); err != nil {
mopentelemetry.HandleSpanError(&span, "Failed to validate 'to' asset codes", err)

return nil, pkg.ValidateBusinessError(err, reflect.TypeOf(assetrate.AssetRate{}).Name())
}
}

assetRates, err := uc.AssetRateRepo.FindAllByAssetCodes(ctx, organizationID, ledgerID, fromAssetCode, filter.ToAssetCodes, filter.Limit, filter.Page)
if err != nil {
mopentelemetry.HandleSpanError(&span, "Failed to get asset rate by asset codes on repository", err)
Expand Down

0 comments on commit da49821

Please sign in to comment.