Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
))
Expand Down
10 changes: 10 additions & 0 deletions Sources/Infrastructure/Shared/SDKFilter.swift
Original file line number Diff line number Diff line change
@@ -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<SDKValue: RawRepresentable, DomainValue: RawRepresentable>(
_ value: DomainValue?
) -> [SDKValue]? where SDKValue.RawValue == String, DomainValue.RawValue == String {
value.flatMap { SDKValue(rawValue: $0.rawValue) }.map { [$0] }
}
Loading