Skip to content

Commit e553812

Browse files
authored
Merge pull request #5 from WilhelmOks/VoteStateEnum
changed voteState from Int to enum
2 parents fbdc3bc + 2957155 commit e553812

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

Sources/SwiftRant/RantInFeed.swift

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,23 @@ public struct RantInFeed: Decodable, Identifiable {
3737
/// * `0` = Unvoted
3838
/// * `-1` = Downvote
3939
/// * `-2` = Voting disabled (the rant belongs to the user whose token was used to fetch the rant)
40-
public var voteState: Int
40+
public var voteStateRaw: Int
41+
42+
public enum VoteState: Int {
43+
case upvoted = 1
44+
case unvoted = 0
45+
case downvoted = -1
46+
case unvotable = -2
47+
}
48+
49+
public var voteState: VoteState {
50+
get {
51+
return VoteState(rawValue: voteStateRaw) ?? .unvotable
52+
}
53+
set {
54+
voteStateRaw = newValue.rawValue
55+
}
56+
}
4157

4258
/// Whether or not the rant was edited in the past.
4359
public let isEdited: Bool
@@ -111,7 +127,7 @@ extension RantInFeed {
111127

112128
commentCount = try values.decode(Int.self, forKey: .commentCount)
113129
tags = try values.decode([String].self, forKey: .tags)
114-
voteState = try values.decode(Int.self, forKey: .voteState)
130+
voteStateRaw = try values.decode(Int.self, forKey: .voteState)
115131
isEdited = try values.decode(Bool.self, forKey: .isEdited)
116132
link = try? values.decode(String.self, forKey: .link)
117133
collabType = try? values.decode(Int.self, forKey: .collabType)

0 commit comments

Comments
 (0)