라이브 상세 페이지 추가
This commit is contained in:
@@ -37,7 +37,7 @@ final class LiveViewModel: ObservableObject {
|
||||
@Published var paymentDialogConfirmTitle = ""
|
||||
|
||||
@Published var secretOrPasswordDialogCoin = 0
|
||||
@Published var passwordDialogConfirmAction: (Int) -> Void = { _ in }
|
||||
@Published var passwordDialogConfirmAction: (String) -> Void = { _ in }
|
||||
@Published var isShowPasswordDialog = false
|
||||
|
||||
@Published var isFollowingList = UserDefaults.bool(forKey: .isFollowedChannel) {
|
||||
@@ -52,6 +52,17 @@ final class LiveViewModel: ObservableObject {
|
||||
var isLast = false
|
||||
private let pageSize = 10
|
||||
|
||||
var selectedDateString: String = "" {
|
||||
didSet {
|
||||
if !selectedDateString.trimmingCharacters(in: .whitespaces).isEmpty {
|
||||
page = 1
|
||||
isLast = false
|
||||
liveReservationItems.removeAll()
|
||||
getLiveReservationList()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func hidePopup() {
|
||||
isShowPaymentDialog = false
|
||||
isShowPasswordDialog = false
|
||||
@@ -176,7 +187,7 @@ final class LiveViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func enterRoom(roomId: Int, onSuccess: (() -> Void)? = nil, password: Int? = nil) {
|
||||
func enterRoom(roomId: Int, onSuccess: (() -> Void)? = nil, password: String? = nil) {
|
||||
isLoading = true
|
||||
let request = EnterOrQuitLiveRoomRequest(roomId: roomId, password: password)
|
||||
repository.enterRoom(request: request)
|
||||
@@ -260,6 +271,216 @@ final class LiveViewModel: ObservableObject {
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
func getLiveNowList() {
|
||||
if (!isLast && !isLoading) {
|
||||
isLoading = true
|
||||
repository.roomList(
|
||||
request: GetRoomListRequest(
|
||||
timezone: TimeZone.current.identifier,
|
||||
dateString: nil,
|
||||
status: .NOW,
|
||||
page: page,
|
||||
size: pageSize
|
||||
)
|
||||
)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<[GetRoomListResponse]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
if !data.isEmpty {
|
||||
page += 1
|
||||
self.liveNowItems.append(contentsOf: data)
|
||||
} else {
|
||||
isLast = true
|
||||
}
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func getLiveReservationList() {
|
||||
if (!isLast && !isLoading) {
|
||||
isLoading = true
|
||||
repository.roomList(
|
||||
request: GetRoomListRequest(
|
||||
timezone: TimeZone.current.identifier,
|
||||
dateString: selectedDateString,
|
||||
status: .RESERVATION,
|
||||
page: page,
|
||||
size: pageSize
|
||||
)
|
||||
)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<[GetRoomListResponse]>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
if !data.isEmpty {
|
||||
page += 1
|
||||
self.liveReservationItems.append(contentsOf: data)
|
||||
} else {
|
||||
isLast = true
|
||||
}
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
}
|
||||
|
||||
func reservationLiveRoom(roomId: Int) {
|
||||
getRoomDetail(roomId: roomId) { [unowned self] in
|
||||
if ($0.manager.id == UserDefaults.int(forKey: .userId)) {
|
||||
self.errorMessage = "내가 만든 라이브는 예약할 수 없습니다."
|
||||
self.isShowPopup = true
|
||||
} else {
|
||||
if $0.isPrivateRoom {
|
||||
self.passwordDialogConfirmAction = { password in
|
||||
self.reservation(roomId: roomId, password: password)
|
||||
}
|
||||
self.isShowPasswordDialog = true
|
||||
} else {
|
||||
if ($0.price == 0 || $0.isPaid) {
|
||||
self.reservation(roomId: roomId)
|
||||
} else {
|
||||
self.paymentDialogTitle = "\($0.price)코인으로 예약"
|
||||
self.paymentDialogDesc = "'\($0.title)' 라이브에 참여하기 위해 결제합니다."
|
||||
self.paymentDialogConfirmTitle = "결제 후 예약하기"
|
||||
self.paymentDialogConfirmAction = { [unowned self] in
|
||||
hidePopup()
|
||||
reservation(roomId: roomId)
|
||||
}
|
||||
self.isShowPaymentDialog = true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func getRoomDetail(roomId: Int, onSuccess: @escaping (GetRoomDetailResponse) -> Void) {
|
||||
isLoading = true
|
||||
repository.getRoomDetail(roomId: roomId)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { response in
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<GetRoomDetailResponse>.self, from: responseData)
|
||||
|
||||
if let data = decoded.data, decoded.success {
|
||||
onSuccess(data)
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "라이브 정보를 가져오지 못했습니다.\n다시 시도해 주세요."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "라이브 정보를 가져오지 못했습니다.\n다시 시도해 주세요."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
|
||||
self.isLoading = false
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func reservation(roomId: Int, password: String? = nil) {
|
||||
isLoading = true
|
||||
let request = MakeLiveReservationRequest(roomId: roomId, password: password)
|
||||
repository.makeReservation(request: request)
|
||||
.sink { result in
|
||||
switch result {
|
||||
case .finished:
|
||||
DEBUG_LOG("finish")
|
||||
case .failure(let error):
|
||||
ERROR_LOG(error.localizedDescription)
|
||||
}
|
||||
} receiveValue: { [unowned self] response in
|
||||
self.isLoading = false
|
||||
let responseData = response.data
|
||||
|
||||
do {
|
||||
let jsonDecoder = JSONDecoder()
|
||||
let decoded = try jsonDecoder.decode(ApiResponse<MakeLiveReservationResponse>.self, from: responseData)
|
||||
|
||||
if let response = decoded.data, decoded.success {
|
||||
self.getSummary()
|
||||
AppState.shared.setAppStep(step: .liveReservationComplete(response: response))
|
||||
} else {
|
||||
if let message = decoded.message {
|
||||
self.errorMessage = message
|
||||
} else {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
}
|
||||
|
||||
self.isShowPopup = true
|
||||
}
|
||||
} catch {
|
||||
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
|
||||
self.isShowPopup = true
|
||||
}
|
||||
}
|
||||
.store(in: &subscription)
|
||||
}
|
||||
|
||||
private func getFollowedChannelList() {
|
||||
followedChannelItems.removeAll()
|
||||
isFollowedChannelLoading = true
|
||||
|
Reference in New Issue
Block a user