@@ -17,6 +17,7 @@ open class MyQuestion: RequestYotpo {
17
17
public typealias CompletionDefault = ( _ code: Int , _ msg: String ) -> Void
18
18
public typealias CompletionQuestion = ( _ code: Int , _ title: String , _ msg: String ) -> Void
19
19
public typealias CompleteNextPageQuestions = ( _ msg: String , _ newQuestions: [ Question ] , _ productQuestio: ProductQuestion ) -> Void
20
+ public typealias CompletionWithQuestionsAndExhibition = ( _ code: Int , _ msg: String , _ productQuestion: ProductQuestion , _ questionsExhibition: [ QuestionExhibition ] ) -> Void
20
21
21
22
open func getQuestions( productId: String , completion: @escaping CompletionWithProductQuestions ) {
22
23
let endPoint = Endpoint . MyQuestion ( ) . getQuestions ( productId: productId, appKey: appKey)
@@ -184,6 +185,43 @@ open class MyQuestion: RequestYotpo {
184
185
completion ( " There aren't questions to download " , [ ] , currentQuestion)
185
186
}
186
187
}
188
+
189
+ open func getNextQuestionsWithExhibition( productQuestion: ProductQuestion , oldQuestionsExhibition: [ QuestionExhibition ] ,
190
+ productId: String , completion: @escaping CompletionWithQuestionsAndExhibition ) {
191
+ let myOldProductQuestion = productQuestion. questions. filter { ( question) -> Bool in
192
+ return question. id != 0
193
+ }
194
+ var newProductQuestion = productQuestion
195
+
196
+ if productQuestion. totalQuestions > myOldProductQuestion. count {
197
+ let currentPage = myOldProductQuestion. count/ 5
198
+ var questionsExhibition = [ QuestionExhibition] ( )
199
+ getQuestionPerPage ( productId: productId, page: currentPage+ 1 , completion: { ( code, msg, result) in
200
+ newProductQuestion. questions += result
201
+
202
+ for question in result {
203
+ let questExhibition = QuestionExhibition ( withQuestion: question)
204
+
205
+ let isContain = oldQuestionsExhibition. contains ( where: { ( questionEx) -> Bool in
206
+ return questionEx. idQuestion == questExhibition. idQuestion &&
207
+ questionEx. idAnswer == questExhibition. idAnswer &&
208
+ questionEx. typeQuestion == questExhibition. typeQuestion
209
+ } )
210
+ if !isContain {
211
+ questionsExhibition. append ( questExhibition)
212
+ for answer in question. answers {
213
+ let answerExhibition = QuestionExhibition ( withAnswer: answer, idQuest: question. id)
214
+ questionsExhibition. append ( answerExhibition)
215
+ }
216
+ }
217
+ }
218
+
219
+ completion ( code, msg, newProductQuestion, questionsExhibition)
220
+ } )
221
+ } else {
222
+ completion ( 2 , " There aren't questions to download " , newProductQuestion, [ ] )
223
+ }
224
+ }
187
225
188
226
open func convertProductQuestionToUnicArray( productQuestion: ProductQuestion ) -> [ QuestionExhibition ] {
189
227
var questionsExhibition = [ QuestionExhibition] ( )
0 commit comments