Commit 3c89dac9 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

actualize feeds repository

parent 65538f6a
...@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntit ...@@ -6,7 +6,6 @@ import com.biganto.visual.roompark.data.repository.db.requrey.model.ArticleEntit
import com.biganto.visual.roompark.data.repository.mapper.fromRaw import com.biganto.visual.roompark.data.repository.mapper.fromRaw
import com.biganto.visual.roompark.data.repository.mapper.fromRawList import com.biganto.visual.roompark.data.repository.mapper.fromRawList
import com.biganto.visual.roompark.domain.contract.FeedsContract import com.biganto.visual.roompark.domain.contract.FeedsContract
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.domain.model.ArticleModel import com.biganto.visual.roompark.domain.model.ArticleModel
import com.biganto.visual.roompark.domain.model.ArticlesPreviewModel import com.biganto.visual.roompark.domain.model.ArticlesPreviewModel
import com.biganto.visual.roompark.domain.model.FeedModel import com.biganto.visual.roompark.domain.model.FeedModel
...@@ -31,11 +30,11 @@ class FeedsContractModule @Inject constructor( ...@@ -31,11 +30,11 @@ class FeedsContractModule @Inject constructor(
override fun fetchFeeds(): Observable<List<FeedModel>> = override fun fetchFeeds(): Observable<List<FeedModel>> =
fetchAllFeeds().doOnError (::e) fetchAllFeeds().doOnError (::e)
override fun fetchFeedObservable(id: Int): Observable<ArticlesPreviewModel> = override fun fetchFeedObservable(feedAlias: String): Observable<ArticlesPreviewModel> =
fetchArticles(id) fetchArticles(feedAlias)
override fun fetchFeedObservable(id: Int,pageSize:Int, startIndex:Int) override fun fetchFeedObservable(feedAlias: String,pageSize:Int, startIndex:Int)
: Observable<ArticlesPreviewModel> = fetchArticles(id,pageSize,startIndex) : Observable<ArticlesPreviewModel> = fetchArticles(feedAlias,pageSize,startIndex)
override fun getArticle(id: Int): Observable<ArticleModel> = override fun getArticle(id: Int): Observable<ArticleModel> =
fetchArticle(id) fetchArticle(id)
...@@ -45,44 +44,36 @@ class FeedsContractModule @Inject constructor( ...@@ -45,44 +44,36 @@ class FeedsContractModule @Inject constructor(
} }
private fun fetchArticlessApi(feedId:Int,pageSize:Int, startIndex:Int): Observable<List<ArticleEntity>>? { private fun fetchArticlessApi(feedAlias:String,pageSize:Int, startIndex:Int)
val feed = db.getFeed(feedId).firstOrNull() : Observable<List<ArticleEntity>>? =api.getArticlesPage(
if (feed == null) { feedAlias
e("Unknown feedId: $feedId - cann't resolve feed_alias!") ,pageSize
throw CustomApiException.UnknownCustomApiException(-1,null,"Unknown Feed!") ,floor(startIndex.toDouble()/pageSize.toDouble()).toInt()+1
} )
else {
return api.getArticlesPage(
feed.alias
, pageSize
, floor(startIndex.toDouble()/pageSize.toDouble()).toInt()+1)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.map { it.items } .map { it.items }
.map { fromRaw(it, feedId) } .map { fromRaw(it, feedAlias) }
.doOnNext { Timber.d("raw enitites $it") } .doOnNext { Timber.d("raw enitites $it") }
.doOnNext(db::blockingUpsert) .doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
}
}
private fun fetchArticlesDb(feedId:Int,pageSize:Int, startIndex:Int): Observable<MutableList<ArticleEntity>>? {
val feed = db.getFeed(feedId).firstOrNull() private fun fetchArticlesDb(feedAlias: String,pageSize:Int, startIndex:Int)
Timber.d("db startindex: $startIndex") : Observable<MutableList<ArticleEntity>>? =
if (feed == null) { db.fetchArticles(feedAlias, pageSize, startIndex)
e("Unknown feedId: $feedId - cann't resolve feed_alias!")
throw CustomApiException.UnknownCustomApiException(-1, null, "Unknown Feed!")
} else return db.fetchArticles(feed.alias, pageSize, startIndex)
.toList() .toList()
.toObservable() .toObservable()
.doOnNext { Timber.d("db items: ${it.size}") } .doOnNext { Timber.d("db items: ${it.size}") }
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
}
private fun fetchArticles(feedId:Int,pageSize:Int = 10, startIndex:Int = 0): Observable<ArticlesPreviewModel> = private fun fetchArticles(feedAlias: String,pageSize:Int = 10, startIndex:Int = 0)
: Observable<ArticlesPreviewModel> =
Observable.mergeDelayError( Observable.mergeDelayError(
arrayListOf(fetchArticlessApi(feedId,pageSize,startIndex),fetchArticlesDb(feedId,pageSize,startIndex)) arrayListOf(fetchArticlessApi(feedAlias,pageSize
).map { fromEntity(feedId,it) } ,startIndex),fetchArticlesDb(feedAlias,pageSize,startIndex)
)
).map { fromEntity(feedAlias,it) }
private val fetchFeedsApi = private val fetchFeedsApi =
...@@ -106,10 +97,7 @@ class FeedsContractModule @Inject constructor( ...@@ -106,10 +97,7 @@ class FeedsContractModule @Inject constructor(
private fun fetchArticleApi(id:Int) = private fun fetchArticleApi(id:Int) =
api.getArticle(id) api.getArticle(id)
.doOnNext { Timber.d("raw0 $it") } .doOnNext { Timber.d("raw0 $it") }
.flatMap {article -> .map ( ::fromRaw )
db.getFeed(article.feed_alias).observable()
.map { fromRaw(article,it.id) }
}
.flatMap { article -> .flatMap { article ->
db.getArticle(article.id).observable() db.getArticle(article.id).observable()
.map { articleEntity -> .map { articleEntity ->
......
...@@ -40,12 +40,13 @@ interface IRoomParkApi { ...@@ -40,12 +40,13 @@ interface IRoomParkApi {
showElectric: Boolean showElectric: Boolean
): Observable<String> ): Observable<String>
fun getMultiTour(building: Int, flat: Int): Observable<List<PlanRaw>> fun getMultiTour(building: Int, flat: Int): Observable<Int>
fun getArticlesPage(feedName:String, fun getArticlesPage(feedName:String,
pageSize:Int = DEFAULT_ARTICLE_PAGE_SIZE, pageSize:Int = DEFAULT_ARTICLE_PAGE_SIZE,
page:Int): Observable<ArticlesListPaginationRaw> page:Int): Observable<ArticlesListPaginationRaw>
fun getAlbums(parentId: Int? = null): Observable<List<ImageAlbumRaw>> fun getAlbums(parentId: Int? = null): Observable<List<ImageAlbumRaw>>
fun getEstate(building: Int, flat: Int): Observable<EstateRaw>
} }
......
...@@ -107,13 +107,22 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi ...@@ -107,13 +107,22 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
) )
.compose(RetrofitResponseValidation()) .compose(RetrofitResponseValidation())
override fun getMultiTour(building: Int, flat: Int): Observable<List<PlanRaw>> =
@Deprecated("hidden by states.getEstate method")
override fun getMultiTour(building: Int, flat: Int): Observable<Int> =
api.getMultiTourId( api.getMultiTourId(
building = building, building = building,
flatNumber = flat flatNumber = flat
) )
.compose(RetrofitResponseValidation()) .compose(RetrofitResponseValidation())
override fun getEstate(building: Int, flat: Int): Observable<EstateRaw> =
api.getEstate(
building = building,
flatNumber = flat
)
.compose(RetrofitResponseValidation())
} }
enum class PlanTypeCatalog(val planId:Int, val planName:String ){ enum class PlanTypeCatalog(val planId:Int, val planName:String ){
......
...@@ -13,10 +13,11 @@ interface FeedsContract{ ...@@ -13,10 +13,11 @@ interface FeedsContract{
fun fetchFeeds(): Observable<List<FeedModel>> fun fetchFeeds(): Observable<List<FeedModel>>
fun getArticle(id:Int): Observable<ArticleModel> fun getArticle(id:Int): Observable<ArticleModel>
fun fetchFeedObservable(id: Int): Observable<ArticlesPreviewModel>
fun fetchFeedObservable( fun fetchFeedObservable(
id: Int, feedAlias: String,
pageSize: Int, pageSize: Int,
startIndex: Int startIndex: Int
): Observable<ArticlesPreviewModel> ): Observable<ArticlesPreviewModel>
fun fetchFeedObservable(feedAlias: String): Observable<ArticlesPreviewModel>
} }
\ No newline at end of file
...@@ -30,7 +30,7 @@ data class ArticlePreviewModel( ...@@ -30,7 +30,7 @@ data class ArticlePreviewModel(
} }
} }
data class ArticlesPreviewModel(val parentFeedId:Int,val articles:List<ArticlePreviewModel>) data class ArticlesPreviewModel(val parentFeedAlias:String,val articles:List<ArticlePreviewModel>)
data class ArticleModel( data class ArticleModel(
...@@ -58,7 +58,7 @@ fun fromEntity(entity: ArticleEntity):ArticlePreviewModel = ArticlePreviewModel( ...@@ -58,7 +58,7 @@ fun fromEntity(entity: ArticleEntity):ArticlePreviewModel = ArticlePreviewModel(
isRead = false isRead = false
) )
fun fromEntity(parentId:Int,entity: List<ArticleEntity>):ArticlesPreviewModel = fun fromEntity(parentId:String,entity: List<ArticleEntity>):ArticlesPreviewModel =
ArticlesPreviewModel( ArticlesPreviewModel(
parentFeedId = parentId, parentFeedId = parentId,
articles = fromEntity(entity,::fromEntity) articles = fromEntity(entity,::fromEntity)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment