인기 콘텐츠 전체 보기 - 정렬 추가
This commit is contained in:
		| @@ -31,6 +31,14 @@ struct ContentRankingAllView: View { | ||||
|                 .background(Color(hex: "222222")) | ||||
|                 .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) { | ||||
|                     VStack(spacing: 20) { | ||||
|                         ForEach(0..<viewModel.contentRankingItemList.count, id: \.self) { index in | ||||
| @@ -141,6 +149,7 @@ struct ContentRankingAllView: View { | ||||
|             } | ||||
|         } | ||||
|         .onAppear { | ||||
|             viewModel.getContentRankingSortType() | ||||
|             viewModel.getContentRanking() | ||||
|         } | ||||
|     } | ||||
|   | ||||
| @@ -19,6 +19,15 @@ final class ContentRankingAllViewModel: ObservableObject { | ||||
|      | ||||
|     @Published var dateString = "" | ||||
|     @Published var contentRankingItemList = [GetAudioContentRankingItem]() | ||||
|     @Published var contentRankingSortList = [String]() | ||||
|      | ||||
|     @Published var selectedContentRankingSort = "매출" { | ||||
|         didSet { | ||||
|             page = 1 | ||||
|             isLast = false | ||||
|             getContentRanking() | ||||
|         } | ||||
|     } | ||||
|      | ||||
|     var page = 1 | ||||
|     var isLast = false | ||||
| @@ -28,7 +37,7 @@ final class ContentRankingAllViewModel: ObservableObject { | ||||
|         if (!isLast && !isLoading && page <= 5) { | ||||
|             isLoading = true | ||||
|              | ||||
|             repository.getContentRanking(page: page, size: pageSize) | ||||
|             repository.getContentRanking(page: page, size: pageSize, sortType: selectedContentRankingSort) | ||||
|                 .sink { result in | ||||
|                     switch result { | ||||
|                     case .finished: | ||||
| @@ -76,4 +85,40 @@ final class ContentRankingAllViewModel: ObservableObject { | ||||
|                 .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) | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -30,6 +30,7 @@ enum ContentApi { | ||||
|     case getNewContentAllOfTheme(theme: String, page: Int, size: Int) | ||||
|     case getAudioContentListByCurationId(curationId: Int, page: Int, size: Int, sort: ContentCurationViewModel.Sort) | ||||
|     case getContentRanking(page: Int, size: Int, sortType: String) | ||||
|     case getContentRankingSortType | ||||
| } | ||||
|  | ||||
| extension ContentApi: TargetType { | ||||
| @@ -101,6 +102,9 @@ extension ContentApi: TargetType { | ||||
|              | ||||
|         case .getContentRanking: | ||||
|             return  "/audio-content/ranking" | ||||
|              | ||||
|         case .getContentRankingSortType: | ||||
|             return  "/audio-content/ranking-sort-type" | ||||
|         } | ||||
|     } | ||||
|      | ||||
| @@ -108,7 +112,8 @@ extension ContentApi: TargetType { | ||||
|         switch self { | ||||
|         case .getAudioContentList, .getAudioContentDetail, .getOrderList, .getAudioContentThemeList, | ||||
|                 .getAudioContentCommentList, .getAudioContentCommentReplyList, .getMain, .getNewContentOfTheme, | ||||
|                 .getNewContentThemeList, .getNewContentAllOfTheme, .getAudioContentListByCurationId, .getContentRanking: | ||||
|                 .getNewContentThemeList, .getNewContentAllOfTheme, .getAudioContentListByCurationId, .getContentRanking, | ||||
|                 .getContentRankingSortType: | ||||
|             return .get | ||||
|              | ||||
|         case .likeContent, .modifyAudioContent, .modifyComment: | ||||
| @@ -228,6 +233,9 @@ extension ContentApi: TargetType { | ||||
|             ] as [String : Any] | ||||
|              | ||||
|             return .requestParameters(parameters: parameters, encoding: URLEncoding.queryString) | ||||
|              | ||||
|         case .getContentRankingSortType: | ||||
|             return .requestPlain | ||||
|         } | ||||
|     } | ||||
|      | ||||
|   | ||||
| @@ -93,6 +93,10 @@ final class ContentRepository { | ||||
|         return api.requestPublisher(.getAudioContentListByCurationId(curationId: curationId, page: page, size: size, sort: sort)) | ||||
|     } | ||||
|      | ||||
|     func getContentRankingSortType() -> AnyPublisher<Response, MoyaError> { | ||||
|         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)) | ||||
|     } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Yu Sung
					Yu Sung