feat(main): 홈 대화 탭을 추가한다
This commit is contained in:
45
SodaLive/Sources/V2/Main/Chat/Repository/MainChatApi.swift
Normal file
45
SodaLive/Sources/V2/Main/Chat/Repository/MainChatApi.swift
Normal file
@@ -0,0 +1,45 @@
|
||||
import Foundation
|
||||
import Moya
|
||||
|
||||
enum MainChatApi {
|
||||
case getChatRooms(filter: String, cursor: String?)
|
||||
}
|
||||
|
||||
extension MainChatApi: TargetType {
|
||||
var baseURL: URL {
|
||||
return URL(string: BASE_URL)!
|
||||
}
|
||||
|
||||
var path: String {
|
||||
switch self {
|
||||
case .getChatRooms:
|
||||
return "/api/v2/chat/rooms"
|
||||
}
|
||||
}
|
||||
|
||||
var method: Moya.Method {
|
||||
switch self {
|
||||
case .getChatRooms:
|
||||
return .get
|
||||
}
|
||||
}
|
||||
|
||||
var task: Moya.Task {
|
||||
switch self {
|
||||
case .getChatRooms(let filter, let cursor):
|
||||
var parameters: [String: Any] = [
|
||||
"filter": filter
|
||||
]
|
||||
|
||||
if let cursor {
|
||||
parameters["cursor"] = cursor
|
||||
}
|
||||
|
||||
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
|
||||
}
|
||||
}
|
||||
|
||||
var headers: [String: String]? {
|
||||
return ["Authorization": "Bearer \(UserDefaults.string(forKey: UserDefaultsKey.token))"]
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
import Foundation
|
||||
import Combine
|
||||
import CombineMoya
|
||||
import Moya
|
||||
|
||||
final class MainChatRepository {
|
||||
private let api = MoyaProvider<MainChatApi>()
|
||||
|
||||
func getChatRooms(filter: String, cursor: String?) -> AnyPublisher<Response, MoyaError> {
|
||||
return api.requestPublisher(.getChatRooms(filter: filter, cursor: cursor))
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user