Commit eb714450 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

added webCam api impl

parent 4d0a9bdf
......@@ -45,6 +45,7 @@ class AlbumsContractModule @Inject constructor(
}
//region allAlbums
private val fetchTopLevelAlbumsApi =
api.getAlbums()
.doOnNext { Timber.d("raw0 $it") }
......@@ -64,7 +65,10 @@ class AlbumsContractModule @Inject constructor(
arrayListOf(fetchTopLevelAlbumsApi,fetchTopLevelAlbumsDb)
).doOnNext { Timber.d("got entity $it") }.map { fromEntity(it,::fromEntity) }
//endregion allAlbums
//region concrete Albums
private fun fetchAlbumsApi(parentAlbumId:Int) =
api.getAlbums(parentAlbumId)
.doOnNext { Timber.d("raw0 $it") }
......@@ -94,5 +98,39 @@ class AlbumsContractModule @Inject constructor(
arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId))
).map { fromEntity(it,::fromEntity) }
//endregion concrete Albums
//region cams
private fun fetchWebCamsApi() =
api.get()
.doOnNext { Timber.d("raw0 $it") }
.map{ fromRawList(it,::fromRaw) }
.doOnNext(db::blockingUpsert)
.doOnNext {
it.asSequence().map { album ->
if (db.checkIfExistsAlbumJunction(album.id, parentAlbumId) != null) {
return@map null
}
val entity = ImageAlbumJunctionEntity()
entity.setAlbumId(album.id)
entity.setParentId(parentAlbumId)
entity
}.filterNotNull().toList().also { junctions -> db.blockingUpsert(junctions) }
}
.subscribeOn(Schedulers.io())
private fun fetchAlbumsDb(parentAlbumId:Int) =
db.getChildAlbums(parentAlbumId)
.toList()
.toObservable()
.subscribeOn(Schedulers.io())
private fun fetchAlbums(parentId:Int): Observable<List<AlbumPreviewModel>> =
Observable.mergeDelayError(
arrayListOf(fetchAlbumsApi(parentId),fetchAlbumsDb(parentId))
).map { fromEntity(it,::fromEntity) }
//endregion
}
......@@ -47,6 +47,7 @@ interface IRoomParkApi {
fun getAlbums(parentId: Int? = null): Observable<List<ImageAlbumRaw>>
fun getEstate(building: Int, flat: Int): Observable<EstateRaw>
fun getWebCamsList(): Observable<List<WebCamRaw>>
}
......
......@@ -133,6 +133,9 @@ interface IRoomParkMobileApi{
const val ESTATE_FLAT_NUMBER_PARAM="number "
//endregion
//region Get Web Cams
const val GET_WEB_CAMS_METHOD="webcams.getCameras"
//endregion
}
......@@ -193,6 +196,15 @@ interface IRoomParkMobileApi{
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION
): Observable<Response<List<FeedRaw>>>
@GET("$API_URL$GET_WEB_CAMS_METHOD$DELIMITER")
fun getWebCams(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
@Query(CLIENT_VERSION_PARAM) clientVersion: String = DEFAULT_CLIENT_VERSION,
@Query(API_VERSION_PARAM) apiVersion: String = DEFAULT_API_VERSION
): Observable<Response<List<WebCamRaw>>>
@GET("$API_URL$GET_ARTICLES_PAGE_METHOD$DELIMITER")
fun getArticlesPage(
@Query(CLIENT_TYPE_PARAM) clientType: String = DEFAULT_CLIENT_TYPE,
......
......@@ -80,6 +80,11 @@ class RetrofitRepository @Inject constructor(retrofit: Retrofit) : IRoomParkApi
.subscribeOn(Schedulers.io())
.compose(RetrofitResponseValidation())
override fun getWebCamsList(): Observable<List<WebCamRaw>> =
api.getWebCams()
.subscribeOn(Schedulers.io())
.compose(RetrofitResponseValidation())
override fun getPhotos(parentId: Int): Observable<List<NewsPhotoRaw>> =
api.getPhotos(id = parentId)
.subscribeOn(Schedulers.io())
......
package com.biganto.visual.roompark.domain.use_case
import com.biganto.visual.roompark.domain.contract.DevProgressContract
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
class CamsUseCase @Inject constructor(
private val contract: DevProgressContract
){
fun getWebCams() = contract.getWebCamsList()
fun getCam(camId:Int) =
contract.getWebCamStream(camId)
}
\ No newline at end of file
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