-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Jiaqi Feng <jiaqi.feng@transcarent.com>
- Loading branch information
1 parent
9cf6ef1
commit 3757ba4
Showing
41 changed files
with
487 additions
and
222 deletions.
There are no files selected for viewing
63 changes: 44 additions & 19 deletions
63
Packages/HackerNewsKit/Sources/HackerNewsKit/Models/SearchFilter.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 |
---|---|---|
@@ -1,23 +1,48 @@ | ||
public protocol SearchFilter: Equatable { | ||
var query: String { get } | ||
} | ||
|
||
public class StoryFilter: SearchFilter { | ||
public let query: String = "story" | ||
import Foundation | ||
|
||
public static func == (lhs: StoryFilter, rhs: StoryFilter) -> Bool { | ||
lhs.query == rhs.query | ||
public enum SearchFilter: Equatable, Hashable { | ||
case story | ||
case comment | ||
case dateRange(Date, Date) | ||
|
||
var query: String { | ||
switch(self){ | ||
case .story: | ||
return "story" | ||
case .comment: | ||
return "comment" | ||
case .dateRange(let startDate, let endDate): | ||
let startTimestamp = Int(startDate.timeIntervalSince1970.rounded()) | ||
let endTimestamp = Int(endDate.timeIntervalSince1970.rounded()) | ||
|
||
if startTimestamp != endTimestamp { | ||
return "created_at_i>=\(startTimestamp),created_at_i<=\(endTimestamp)" | ||
} else { | ||
let updatedStartDate = Calendar.current.date( | ||
byAdding: .hour, | ||
value: -24, | ||
to: startDate) | ||
let updatedStartTimestamp = updatedStartDate?.timeIntervalSince1970 | ||
|
||
if let updatedStartTimestamp = updatedStartTimestamp?.rounded() { | ||
return "created_at_i>=\(Int(updatedStartTimestamp)),created_at_i<=\(endTimestamp)" | ||
} | ||
|
||
return .init() | ||
} | ||
} | ||
} | ||
|
||
public init() { } | ||
} | ||
|
||
public class CommentFilter: SearchFilter { | ||
public let query: String = "comment" | ||
|
||
public static func == (lhs: CommentFilter, rhs: CommentFilter) -> Bool { | ||
lhs.query == rhs.query | ||
|
||
var isNumericFilter: Bool { | ||
switch(self){ | ||
case .story, .comment: | ||
return false | ||
case .dateRange: | ||
return true | ||
} | ||
} | ||
|
||
var isTagFilter: Bool { | ||
!isNumericFilter | ||
} | ||
|
||
public init() { } | ||
} |
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
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,7 @@ enum Action: Equatable { | |
case .copy: | ||
return "Copied" | ||
case .none: | ||
return String() | ||
return .init() | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.