Commit 38f8b251 authored by Vladislav Bogdashkin's avatar Vladislav Bogdashkin 🎣

deals user dependencies workaround

parent 1bd9f768
......@@ -4,12 +4,14 @@ import com.biganto.visual.androidplayer.data.repository.local.ILocalStore
import com.biganto.visual.roompark.data.local.UserState
import com.biganto.visual.roompark.data.repository.api.IRoomParkApi
import com.biganto.visual.roompark.data.repository.db.IDb
import com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import com.biganto.visual.roompark.data.repository.file.FileModule
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.DealContract
import com.biganto.visual.roompark.domain.custom_exception.CustomApiException
import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import com.biganto.visual.roompark.domain.model.fromEntity
......@@ -23,6 +25,8 @@ import javax.inject.Inject
*/
//
const val TEST_DEAL_TOKEN =
"185|_Zs1k17uO_Ezn7wqZ8ostl8XJ5_G2rDez3x9F4qxj-do4wV1bxiUfLgOZZMUvc5guXScNN3Dr9yfNEBVvxGkQw=="
class EstateRepository @Inject constructor(
private val local: ILocalStore,
......@@ -189,4 +193,45 @@ class EstateRepository @Inject constructor(
// , electric:Boolean
// ) = api.getDirectPlan(estateId,planId,furniture,sizes,electric).
private val getDealsApi: Observable<List<DealEntity>> =
local.recentUser()
.flatMap {
when (it) {
is UserState.Authenticated -> db.fetchUser(it.uuid.toInt())
else -> throw CustomApiException.NotAuthorizedException()
}
}
.flatMap { user ->
api.getDeals(TEST_DEAL_TOKEN)//api.getDeals(user.authToken)
.doOnError(Timber::e)
.map { fromRawList(it, ::fromRaw) }
.doOnNext {
it.forEach { deal ->
deal.user = user
}
}
.doOnNext(db::blockingUpsert)
}
private val getDealsDb: Observable<List<DealEntity>> =
local.recentUser()
.flatMap {
when (it) {
is UserState.Authenticated -> db.fetchUser(it.uuid.toInt()).take(1)
else -> throw CustomApiException.NotAuthorizedException()
}
}
.map { it.deals?.map {deal -> deal as DealEntity } }
override fun getDeals(): Observable<List<DealModel>> {
return Observable.mergeDelayError(
arrayListOf(
getDealsDb, getDealsApi
)
).map { fromEntity(it, ::fromEntity) }
.doOnError(Timber::e)
}
}
......@@ -10,19 +10,19 @@ import io.requery.*
interface Deal : Persistable {
@get:Key
val id:String
val estateCrmId:String
val id:Int
val estateCrmId:Int
val opportunitySum:Int
val paymentSum:Int
val amountPaySum:Int
val statusId:Int
val managerName: String
@get:ForeignKey(references = Estate::class )
@get:OneToOne(cascade = [CascadeAction.NONE])
@get:OneToOne(cascade = [CascadeAction.SAVE])
var estate:Estate
@get:Nullable
@get:Column(name = "UserContainer")
@get:ForeignKey(references = User::class )
@get:OneToOne(mappedBy = "uuid",cascade = [CascadeAction.NONE])
@get:ManyToOne(cascade = [CascadeAction.NONE])
var user:User?
}
\ No newline at end of file
package com.biganto.visual.roompark.data.repository.db.requrey.model
import io.requery.Entity
import io.requery.Key
import io.requery.Persistable
import io.requery.Table
import io.requery.*
/**
* Created by Vladislav Bogdashkin on 29.10.2019.
......@@ -21,5 +18,11 @@ interface User : Persistable {
val authToken: String
val targetResolution: Int
// @get:ForeignKey(references = Deal::class )
@get:Nullable
@get:OneToMany(cascade = [CascadeAction.DELETE])
val deals:List<Deal>?
}
......@@ -93,6 +93,33 @@ fun fromRaw(raw:ResolutionRaw) =
fun fromRaw(raw:DealRaw,uuid:Int):DealEntity {
val user = UserEntity()
user.setUuid(uuid)
return fromRaw(raw,user)
}
fun fromRaw(raw:DealRaw):DealEntity {
val entity = DealEntity()
entity.setId(raw.id)
entity.setEstateCrmId(raw.estate_id)
entity.setOpportunitySum(raw.opportunity_sum)
entity.setPaymentSum(raw.payment_sum)
entity.setAmountPaySum(raw.amount_pay_sum)
entity.setStatusId(raw.status_id)
entity.setManagerName(raw.manager)
return entity
}
fun fromRaw(raw:DealRaw,user:UserEntity):DealEntity {
val entity = fromRaw(raw)
entity.estate = fromRaw(raw.estate)
entity.user = user
return entity
}
fun fromRaw(raw:EstateRaw):EstateEntity{
val entity = EstateEntity()
......
package com.biganto.visual.roompark.domain.contract
import com.biganto.visual.roompark.domain.model.DealModel
import com.biganto.visual.roompark.domain.model.EstateModel
import com.biganto.visual.roompark.domain.model.PlanPresetModel
import io.reactivex.Observable
......@@ -24,5 +25,5 @@ interface DealContract{
, electric:Boolean?): Observable<String>
fun getDeals(): Observable<List<DealModel>>
}
\ No newline at end of file
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.contract.DealContract
import com.biganto.visual.roompark.domain.model.*
import io.reactivex.Single
import io.reactivex.Observable
import javax.inject.Inject
/**
......@@ -9,10 +10,14 @@ import javax.inject.Inject
*/
class DealInteractor @Inject constructor(
val useCase : DealContract
){
fun getDeal(id:String) = Single.just(dealFlat)
fun getStatusList() = Single.just(statusList.sortedBy{ it.orderId })
fun getDeal(id:Int): Observable<DealModel> =
useCase.getDeals()
.map { it.first { it.id==id } }
fun getStatusList() = Observable.just(statusList.sortedBy{ it.orderId })
companion object{
......@@ -193,8 +198,8 @@ class DealInteractor @Inject constructor(
type = "flat",
url = "https://stage.room-park.ru:38386/choose/flat/1/14/1086/"
),
estate_id = "20dfe300-b85c-e711-80d7-00155d0a0a0e",
id = "9abdcb37-306a-e811-80e6-00155d0a0a0e",
estate_id = 2156,
id = 1562623,
managerName = "\u0411\u043e\u0441\u043e\u0432\u0430, \u0418\u0440\u0438\u043d\u0430",
opportunitySum= 5035860,
paymentSum= 500000,
......@@ -302,8 +307,8 @@ class DealInteractor @Inject constructor(
type = "flat",
url = "https://stage.room-park.ru:38386/choose/flat/1/2/88/"
),
estate_id = "54d7e300-b85c-e711-80d7-00155d0a0a0e",
id = "2419877b-2d6a-e811-80e6-00155d0a0a0e",
estate_id = 6222,
id = 42341,
managerName = "Босова, Ирина",
opportunitySum = 5618160,
paymentSum = 500000,
......
package com.biganto.visual.roompark.domain.interactor
import com.biganto.visual.roompark.domain.model.*
import io.reactivex.Single
import com.biganto.visual.roompark.domain.use_case.DealseUseCase
import io.reactivex.Observable
import javax.inject.Inject
/**
......@@ -9,10 +10,12 @@ import javax.inject.Inject
*/
class DealsInteractor @Inject constructor(
val useCase:DealseUseCase
){
fun fetchDeals() = Single.just(arrayListOf(dealFlat, dealParkign))
fun getStatusList() = Single.just(statusList.sortedBy{ it.orderId })
fun fetchDeals() = useCase.getDeals()
// Single.just(arrayListOf(dealFlat, dealParkign))
fun getStatusList() = Observable.just(statusList.sortedBy{ it.orderId })
companion object{
......@@ -67,6 +70,11 @@ class DealsInteractor @Inject constructor(
10,
"Договор находится в офисе продаж. Вы можете забрать его в любое время",
"Договор готов к выдаче"
),
StatusModel(
11,
"AAAA aa a a aAA a a",
"AAAA"
)
)
......@@ -187,8 +195,8 @@ class DealsInteractor @Inject constructor(
type = "flat",
url = "https://stage.room-park.ru:38386/choose/flat/1/14/1086/"
),
estate_id = "20dfe300-b85c-e711-80d7-00155d0a0a0e",
id = "9abdcb37-306a-e811-80e6-00155d0a0a0e",
estate_id = 1425,
id = 4621213,
managerName = "\u0411\u043e\u0441\u043e\u0432\u0430, \u0418\u0440\u0438\u043d\u0430",
opportunitySum= 5035860,
paymentSum= 500000,
......@@ -296,8 +304,8 @@ class DealsInteractor @Inject constructor(
type = "flat",
url = "https://stage.room-park.ru:38386/choose/flat/1/2/88/"
),
estate_id = "54d7e300-b85c-e711-80d7-00155d0a0a0e",
id = "2419877b-2d6a-e811-80e6-00155d0a0a0e",
estate_id = 1231,
id = 42342342,
managerName = "Босова, Ирина",
opportunitySum = 5618160,
paymentSum = 500000,
......
package com.biganto.visual.roompark.domain.model
import com.biganto.visual.roompark.data.repository.db.requrey.model.DealEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.EstateEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.ExplicationEntity
import com.biganto.visual.roompark.data.repository.db.requrey.model.PlanPreset
......@@ -20,8 +21,8 @@ data class StatusModel(
)
data class DealModel(
val id:String,
val estate_id:String,
val id:Int,
val estate_id:Int,
val opportunitySum:Int,
val paymentSum:Int,
val amount_pay_sum:Int,
......@@ -30,6 +31,17 @@ data class DealModel(
val estate:EstateModel
)
fun fromEntity(entity:DealEntity) = DealModel(
id = entity.id,
estate_id = entity.estateCrmId,
opportunitySum = entity.opportunitySum,
paymentSum = entity.paymentSum,
amount_pay_sum = entity.amountPaySum,
statusId = entity.statusId,
managerName = entity.managerName,
estate = fromEntity(entity.estate as EstateEntity)
)
data class EstateModel(
val id:Int,
......
package com.biganto.visual.roompark.domain.use_case
import com.biganto.visual.roompark.domain.contract.DealContract
import javax.inject.Inject
/**
* Created by Vladislav Bogdashkin on 24.09.2019.
*/
class DealseUseCase @Inject constructor(
private val contract: DealContract
) {
fun getDeals() = contract.getDeals()
}
\ No newline at end of file
......@@ -33,7 +33,7 @@ class DealScreenController :
constructor(args: Bundle):super(args)
constructor(id: String) : super(bundleOf(SELECTED_DEAL_ID_KEY to id))
constructor(id: Int) : super(bundleOf(SELECTED_DEAL_ID_KEY to id))
override fun injectDependencies() {
getComponent()
......@@ -161,7 +161,8 @@ class DealScreenController :
private fun getComponent() = DaggerDealScreenComponent.factory()
.create(RoomParkApplication.component,activity as RoomParkMainActivity
,args.getString(SELECTED_DEAL_ID_KEY)?: error("Deal Id is empty!"))
, args.getInt(SELECTED_DEAL_ID_KEY)
)
.inject(this)
override fun getLayoutId(): Int = R.layout.deal_screen
......
......@@ -22,7 +22,7 @@ interface DealScreenComponent {
fun create(
appComponent: AppComponent
,@BindsInstance activity: RoomParkMainActivity
,@BindsInstance @Named(SELECTED_DEAL_ID_KEY) selectedDealId:String
,@BindsInstance @Named(SELECTED_DEAL_ID_KEY) selectedDealId:Int
): DealScreenComponent
}
......
......@@ -22,7 +22,7 @@ import javax.inject.Named
class DealScreenPresenter @Inject constructor(
private val interactor: DealInteractor,
private val context: Context,
@Named(SELECTED_DEAL_ID_KEY) private val dealId:String
@Named(SELECTED_DEAL_ID_KEY) private val dealId:Int
)
: BigantoBasePresenter<DealScreen, DealScreenViewState>() {
......
......@@ -13,7 +13,7 @@ interface DealsScreen : BigantoBaseContract<DealsScreenViewState> {
data class DealPreviewModel(
val id:String,
val id:Int,
val type:String,
val name:String,
val building: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