From da49821948f382c175fd5f5701d1fd539fda4bd1 Mon Sep 17 00:00:00 2001 From: Brecci Date: Thu, 5 Dec 2024 23:54:47 -0300 Subject: [PATCH] refactor(asset-rate): add code validation to the get all asset rates by asset codes endpoint :hammer: --- .../services/query/get-all-assetrates-assetcode.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/components/transaction/internal/services/query/get-all-assetrates-assetcode.go b/components/transaction/internal/services/query/get-all-assetrates-assetcode.go index 6270f8bd..42b7209d 100644 --- a/components/transaction/internal/services/query/get-all-assetrates-assetcode.go +++ b/components/transaction/internal/services/query/get-all-assetrates-assetcode.go @@ -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)