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
import com.biganto.visual.roompark.data.repository.mapper.fromRaw
import com.biganto.visual.roompark.data.repository.mapper.fromRawList
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.ArticlesPreviewModel
import com.biganto.visual.roompark.domain.model.FeedModel
......@@ -31,11 +30,11 @@ class FeedsContractModule @Inject constructor(
override fun fetchFeeds(): Observable<List<FeedModel>> =
fetchAllFeeds().doOnError (::e)
override fun fetchFeedObservable(id: Int): Observable<ArticlesPreviewModel> =
fetchArticles(id)
override fun fetchFeedObservable(feedAlias: String): Observable<ArticlesPreviewModel> =
fetchArticles(feedAlias)
override fun fetchFeedObservable(id: Int,pageSize:Int, startIndex:Int)
: Observable<ArticlesPreviewModel> = fetchArticles(id,pageSize,startIndex)
override fun fetchFeedObservable(feedAlias: String,pageSize:Int, startIndex:Int)
: Observable<ArticlesPreviewModel> = fetchArticles(feedAlias,pageSize,startIndex)
override fun getArticle(id: Int): Observable<ArticleModel> =
fetchArticle(id)
......@@ -45,44 +44,36 @@ class FeedsContractModule @Inject constructor(
}
private fun fetchArticlessApi(feedId:Int,pageSize:Int, startIndex:Int): Observable<List<ArticleEntity>>? {
val feed = db.getFeed(feedId).firstOrNull()
if (feed == null) {
e("Unknown feedId: $feedId - cann't resolve feed_alias!")
throw CustomApiException.UnknownCustomApiException(-1,null,"Unknown Feed!")
}
else {
return api.getArticlesPage(
feed.alias
, pageSize
, floor(startIndex.toDouble()/pageSize.toDouble()).toInt()+1)
private fun fetchArticlessApi(feedAlias:String,pageSize:Int, startIndex:Int)
: Observable<List<ArticleEntity>>? =api.getArticlesPage(
feedAlias
,pageSize
,floor(startIndex.toDouble()/pageSize.toDouble()).toInt()+1
)
.doOnNext { Timber.d("raw0 $it") }
.map { it.items }
.map { fromRaw(it, feedId) }
.map { fromRaw(it, feedAlias) }
.doOnNext { Timber.d("raw enitites $it") }
.doOnNext(db::blockingUpsert)
.subscribeOn(Schedulers.io())
}
}
private fun fetchArticlesDb(feedId:Int,pageSize:Int, startIndex:Int): Observable<MutableList<ArticleEntity>>? {
val feed = db.getFeed(feedId).firstOrNull()
Timber.d("db startindex: $startIndex")
if (feed == null) {
e("Unknown feedId: $feedId - cann't resolve feed_alias!")
throw CustomApiException.UnknownCustomApiException(-1, null, "Unknown Feed!")
} else return db.fetchArticles(feed.alias, pageSize, startIndex)
private fun fetchArticlesDb(feedAlias: String,pageSize:Int, startIndex:Int)
: Observable<MutableList<ArticleEntity>>? =
db.fetchArticles(feedAlias, pageSize, startIndex)
.toList()
.toObservable()
.doOnNext { Timber.d("db items: ${it.size}") }
.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(
arrayListOf(fetchArticlessApi(feedId,pageSize,startIndex),fetchArticlesDb(feedId,pageSize,startIndex))
).map { fromEntity(feedId,it) }
arrayListOf(fetchArticlessApi(feedAlias,pageSize
,startIndex),fetchArticlesDb(feedAlias,pageSize,startIndex)
)
).map { fromEntity(feedAlias,it) }
private val fetchFeedsApi =
......@@ -106,10 +97,7 @@ class FeedsContractModule @Inject constructor(
private fun fetchArticleApi(id:Int) =
api.getArticle(id)
.doOnNext { Timber.d("raw0 $it") }
.flatMap {article ->
db.getFeed(article.feed_alias).observable()
.map { fromRaw(article,it.id) }
}
.map ( ::fromRaw )
.flatMap { article ->
db.getArticle(article.id).observable()
.map { articleEntity ->
......
......@@ -40,12 +40,13 @@ interface IRoomParkApi {
showElectric: Boolean
): Observable<String>
fun getMultiTour(building: Int, flat: Int): Observable<List<PlanRaw>>
fun getMultiTour(building: Int, flat: Int): Observable<Int>
fun getArticlesPage(feedName:String,
pageSize:Int = DEFAULT_ARTICLE_PAGE_SIZE,
page:Int): Observable<ArticlesListPaginationRaw>
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
)
.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(
building = building,
flatNumber = flat
)
.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 ){
......
......@@ -13,10 +13,11 @@ interface FeedsContract{
fun fetchFeeds(): Observable<List<FeedModel>>
fun getArticle(id:Int): Observable<ArticleModel>
fun fetchFeedObservable(id: Int): Observable<ArticlesPreviewModel>
fun fetchFeedObservable(
id: Int,
feedAlias: String,
pageSize: Int,
startIndex: Int
): Observable<ArticlesPreviewModel>
fun fetchFeedObservable(feedAlias: String): Observable<ArticlesPreviewModel>
}
\ No newline at end of file
......@@ -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(
......@@ -58,7 +58,7 @@ fun fromEntity(entity: ArticleEntity):ArticlePreviewModel = ArticlePreviewModel(
isRead = false
)
fun fromEntity(parentId:Int,entity: List<ArticleEntity>):ArticlesPreviewModel =
fun fromEntity(parentId:String,entity: List<ArticleEntity>):ArticlesPreviewModel =
ArticlesPreviewModel(
parentFeedId = parentId,
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