Compare commits

..

5 Commits

13 changed files with 219 additions and 22 deletions

View File

@ -31,6 +31,14 @@ struct ContentRankingAllView: View {
.background(Color(hex: "222222")) .background(Color(hex: "222222"))
.padding(.top, 13.3) .padding(.top, 13.3)
ContentMainRankingSortView(
sorts: viewModel.contentRankingSortList,
selectSort: { viewModel.selectedContentRankingSort = $0 },
selectedSort: $viewModel.selectedContentRankingSort
)
.frame(width: screenSize().width - 26.7)
.padding(.vertical, 16.7)
ScrollView(.vertical, showsIndicators: false) { ScrollView(.vertical, showsIndicators: false) {
VStack(spacing: 20) { VStack(spacing: 20) {
ForEach(0..<viewModel.contentRankingItemList.count, id: \.self) { index in ForEach(0..<viewModel.contentRankingItemList.count, id: \.self) { index in
@ -141,6 +149,7 @@ struct ContentRankingAllView: View {
} }
} }
.onAppear { .onAppear {
viewModel.getContentRankingSortType()
viewModel.getContentRanking() viewModel.getContentRanking()
} }
} }

View File

@ -19,6 +19,15 @@ final class ContentRankingAllViewModel: ObservableObject {
@Published var dateString = "" @Published var dateString = ""
@Published var contentRankingItemList = [GetAudioContentRankingItem]() @Published var contentRankingItemList = [GetAudioContentRankingItem]()
@Published var contentRankingSortList = [String]()
@Published var selectedContentRankingSort = "매출" {
didSet {
page = 1
isLast = false
getContentRanking()
}
}
var page = 1 var page = 1
var isLast = false var isLast = false
@ -28,7 +37,7 @@ final class ContentRankingAllViewModel: ObservableObject {
if (!isLast && !isLoading && page <= 5) { if (!isLast && !isLoading && page <= 5) {
isLoading = true isLoading = true
repository.getContentRanking(page: page, size: pageSize) repository.getContentRanking(page: page, size: pageSize, sortType: selectedContentRankingSort)
.sink { result in .sink { result in
switch result { switch result {
case .finished: case .finished:
@ -76,4 +85,40 @@ final class ContentRankingAllViewModel: ObservableObject {
.store(in: &subscription) .store(in: &subscription)
} }
} }
func getContentRankingSortType() {
repository.getContentRankingSortType()
.sink { result in
switch result {
case .finished:
DEBUG_LOG("finish")
case .failure(let error):
ERROR_LOG(error.localizedDescription)
}
} receiveValue: { [unowned self] response in
let responseData = response.data
do {
let jsonDecoder = JSONDecoder()
let decoded = try jsonDecoder.decode(ApiResponse<[String]>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.contentRankingSortList.removeAll()
self.contentRankingSortList.append(contentsOf: data)
} 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)
}
} }

View File

@ -29,7 +29,8 @@ enum ContentApi {
case getNewContentThemeList case getNewContentThemeList
case getNewContentAllOfTheme(theme: String, page: Int, size: Int) case getNewContentAllOfTheme(theme: String, page: Int, size: Int)
case getAudioContentListByCurationId(curationId: Int, page: Int, size: Int, sort: ContentCurationViewModel.Sort) case getAudioContentListByCurationId(curationId: Int, page: Int, size: Int, sort: ContentCurationViewModel.Sort)
case getContentRanking(page: Int, size: Int) case getContentRanking(page: Int, size: Int, sortType: String)
case getContentRankingSortType
} }
extension ContentApi: TargetType { extension ContentApi: TargetType {
@ -101,6 +102,9 @@ extension ContentApi: TargetType {
case .getContentRanking: case .getContentRanking:
return "/audio-content/ranking" return "/audio-content/ranking"
case .getContentRankingSortType:
return "/audio-content/ranking-sort-type"
} }
} }
@ -108,7 +112,8 @@ extension ContentApi: TargetType {
switch self { switch self {
case .getAudioContentList, .getAudioContentDetail, .getOrderList, .getAudioContentThemeList, case .getAudioContentList, .getAudioContentDetail, .getOrderList, .getAudioContentThemeList,
.getAudioContentCommentList, .getAudioContentCommentReplyList, .getMain, .getNewContentOfTheme, .getAudioContentCommentList, .getAudioContentCommentReplyList, .getMain, .getNewContentOfTheme,
.getNewContentThemeList, .getNewContentAllOfTheme, .getAudioContentListByCurationId, .getContentRanking: .getNewContentThemeList, .getNewContentAllOfTheme, .getAudioContentListByCurationId, .getContentRanking,
.getContentRankingSortType:
return .get return .get
case .likeContent, .modifyAudioContent, .modifyComment: case .likeContent, .modifyAudioContent, .modifyComment:
@ -220,13 +225,17 @@ extension ContentApi: TargetType {
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
case .getContentRanking(let page, let size): case .getContentRanking(let page, let size, let sortType):
let parameters = [ let parameters = [
"page": page - 1, "page": page - 1,
"size": size, "size": size,
"sort-type": sortType
] as [String : Any] ] as [String : Any]
return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString)
case .getContentRankingSortType:
return .requestPlain
} }
} }

View File

@ -93,7 +93,11 @@ final class ContentRepository {
return api.requestPublisher(.getAudioContentListByCurationId(curationId: curationId, page: page, size: size, sort: sort)) return api.requestPublisher(.getAudioContentListByCurationId(curationId: curationId, page: page, size: size, sort: sort))
} }
func getContentRanking(page: Int, size: Int) -> AnyPublisher<Response, MoyaError> { func getContentRankingSortType() -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.getContentRanking(page: page, size: size)) return api.requestPublisher(.getContentRankingSortType)
}
func getContentRanking(page: Int, size: Int, sortType: String = "매출") -> AnyPublisher<Response, MoyaError> {
return api.requestPublisher(.getContentRanking(page: page, size: size, sortType: sortType))
} }
} }

