diff --git a/SodaLive/Sources/V2/CreatorChannel/Donation/Models/CreatorChannelDonationTabResponse.swift b/SodaLive/Sources/V2/CreatorChannel/Donation/Models/CreatorChannelDonationTabResponse.swift new file mode 100644 index 00000000..4bb08f0f --- /dev/null +++ b/SodaLive/Sources/V2/CreatorChannel/Donation/Models/CreatorChannelDonationTabResponse.swift @@ -0,0 +1,17 @@ +import Foundation + +struct CreatorChannelDonationTabResponse: Decodable { + let donationCount: Int + let rankings: [MemberDonationRankingResponse] + let donations: [CreatorChannelDonationResponse] + let page: Int + let size: Int + let hasNext: Bool +} + +struct MemberDonationRankingResponse: Decodable { + let userId: Int + let nickname: String + let profileImage: String + let donationCan: Int +} diff --git a/SodaLive/Sources/V2/CreatorChannel/Donation/Repository/CreatorChannelDonationApi.swift b/SodaLive/Sources/V2/CreatorChannel/Donation/Repository/CreatorChannelDonationApi.swift new file mode 100644 index 00000000..df4ed236 --- /dev/null +++ b/SodaLive/Sources/V2/CreatorChannel/Donation/Repository/CreatorChannelDonationApi.swift @@ -0,0 +1,44 @@ +import Foundation + +import Moya + +enum CreatorChannelDonationApi { + case getDonations(creatorId: Int, page: Int, size: Int) +} + +extension CreatorChannelDonationApi: TargetType { + var baseURL: URL { + return URL(string: BASE_URL)! + } + + var path: String { + switch self { + case .getDonations(let creatorId, _, _): + return "/api/v2/creator-channels/\(creatorId)/donations" + } + } + + var method: Moya.Method { + switch self { + case .getDonations: + return .get + } + } + + var task: Moya.Task { + switch self { + case .getDonations(_, let page, let size): + return .requestParameters( + parameters: [ + "page": page, + "size": size + ], + encoding: URLEncoding.queryString + ) + } + } + + var headers: [String: String]? { + return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"] + } +} diff --git a/SodaLive/Sources/V2/CreatorChannel/Donation/Repository/CreatorChannelDonationRepository.swift b/SodaLive/Sources/V2/CreatorChannel/Donation/Repository/CreatorChannelDonationRepository.swift new file mode 100644 index 00000000..2a5b040e --- /dev/null +++ b/SodaLive/Sources/V2/CreatorChannel/Donation/Repository/CreatorChannelDonationRepository.swift @@ -0,0 +1,13 @@ +import Foundation +import Combine + +import CombineMoya +import Moya + +final class CreatorChannelDonationRepository { + private let api = MoyaProvider() + + func getDonations(creatorId: Int, page: Int, size: Int) -> AnyPublisher { + return api.requestPublisher(.getDonations(creatorId: creatorId, page: page, size: size)) + } +}