added DownvoteReason

This commit is contained in:
Wilhelm Oks 2024-12-20 16:36:47 +01:00
parent ce3c96b887
commit 689f75483d
2 changed files with 16 additions and 2 deletions

View File

@ -0,0 +1,6 @@
/// Represents the reason for downvoting.
public enum DownvoteReason: Int, Hashable {
case notForMe = 0
case repost = 1
case offensiveOrSpam = 2
}

View File

@ -261,11 +261,15 @@ public extension SwiftDevRant {
/// - token: The token from the `logIn` call response. /// - token: The token from the `logIn` call response.
/// - rantId: The id of the rant. /// - rantId: The id of the rant.
/// - vote: The vote for this rant. /// - vote: The vote for this rant.
public func voteOnRant(token: AuthToken, rantId: Int, vote: VoteState) async throws -> Rant { //TODO: add downvote reason public func voteOnRant(token: AuthToken, rantId: Int, vote: VoteState, downvoteReason: DownvoteReason = .notForMe) async throws -> Rant {
var parameters: [String: String] = [:] var parameters: [String: String] = [:]
parameters["vote"] = String(vote.rawValue) parameters["vote"] = String(vote.rawValue)
if vote == .downvoted {
parameters["reason"] = String(downvoteReason.rawValue)
}
let config = makeConfig(.post, path: "devrant/rants/\(rantId)/vote", urlParameters: parameters, token: token) let config = makeConfig(.post, path: "devrant/rants/\(rantId)/vote", urlParameters: parameters, token: token)
struct Response: Codable { struct Response: Codable {
@ -284,11 +288,15 @@ public extension SwiftDevRant {
/// - token: The token from the `logIn` call response. /// - token: The token from the `logIn` call response.
/// - commentId: The id of the comment. /// - commentId: The id of the comment.
/// - vote: The vote for this comment. /// - vote: The vote for this comment.
public func voteOnComment(token: AuthToken, commentId: Int, vote: VoteState) async throws -> Comment { public func voteOnComment(token: AuthToken, commentId: Int, vote: VoteState, downvoteReason: DownvoteReason = .notForMe) async throws -> Comment {
var parameters: [String: String] = [:] var parameters: [String: String] = [:]
parameters["vote"] = String(vote.rawValue) parameters["vote"] = String(vote.rawValue)
if vote == .downvoted {
parameters["reason"] = String(downvoteReason.rawValue)
}
let config = makeConfig(.post, path: "comments/\(commentId)/vote", urlParameters: parameters, token: token) let config = makeConfig(.post, path: "comments/\(commentId)/vote", urlParameters: parameters, token: token)
struct Response: Decodable { struct Response: Decodable {