diff --git a/native/swift/Example/Example/ExampleApp.swift b/native/swift/Example/Example/ExampleApp.swift index 7bc51d1ce..a2a6136af 100644 --- a/native/swift/Example/Example/ExampleApp.swift +++ b/native/swift/Example/Example/ExampleApp.swift @@ -4,6 +4,7 @@ import Combine private let userListParams = UserListParams(perPage: 5) private let postListParams = PostListParams(perPage: 5) +private let mediaListParams = MediaListParams(perPage: 5) @main struct ExampleApp: App { @@ -35,6 +36,10 @@ struct ExampleApp: App { let sequence = try WordPressAPI.globalInstance.posts.sequenceWithEditContext(params: postListParams) return ListViewSequence(underlyingSequence: sequence) }), + RootListData(name: "Media", sequence: { + let sequence = try WordPressAPI.globalInstance.media.sequenceWithEditContext(params: mediaListParams) + return ListViewSequence(underlyingSequence: sequence) + }), RootListData(name: "Site Health Tests", callback: { let items: [any ListViewDataConvertable] = [ try await WordPressAPI.globalInstance.siteHealthTests.authorizationHeader().data, diff --git a/native/swift/Example/Example/ListViewData.swift b/native/swift/Example/Example/ListViewData.swift index 63112ea40..75a3ab74d 100644 --- a/native/swift/Example/Example/ListViewData.swift +++ b/native/swift/Example/Example/ListViewData.swift @@ -157,12 +157,28 @@ extension PostWithEditContext: ListViewDataConvertable { } } +extension MediaWithEditContext: @retroactive Identifiable, ListViewDataConvertable { + public var id: String { + self.slug + } + + var asListViewData: ListViewData { + ListViewData(id: self.id, title: self.title.raw, subtitle: String(describing: self.mediaDetails), fields: [:]) + } +} + extension [PostWithEditContext] { func asListViewData() -> [ListViewData] { self.map { $0.asListViewData } } } +extension [MediaWithEditContext] { + func asListViewData() -> [ListViewData] { + self.map { $0.asListViewData } + } +} + extension [ListViewDataConvertable] { func asListViewData() -> [ListViewData] { self.map { $0.asListViewData } diff --git a/native/swift/Sources/wordpress-api/Exports.swift b/native/swift/Sources/wordpress-api/Exports.swift index 36ceb1610..ef2ede586 100644 --- a/native/swift/Sources/wordpress-api/Exports.swift +++ b/native/swift/Sources/wordpress-api/Exports.swift @@ -88,6 +88,18 @@ public typealias PostsRequestListWithEditContextResponse = WordPressAPIInternal. public typealias PostsRequestListWithViewContextResponse = WordPressAPIInternal.PostsRequestListWithViewContextResponse public typealias PostsRequestListWithEmbedContextResponse = WordPressAPIInternal.PostsRequestListWithEmbedContextResponse +// MARK: - Media +public typealias SparseMedia = WordPressAPIInternal.SparseMedia +public typealias MediaWithEditContext = WordPressAPIInternal.MediaWithEditContext +public typealias MediaWithViewContext = WordPressAPIInternal.MediaWithViewContext +public typealias MediaWithEmbedContext = WordPressAPIInternal.MediaWithEmbedContext +public typealias MediaListParams = WordPressAPIInternal.MediaListParams +public typealias MediaRequestExecutor = WordPressAPIInternal.MediaRequestExecutor + +public typealias MediaRequestListWithEditContextResponse = WordPressAPIInternal.MediaRequestListWithEditContextResponse +public typealias MediaRequestListWithViewContextResponse = WordPressAPIInternal.MediaRequestListWithViewContextResponse +public typealias MediaRequestListWithEmbedContextResponse = WordPressAPIInternal.MediaRequestListWithEmbedContextResponse + // MARK: – Site Settings public typealias SparseSiteSettings = WordPressAPIInternal.SparseSiteSettings public typealias SiteSettingsWithEditContext = WordPressAPIInternal.SiteSettingsWithEditContext diff --git a/native/swift/Sources/wordpress-api/Pagination.swift b/native/swift/Sources/wordpress-api/Pagination.swift index a7b6dec5c..6e9c4ea6c 100644 --- a/native/swift/Sources/wordpress-api/Pagination.swift +++ b/native/swift/Sources/wordpress-api/Pagination.swift @@ -204,6 +204,28 @@ extension PostsRequestExecutor: PaginationAwareExecutor { public typealias EmbedContextResponseType = PostsRequestListWithEmbedContextResponse } +// MARK: - Media +extension MediaRequestListWithEditContextResponse: PaginatableResponse, @unchecked Sendable { + public typealias ParamsType = MediaListParams + public typealias DataType = MediaWithEditContext +} + +extension MediaRequestListWithViewContextResponse: PaginatableResponse, @unchecked Sendable { + public typealias ParamsType = MediaListParams + public typealias DataType = MediaWithViewContext +} + +extension MediaRequestListWithEmbedContextResponse: PaginatableResponse, @unchecked Sendable { + public typealias ParamsType = MediaListParams + public typealias DataType = MediaWithEmbedContext +} + +extension MediaRequestExecutor: PaginationAwareExecutor { + public typealias EditContextResponseType = MediaRequestListWithEditContextResponse + public typealias ViewContextResponseType = MediaRequestListWithViewContextResponse + public typealias EmbedContextResponseType = MediaRequestListWithEmbedContextResponse +} + // MARK: - Users extension UsersRequestListWithEditContextResponse: PaginatableResponse, @unchecked Sendable { public typealias ParamsType = UserListParams diff --git a/native/swift/Sources/wordpress-api/WordPressAPI.swift b/native/swift/Sources/wordpress-api/WordPressAPI.swift index b45a8d50f..080c54df2 100644 --- a/native/swift/Sources/wordpress-api/WordPressAPI.swift +++ b/native/swift/Sources/wordpress-api/WordPressAPI.swift @@ -63,6 +63,10 @@ public struct WordPressAPI { self.requestBuilder.posts() } + public var media: MediaRequestExecutor { + self.requestBuilder.media() + } + public var siteSettings: SiteSettingsRequestExecutor { self.requestBuilder.siteSettings() } diff --git a/native/swift/Tests/wordpress-api/SendableTests.swift b/native/swift/Tests/wordpress-api/SendableTests.swift index 82c41eac1..9d9229f89 100644 --- a/native/swift/Tests/wordpress-api/SendableTests.swift +++ b/native/swift/Tests/wordpress-api/SendableTests.swift @@ -4,6 +4,10 @@ import WordPressAPI struct SendableTests { private static let sendables: [Sendable] = [ + MediaRequestListWithEditContextResponse.empty, + MediaRequestListWithViewContextResponse.empty, + MediaRequestListWithEmbedContextResponse.empty, + PostsRequestListWithEditContextResponse.empty, PostsRequestListWithViewContextResponse.empty, PostsRequestListWithEmbedContextResponse.empty,