View File

@ -305,6 +305,11 @@ final class ContentDetailViewModel: ObservableObject {
} else { } else {
if let message = decoded.message { if let message = decoded.message {
self.errorMessage = message self.errorMessage = message
if message.contains("캔이 부족합니다") {
DispatchQueue.main.asyncAfter(deadline: .now() + 2) {
AppState.shared.setAppStep(step: .canCharge(refresh: {}, afterCompletionToGoBack: true))
}
}
} else { } else {
self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다." self.errorMessage = "다시 시도해 주세요.\n계속 같은 문제가 발생할 경우 고객센터로 문의 주시기 바랍니다."
} }

View File

@ -60,7 +60,7 @@ struct LiveRoomDonationDialogView: View {
Image("ic_forward") Image("ic_forward")
} }
.onTapGesture { .onTapGesture {
AppState.shared.setAppStep(step: .canCharge(refresh: {})) AppState.shared.setAppStep(step: .canCharge(refresh: {}, afterCompletionToGoBack: true))
self.isShowing = false self.isShowing = false
} }
} }

View File

@ -0,0 +1,55 @@
//
// ContentMainRankingSortView.swift
// SodaLive
//
// Created by klaus on 2023/11/03.
//
import SwiftUI
struct ContentMainRankingSortView: View {
let sorts: [String]
let selectSort: (String) -> Void
@Binding var selectedSort: String
var body: some View {
ScrollView(.horizontal, showsIndicators: false) {
HStack(alignment: .top, spacing: 8) {
ForEach(0..<sorts.count, id: \.self) { index in
let sort = sorts[index]
Text(sort)
.font(.custom(Font.medium.rawValue, size: 14.7))
.foregroundColor(Color(hex: selectedSort == sort ? "9970ff" : "777777"))
.padding(.horizontal, 13.3)
.padding(.vertical, 9.3)
.border(
Color(hex: selectedSort == sort ? "9970ff" : "eeeeee"),
width: 0.5
)
.cornerRadius(16.7)
.overlay(
RoundedRectangle(cornerRadius: CGFloat(16.7))
.stroke(lineWidth: 0.5)
.foregroundColor(Color(hex: selectedSort == sort ? "9970ff" : "eeeeee"))
)
.onTapGesture {
if selectedSort != sort {
selectSort(sort)
}
}
}
}
}
}
}
struct ContentMainRankingSortView_Previews: PreviewProvider {
static var previews: some View {
ContentMainRankingSortView(
sorts: ["전체", "테마1", "테마2"],
selectSort: { _ in },
selectedSort: .constant("전체")
)
}
}

View File

