-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support Post api without singleton configuration
- Loading branch information
Showing
5 changed files
with
108 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
Sources/WPSwift/Repositories/PostWithSourceRepository.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// | ||
// PostWithSourceRepository.swift | ||
// | ||
// | ||
// Created by Ulaş Sancak on 6.10.2023. | ||
// | ||
|
||
import Foundation | ||
import Resting | ||
|
||
public struct PostWithSourceRepository { | ||
public init() {} | ||
|
||
public func getPostsClient(page: Int = 1, perPage: Int = 10, order: OrderType = .descending, categories: [Int]? = nil, categoriesToExclude: [Int]? = nil, tags: [Int]? = nil, tagsToExclude: [Int]? = nil, include: [Int]? = nil) throws -> WPClient<EmptyModel, [Post]> { | ||
try .init(.init(endpoint: WPEndpoint.Posts.posts.path, parameters: .createParamsForPosts(page: page, perPage: perPage, order: order, categories: categories, categoriesToExclude: categoriesToExclude, tags: tags, tagsToExclude: tagsToExclude, include: include))) | ||
} | ||
|
||
public func getSearchPostsClient(term: String, page: Int = 1, perPage: Int = 10) throws -> WPClient<EmptyModel, [SimplePost]> { | ||
try .init(.init(endpoint: WPEndpoint.Posts.search.path, parameters: .createParamsForSearchPosts(term: term, page: page, perPage: perPage))) | ||
} | ||
|
||
public func getPostClient(by id: Int) throws -> WPClient<EmptyModel, Post> { | ||
try .init(.init(endpoint: WPEndpoint.Posts.post(id: id).path, parameters: .createParamsForPost())) | ||
} | ||
|
||
public func createPostClient(by post: PostToCreate) throws -> WPClient<PostToCreate, Post> { | ||
try .init(.init(endpoint: WPEndpoint.Posts.posts.path, method: .post, requestModel: post)) | ||
} | ||
|
||
public func updatePostClient(by id: Int, post: PostToUpdate) throws -> WPClient<PostToUpdate, Post> { | ||
try .init(.init(endpoint: WPEndpoint.Posts.post(id: id).path, method: .post, requestModel: post)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters