diff --git a/SodaLive/Sources/Chat/Character/CharacterSectionView.swift b/SodaLive/Sources/Chat/Character/CharacterSectionView.swift index d3a1132..e0dac13 100644 --- a/SodaLive/Sources/Chat/Character/CharacterSectionView.swift +++ b/SodaLive/Sources/Chat/Character/CharacterSectionView.swift @@ -19,7 +19,7 @@ struct CharacterSectionView: View { VStack(alignment: .leading, spacing: 16) { HStack(spacing: 0) { Text(title) - .font(.custom(Font.preBold.rawValue, size: 20)) + .font(.custom(Font.preBold.rawValue, size: 24)) .foregroundColor(.white) Spacer() if let trailingTitle = trailingTitle { diff --git a/SodaLive/Sources/Home/HomeApi.swift b/SodaLive/Sources/Home/HomeApi.swift index db5299f..2b8e132 100644 --- a/SodaLive/Sources/Home/HomeApi.swift +++ b/SodaLive/Sources/Home/HomeApi.swift @@ -13,6 +13,7 @@ enum HomeApi { case getLatestContentByTheme(theme: String, isAdultContentVisible: Bool, contentType: ContentType) case getDayOfWeekSeriesList(dayOfWeek: SeriesPublishedDaysOfWeek, isAdultContentVisible: Bool, contentType: ContentType) case getRecommendContents(isAdultContentVisible: Bool, contentType: ContentType) + case getContentRankingBySort(sort: ContentRankingSortType, isAdultContentVisible: Bool, contentType: ContentType) } extension HomeApi: TargetType { @@ -33,6 +34,9 @@ extension HomeApi: TargetType { case .getRecommendContents: return "/api/home/recommend-contents" + + case .getContentRankingBySort: + return "/api/home/content-ranking" } } @@ -75,6 +79,15 @@ extension HomeApi: TargetType { "contentType": contentType ] as [String: Any] + return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) + + case .getContentRankingBySort(let sort, let isAdultContentVisible, let contentType): + let parameters = [ + "sort": sort, + "isAdultContentVisible": isAdultContentVisible, + "contentType": contentType + ] as [String: Any] + return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) } } diff --git a/SodaLive/Sources/Home/HomeTabRepository.swift b/SodaLive/Sources/Home/HomeTabRepository.swift index 2b82717..af17582 100644 --- a/SodaLive/Sources/Home/HomeTabRepository.swift +++ b/SodaLive/Sources/Home/HomeTabRepository.swift @@ -50,4 +50,14 @@ class HomeTabRepository { ) ) } + + func getContentRankingBySort(sort: ContentRankingSortType) -> AnyPublisher { + return api.requestPublisher( + .getContentRankingBySort( + sort: sort, + isAdultContentVisible: UserDefaults.isAdultContentVisible(), + contentType: ContentType(rawValue: UserDefaults.string(forKey: .contentPreference)) ?? ContentType.ALL + ) + ) + } } diff --git a/SodaLive/Sources/Home/HomeTabView.swift b/SodaLive/Sources/Home/HomeTabView.swift index 1a11209..9a1a261 100644 --- a/SodaLive/Sources/Home/HomeTabView.swift +++ b/SodaLive/Sources/Home/HomeTabView.swift @@ -251,8 +251,8 @@ struct HomeTabView: View { ) } - if !viewModel.contentRanking.isEmpty { - HomeWeeklyChartView(contentList: viewModel.contentRanking) + HomeWeeklyChartView(contentList: viewModel.contentRanking) { + viewModel.getContentRankingBySort(sort: $0) } if !viewModel.recommendChannelList.isEmpty { diff --git a/SodaLive/Sources/Home/HomeTabViewModel.swift b/SodaLive/Sources/Home/HomeTabViewModel.swift index bd24f19..bca1319 100644 --- a/SodaLive/Sources/Home/HomeTabViewModel.swift +++ b/SodaLive/Sources/Home/HomeTabViewModel.swift @@ -12,6 +12,10 @@ enum SeriesPublishedDaysOfWeek: String, Encodable { case SUN, MON, TUE, WED, THU, FRI, SAT, RANDOM } +enum ContentRankingSortType: String, Encodable { + case REVENUE, SALES_COUNT, COMMENT_COUNT, LIKE_COUNT +} + final class HomeTabViewModel: ObservableObject { private let repository = HomeTabRepository() private let userRepository = UserRepository() @@ -35,6 +39,13 @@ final class HomeTabViewModel: ObservableObject { @Published var pointAvailableContentList: [AudioContentMainItem] = [] @Published var recommendContentList: [AudioContentMainItem] = [] + private let sortType = [ + "매출": ContentRankingSortType.REVENUE, + "판매량": ContentRankingSortType.SALES_COUNT, + "댓글": ContentRankingSortType.COMMENT_COUNT, + "좋아요": ContentRankingSortType.LIKE_COUNT + ] + func fetchData() { isLoading = true @@ -237,4 +248,42 @@ final class HomeTabViewModel: ObservableObject { } .store(in: &subscription) } + + func getContentRankingBySort(sort: String) { + isLoading = true + + repository.getContentRankingBySort(sort: sortType[sort] ?? ContentRankingSortType.REVENUE) + .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<[GetAudioContentRankingItem]>.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) + } } diff --git a/SodaLive/Sources/Home/HomeWeeklyChartView.swift b/SodaLive/Sources/Home/HomeWeeklyChartView.swift index c716188..e588c5d 100644 --- a/SodaLive/Sources/Home/HomeWeeklyChartView.swift +++ b/SodaLive/Sources/Home/HomeWeeklyChartView.swift @@ -18,6 +18,10 @@ struct HomeWeeklyChartView: View { ] let contentList: [GetAudioContentRankingItem] + let onTapSort: (String) -> Void + + let sortList = ["매출", "판매량", "댓글", "좋아요"] + @State private var selectedSort = "매출" var body: some View { VStack(spacing: 16) { @@ -34,6 +38,14 @@ struct HomeWeeklyChartView: View { } .padding(.horizontal, 24) + HStack(spacing: 16) { + ContentMainContentThemeView( + themeList: sortList, + selectTheme: onTapSort, + selectedTheme: $selectedSort + ) + } + ScrollView(.horizontal, showsIndicators: false) { LazyHGrid(rows: rows, spacing: 16) { ForEach(0..