Commit 692f8415 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

tours merge info

parent 72ab65f7
...@@ -68,4 +68,5 @@ interface IDb { ...@@ -68,4 +68,5 @@ interface IDb {
fun getFileEntitysOrDefault(uri: RevisionString): FileEntity fun getFileEntitysOrDefault(uri: RevisionString): FileEntity
fun getTourPreview(tourId: String): ReactiveResult<TourPreviewEntity> fun getTourPreview(tourId: String): ReactiveResult<TourPreviewEntity>
fun getTourPreviewsObservableResult(estateId: Int): Observable<ReactiveResult<TourPreviewEntity>> fun getTourPreviewsObservableResult(estateId: Int): Observable<ReactiveResult<TourPreviewEntity>>
fun getEstateTourPreviews(estateId: Int): Observable<List<TourPreviewEntity>>
} }
\ No newline at end of file
...@@ -209,6 +209,15 @@ class RequeryRepository @Inject constructor( ...@@ -209,6 +209,15 @@ class RequeryRepository @Inject constructor(
.where(TourPreviewEntity.ID.eq(tourId)) .where(TourPreviewEntity.ID.eq(tourId))
.get() .get()
override fun getEstateTourPreviews(estateId: Int): Observable<List<TourPreviewEntity>> = store
.select(TourPreviewEntity::class)
.where(TourPreviewEntity.ESTATE_ID.eq(estateId))
.get()
.observable()
.toList()
.toObservable()
.map { it.toList() }
override fun upsertTourPreview(list: List<TourPreviewEntity>) = store override fun upsertTourPreview(list: List<TourPreviewEntity>) = store
.upsert(list) .upsert(list)
.doOnSuccess { Timber.d("Upsertd succses %s", it.count()) } .doOnSuccess { Timber.d("Upsertd succses %s", it.count()) }
......
package com.biganto.visual.roompark.domain.interactor package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.use_case.DownloadUseCase import com.biganto.visual.roompark.domain.use_case.DownloadUseCase
import com.biganto.visual.roompark.domain.use_case.TourPreviewsUseCase
import javax.inject.Inject import javax.inject.Inject
/** /**
...@@ -8,9 +10,14 @@ import javax.inject.Inject ...@@ -8,9 +10,14 @@ import javax.inject.Inject
*/ */
class ToursInteractor @Inject constructor( class ToursInteractor @Inject constructor(
val downloadUseCase: DownloadUseCase val downloadUseCase: DownloadUseCase,
val tourUseCase:TourPreviewsUseCase
){ ){
fun getEstateTourList(estate:EstateModel){
tourUseCase.fetchTourOffer(estate.multitourId
?: error("Отсутсвуют виртуальные туры для данного объекта"),estate.id)
}
......
...@@ -2,7 +2,9 @@ package com.biganto.visual.roompark.domain.use_case ...@@ -2,7 +2,9 @@ package com.biganto.visual.roompark.domain.use_case
import android.content.res.Resources import android.content.res.Resources
import com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi import com.biganto.visual.roompark.data.repository.api.biganto.IBigantoApi
import com.biganto.visual.roompark.data.repository.api.biganto.raw.TourPreviewRaw
import com.biganto.visual.roompark.data.repository.db.IDb import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.domain.contract.AuthContract
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.domain.model.TourModel import com.biganto.visual.roompark.domain.model.TourModel
import com.biganto.visual.roompark.domain.model.fromEntity import com.biganto.visual.roompark.domain.model.fromEntity
...@@ -23,6 +25,7 @@ const val EMPTY_PARENT = -778 ...@@ -23,6 +25,7 @@ const val EMPTY_PARENT = -778
class TourPreviewsUseCase @Inject constructor( class TourPreviewsUseCase @Inject constructor(
private val api:IBigantoApi private val api:IBigantoApi
,private val db: IDb ,private val db: IDb
,private val auth:AuthContract
) { ) {
fun getTourById(tourId:String):Observable<DownloadTourByIdResult> { fun getTourById(tourId:String):Observable<DownloadTourByIdResult> {
...@@ -90,9 +93,75 @@ class TourPreviewsUseCase @Inject constructor( ...@@ -90,9 +93,75 @@ class TourPreviewsUseCase @Inject constructor(
, api.provideHttpUrl().toString() , api.provideHttpUrl().toString()
, requestModel.targetResolution) , requestModel.targetResolution)
} }
private fun fetchDbTourList(estateId: Int) =
db.getEstateTourPreviews(estateId)
private fun fetchApiTourList(multitourId:Int,estateId: Int) =
auth.currentUser().flatMap { user ->
api.getOfferTours(multitourId)
.map {
mergeRaw(it, TourRemoteRequestModel(
estateId,
api.provideHttpUrl().toString(),
user.targetResolution
)
)
}
.map { it }
.doOnNext { db.blockingUpsert(it) }
}
fun fetchTourOffer(multitourId:Int,parent:Int) =
Observable.mergeDelayError(
arrayListOf(fetchDbTourList(parent),fetchApiTourList(multitourId,parent))
)
.map { it }
.map (::fromEntity)
private fun mergeRaw(raw: List<TourPreviewRaw>, requestRequestModel: TourRemoteRequestModel) =
raw.map{ mergeRaw(it, requestRequestModel) }
private fun mergeRaw(raw: TourPreviewRaw, requestRequestModel: TourRemoteRequestModel)
: TourPreviewEntity {
val entity = db.getTourPreview(raw.id.toString()).firstOrNull()
?: return fromRaw(raw
, requestRequestModel.estateId
, api.provideHttpUrl().toString()
, requestRequestModel.targetResolution)
val fromApi = fromRaw(raw
, requestRequestModel.estateId
, api.provideHttpUrl().toString()
, requestRequestModel.targetResolution)
if (fromApi.updated > entity.updated
&& entity.isDownloaded == DownloadState.Downloaded) {
entity.isDownloaded =
DownloadState.NotSynced//maxState(entity.isDownloaded, fromApi.isDownloaded)
return entity
}
// In case< where we need to update tour parent, when it was downloaded by link
// if (fromApi.estate.id!=requestRequestModel.estateId)
// entity.estate=fromApi.estate
fromApi.setMetaFileEntityId(entity.metaFileEntityId)
fromApi.targetResolution=entity.targetResolution
fromApi.isDownloaded=entity.isDownloaded
fromApi.overallSize=entity.overallSize
fromApi.downloadedSize=entity.downloadedSize
fromApi.tempSize=entity.tempSize
fromApi.overallFiles=entity.overallFiles
fromApi.downloadedFiles=entity.downloadedFiles
return fromApi
}
} }
data class TourRemoteRequestModel(val estateId: String, val token: String? = null, val targetResolution: Int) data class TourRemoteRequestModel(val estateId: Int, val token: String? = null, val targetResolution: Int)
data class ToursRemoteByIdRequestModel(val ids: List<String>, val estateId: Int, data class ToursRemoteByIdRequestModel(val ids: List<String>, val estateId: Int,
......
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