diff --git a/Sources/Infrastructure/Apps/AssetLibrary/Images/SDKLibraryImageRepository.swift b/Sources/Infrastructure/Apps/AssetLibrary/Images/SDKLibraryImageRepository.swift index 1b7f1335..625b9d36 100644 --- a/Sources/Infrastructure/Apps/AssetLibrary/Images/SDKLibraryImageRepository.swift +++ b/Sources/Infrastructure/Apps/AssetLibrary/Images/SDKLibraryImageRepository.swift @@ -18,8 +18,8 @@ public struct SDKLibraryImageRepository: LibraryImageRepository, @unchecked Send category: AssetCategory? ) async throws -> [LibraryImage] { let sdk = APIEndpoint.v1.appAssetLibraries.id(libraryId).images.get(parameters: .init( - filterCategory: category.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, - filterState: state.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, + filterCategory: sdkFilter(category), + filterState: sdkFilter(state), filterID: imageId.map { [$0] }, limit: 200 )) diff --git a/Sources/Infrastructure/Apps/AssetLibrary/Placements/SDKAssetPlacementRepository.swift b/Sources/Infrastructure/Apps/AssetLibrary/Placements/SDKAssetPlacementRepository.swift index def8e357..3ace294d 100644 --- a/Sources/Infrastructure/Apps/AssetLibrary/Placements/SDKAssetPlacementRepository.swift +++ b/Sources/Infrastructure/Apps/AssetLibrary/Placements/SDKAssetPlacementRepository.swift @@ -117,25 +117,25 @@ public struct SDKAssetPlacementRepository: AssetPlacementRepository, @unchecked switch surface { case .appStoreVersionLocalization: let r = APIEndpoint.v1.appStoreVersionLocalizations.id(localizationId).placements.get(parameters: .init( - filterPlacementType: placementType.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, + filterPlacementType: sdkFilter(placementType), filterPlacementGroup: groups, sort: [.placementGroupPosition], limit: 200, include: [.image, .video] )) sdk = (r.path, r.query) case .experimentTreatmentLocalization: let r = APIEndpoint.v1.appStoreVersionExperimentTreatmentLocalizations.id(localizationId).placements.get(parameters: .init( - filterPlacementType: placementType.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, + filterPlacementType: sdkFilter(placementType), filterPlacementGroup: groups, sort: [.placementGroupPosition], limit: 200, include: [.image, .video] )) sdk = (r.path, r.query) case .customProductPageLocalization: let r = APIEndpoint.v1.appCustomProductPageLocalizations.id(localizationId).placements.get(parameters: .init( - filterPlacementType: placementType.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, + filterPlacementType: sdkFilter(placementType), filterPlacementGroup: groups, sort: [.placementGroupPosition], limit: 200, include: [.image, .video] )) sdk = (r.path, r.query) case .eventLocalization: let r = APIEndpoint.v1.appEventLocalizations.id(localizationId).placements.get(parameters: .init( - filterPlacementType: placementType.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, + filterPlacementType: sdkFilter(placementType), filterPlacementGroup: groups, sort: [.placementGroupPosition], limit: 200, include: [.image, .video] )) sdk = (r.path, r.query) diff --git a/Sources/Infrastructure/Apps/AssetLibrary/Videos/SDKLibraryVideoRepository.swift b/Sources/Infrastructure/Apps/AssetLibrary/Videos/SDKLibraryVideoRepository.swift index f8efb908..14c46bdd 100644 --- a/Sources/Infrastructure/Apps/AssetLibrary/Videos/SDKLibraryVideoRepository.swift +++ b/Sources/Infrastructure/Apps/AssetLibrary/Videos/SDKLibraryVideoRepository.swift @@ -18,8 +18,8 @@ public struct SDKLibraryVideoRepository: LibraryVideoRepository, @unchecked Send category: AssetCategory? ) async throws -> [LibraryVideo] { let sdk = APIEndpoint.v1.appAssetLibraries.id(libraryId).videos.get(parameters: .init( - filterCategory: category.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, - filterState: state.flatMap { .init(rawValue: $0.rawValue) }.map { [$0] }, + filterCategory: sdkFilter(category), + filterState: sdkFilter(state), filterID: videoId.map { [$0] }, limit: 200 )) diff --git a/Sources/Infrastructure/Shared/SDKFilter.swift b/Sources/Infrastructure/Shared/SDKFilter.swift new file mode 100644 index 00000000..70cb20fc --- /dev/null +++ b/Sources/Infrastructure/Shared/SDKFilter.swift @@ -0,0 +1,10 @@ +/// Turns an optional domain enum into the one-element SDK filter array a query parameter takes, +/// or `nil` when there is no value (or the SDK has no matching case). +/// +/// The SDK type comes from the parameter being filled. Spelled as a generic function because +/// Swift 6.2 can't infer `.init(rawValue:)` through `value.flatMap { .init(…) }.map { [$0] }`. +func sdkFilter( + _ value: DomainValue? +) -> [SDKValue]? where SDKValue.RawValue == String, DomainValue.RawValue == String { + value.flatMap { SDKValue(rawValue: $0.rawValue) }.map { [$0] } +}