Skip to content

Commit 9914318

Browse files
committed
Add a method to get prompts for the Prompts List.
1 parent 29abef6 commit 9914318

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

WordPress/Classes/Services/BloggingPromptsService.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ class BloggingPromptsService {
4747
}, failure: failure)
4848
}
4949

50+
/// Convenience method to fetch the blogging prompts for the Prompts List.
51+
/// Fetches 11 prompts - the current day and 10 previous.
52+
///
53+
/// - Parameters:
54+
/// - success: Closure to be called when the fetch process succeeded.
55+
/// - failure: Closure to be called when the fetch process failed.
56+
func fetchListPrompts(success: @escaping ([BloggingPrompt]) -> Void,
57+
failure: @escaping (Error?) -> Void) {
58+
let fromDate = calendar.date(byAdding: .day, value: -9, to: Date()) ?? Date()
59+
fetchPrompts(from: fromDate, number: 11, success: success, failure: failure)
60+
}
61+
5062
required init?(context: NSManagedObjectContext = ContextManager.shared.mainContext,
5163
remote: BloggingPromptsServiceRemote? = nil,
5264
blog: Blog? = nil) {

WordPress/Classes/ViewRelated/Blog/Blogging Prompts/BloggingPromptsViewController.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ private extension BloggingPromptsViewController {
116116

117117
isLoading = true
118118

119-
bloggingPromptsService.fetchPrompts(success: { [weak self] (prompts) in
119+
bloggingPromptsService.fetchListPrompts(success: { [weak self] (prompts) in
120120
self?.isLoading = false
121121
self?.prompts = prompts.sorted(by: { $0.date.compare($1.date) == .orderedDescending })
122122
}, failure: { [weak self] (error) in

0 commit comments

Comments
 (0)