added DownvoteReason
This commit is contained in:
parent
ce3c96b887
commit
689f75483d
6
Sources/SwiftDevRant/Models/DownvoteReason.swift
Normal file
6
Sources/SwiftDevRant/Models/DownvoteReason.swift
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
/// Represents the reason for downvoting.
|
||||||
|
public enum DownvoteReason: Int, Hashable {
|
||||||
|
case notForMe = 0
|
||||||
|
case repost = 1
|
||||||
|
case offensiveOrSpam = 2
|
||||||
|
}
|
@ -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 {
|
||||||
|
Loading…
Reference in New Issue
Block a user