@ -10,8 +10,12 @@ import Kingfisher
struct ContentMainRankingView: View { struct ContentMainRankingView: View {
let sorts: [String]
let item: GetAudioContentRanking let item: GetAudioContentRanking
let selectSort: (String) -> Void
@Binding var selectedSort: String
let rows = [ let rows = [
GridItem(.fixed(60), alignment: .leading), GridItem(.fixed(60), alignment: .leading),
GridItem(.fixed(60), alignment: .leading), GridItem(.fixed(60), alignment: .leading),
@ -47,6 +51,9 @@ struct ContentMainRankingView: View {
.background(Color(hex: "222222")) .background(Color(hex: "222222"))
.padding(.top, 13.3) .padding(.top, 13.3)
ContentMainRankingSortView(sorts: sorts, selectSort: selectSort, selectedSort: $selectedSort)
.padding(.vertical, 16.7)
ScrollView(.horizontal, showsIndicators: false) { ScrollView(.horizontal, showsIndicators: false) {
LazyHGrid(rows: rows, spacing: 13.3) { LazyHGrid(rows: rows, spacing: 13.3) {
ForEach(0..<item.items.count, id: \.self) { index in ForEach(0..<item.items.count, id: \.self) { index in
@ -92,6 +99,7 @@ struct ContentMainRankingView: View {
struct ContentMainRankingView_Previews: PreviewProvider { struct ContentMainRankingView_Previews: PreviewProvider {
static var previews: some View { static var previews: some View {
ContentMainRankingView( ContentMainRankingView(
sorts: ["매출", "후원", "댓글"],
item: GetAudioContentRanking( item: GetAudioContentRanking(
startDate: "2023년 10월 2일", startDate: "2023년 10월 2일",
endDate: "10월 9일", endDate: "10월 9일",
@ -137,7 +145,9 @@ struct ContentMainRankingView_Previews: PreviewProvider {
creatorNickname: "ㄹㄴ어ㅏㅣㅇㄴ런아ㅣ" creatorNickname: "ㄹㄴ어ㅏㅣㅇㄴ런아ㅣ"
), ),
] ]
) ),
selectSort: { _ in },
selectedSort: .constant("매출")
) )
} }
} }

View File

@ -56,9 +56,15 @@ struct ContentMainView: View {
.padding(.horizontal, 13.3) .padding(.horizontal, 13.3)
if let contentRanking = viewModel.contentRanking { if let contentRanking = viewModel.contentRanking {
ContentMainRankingView(item: contentRanking) ContentMainRankingView(
sorts: viewModel.contentRankingSortList,
item: contentRanking,
selectSort: { viewModel.selectedContentRankingSort = $0 },
selectedSort: $viewModel.selectedContentRankingSort
)
.padding(.top, 40) .padding(.top, 40)
.padding(.horizontal, 13.3) .padding(.horizontal, 13.3)
.animation(nil)
} }
if viewModel.curationList.count > 0 { if viewModel.curationList.count > 0 {

View File

@ -24,6 +24,7 @@ final class ContentMainViewModel: ObservableObject {
@Published var orderList = [GetAudioContentMainItem]() @Published var orderList = [GetAudioContentMainItem]()
@Published var themeList = [String]() @Published var themeList = [String]()
@Published var curationList = [GetAudioContentCurationResponse]() @Published var curationList = [GetAudioContentCurationResponse]()
@Published var contentRankingSortList = [String]()
@Published var contentRanking: GetAudioContentRanking? = nil @Published var contentRanking: GetAudioContentRanking? = nil
@Published var selectedTheme = "전체" { @Published var selectedTheme = "전체" {
@ -32,6 +33,12 @@ final class ContentMainViewModel: ObservableObject {
} }
} }
@Published var selectedContentRankingSort = "매출" {
didSet {
getContentRanking()
}
}
func getMain() { func getMain() {
isLoading = true isLoading = true
@ -59,6 +66,7 @@ final class ContentMainViewModel: ObservableObject {
self.orderList.removeAll() self.orderList.removeAll()
self.curationList.removeAll() self.curationList.removeAll()
self.themeList.removeAll() self.themeList.removeAll()
self.contentRankingSortList.removeAll()
self.newContentUploadCreatorList.append(contentsOf: data.newContentUploadCreatorList) self.newContentUploadCreatorList.append(contentsOf: data.newContentUploadCreatorList)
self.newContentList.append(contentsOf: data.newContentList) self.newContentList.append(contentsOf: data.newContentList)
@ -66,6 +74,7 @@ final class ContentMainViewModel: ObservableObject {
self.orderList.append(contentsOf: data.orderList) self.orderList.append(contentsOf: data.orderList)
self.curationList.append(contentsOf: data.curationList) self.curationList.append(contentsOf: data.curationList)
self.contentRanking = data.contentRanking self.contentRanking = data.contentRanking
self.contentRankingSortList.append(contentsOf: data.contentRankingSortTypeList)
self.themeList.append("전체") self.themeList.append("전체")
self.themeList.append(contentsOf: data.themeList) self.themeList.append(contentsOf: data.themeList)
@ -124,4 +133,42 @@ final class ContentMainViewModel: ObservableObject {
} }
.store(in: &subscription) .store(in: &subscription)
} }
func getContentRanking() {
isLoading = true
repository.getContentRanking(page: 1, size: 12, sortType: selectedContentRankingSort)
.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<GetAudioContentRanking>.self, from: responseData)
if let data = decoded.data, decoded.success {
self.contentRanking = data
} 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)
}
} }

View File

@ -14,6 +14,7 @@ struct GetAudioContentMainResponse: Decodable {
let themeList: [String] let themeList: [String]
let newContentList: [GetAudioContentMainItem] let newContentList: [GetAudioContentMainItem]
let curationList: [GetAudioContentCurationResponse] let curationList: [GetAudioContentCurationResponse]
let contentRankingSortTypeList: [String]
let contentRanking: GetAudioContentRanking let contentRanking: GetAudioContentRanking
} }

View File

@ -27,7 +27,7 @@ struct CanPgPaymentView: View {
ZStack { ZStack {
Color.black.ignoresSafeArea() Color.black.ignoresSafeArea()
if viewModel.isShowPamentView { if viewModel.isShowPaymentView {
BootpayUI(payload: viewModel.payload, requestType: BootpayRequest.TYPE_PAYMENT) BootpayUI(payload: viewModel.payload, requestType: BootpayRequest.TYPE_PAYMENT)
.onConfirm { .onConfirm {
DEBUG_LOG("onConfirm: \($0)") DEBUG_LOG("onConfirm: \($0)")
@ -38,28 +38,31 @@ struct CanPgPaymentView: View {
} }
.onError { .onError {
DEBUG_LOG("onError: \($0)") DEBUG_LOG("onError: \($0)")
viewModel.isShowPamentView = false viewModel.isShowPaymentView = false
viewModel.errorMessage = "결제 중 오류가 발생했습니다." viewModel.errorMessage = "결제 중 오류가 발생했습니다."
viewModel.isShowPopup = true viewModel.isShowPopup = true
} }
.onDone { .onDone {
DEBUG_LOG("onDone: \($0)") DEBUG_LOG("onDone: \($0)")
viewModel.verifyPayment($0) { viewModel.verifyPayment($0) {
self.refresh()
if afterCompletionToGoBack {
AppState.shared.back()
} else {
AppState.shared.setAppStep(step: .canStatus(refresh: refresh))
}
let can = UserDefaults.int(forKey: .can) let can = UserDefaults.int(forKey: .can)
UserDefaults.set(can + canResponse.can + canResponse.rewardCan, forKey: .can) UserDefaults.set(can + canResponse.can + canResponse.rewardCan, forKey: .can)
self.refresh()
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
if afterCompletionToGoBack {
AppState.shared.back()
AppState.shared.back()
} else {
AppState.shared.setAppStep(step: .canStatus(refresh: refresh))
}
}
} }
} }
.onClose { .onClose {
DEBUG_LOG("onClose") DEBUG_LOG("onClose")
viewModel.isShowPamentView = false viewModel.isShowPaymentView = false
} }
} else { } else {
GeometryReader { proxy in GeometryReader { proxy in
@ -279,7 +282,7 @@ struct CanPgPaymentView: View {
viewModel.payload.price = Double(canResponse.price) viewModel.payload.price = Double(canResponse.price)
viewModel.payload.taxFree = 0 viewModel.payload.taxFree = 0
viewModel.isShowPamentView = true viewModel.isShowPaymentView = true
} }
} }
} }

View File

@ -26,7 +26,7 @@ final class CanPgPaymentViewModel: ObservableObject {
@Published var isShowPopup = false @Published var isShowPopup = false
@Published var isLoading = false @Published var isLoading = false
@Published var isShowPamentView = false @Published var isShowPaymentView = false
@Published var paymentMethod: PaymentMethod? = nil @Published var paymentMethod: PaymentMethod? = nil
let payload = Payload() let payload = Payload()
@ -99,6 +99,9 @@ final class CanPgPaymentViewModel: ObservableObject {
let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData) let decoded = try jsonDecoder.decode(ApiResponseWithoutData.self, from: responseData)
if decoded.success { if decoded.success {
self.errorMessage = "캔이 충전되었습니다"
self.isShowPopup = true
onSuccess() onSuccess()
} else { } else {
if let message = decoded.message { if let message = decoded.message {