Skip to content

Commit

Permalink
Product Integration - Init
Browse files Browse the repository at this point in the history
  • Loading branch information
aveek committed Jun 19, 2022
1 parent 00f1d7b commit 4cbaf70
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import androidx.activity.viewModels
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import com.google.android.material.snackbar.Snackbar
import com.moneybox.minimb.feature.login.LoginActivityHandler
import com.moneybox.minimb.feature.login.utilities.LoginActivityHandler
import com.moneybox.minimb.feature.login.R
import com.moneybox.minimb.feature.login.databinding.ActivityLoginBinding
import com.moneybox.minimb.feature.login.utilities.Utils.isNetworkAvailable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.moneybox.minimb.feature.login
package com.moneybox.minimb.feature.login.utilities

import android.text.TextUtils
import android.text.Editable
Expand Down
2 changes: 1 addition & 1 deletion feature/login/src/main/res/layout/activity_login.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<variable
name="handler"
type="com.moneybox.minimb.feature.login.LoginActivityHandler" />
type="com.moneybox.minimb.feature.login.utilities.LoginActivityHandler" />

<variable
name="viewModel"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.moneybox.minimb.feature.products.api


import com.moneybox.minimb.feature.products.model.AllProductsResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST

interface ProductDataService {

@GET("investorproducts")
suspend fun loginRequest(@Body user : Map<String , String>) : Response<AllProductsResponse>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package com.moneybox.minimb.feature.products.data

import com.google.gson.Gson
import com.moneybox.minimb.feature.products.api.ProductDataService
import com.moneybox.minimb.feature.products.model.AllProductsResponse
import com.moneybox.minimb.network.ApiResponseResult
import com.moneybox.minimb.network.ErrorResponseRemote
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import javax.inject.Inject

class ProductDataSource @Inject constructor(private val service : ProductDataService) {
suspend fun login(userMap: HashMap<String, String>): Flow<ApiResponseResult<AllProductsResponse>> {
return flow {
emit(ApiResponseResult.loading())
val result = service.loginRequest(userMap)
if (result.isSuccessful) {
emit(ApiResponseResult.success(data = result.body()))
} else {
val errorResponseRemote: ErrorResponseRemote =
Gson().fromJson(
result.errorBody()?.charStream(),
ErrorResponseRemote::class.java
)
errorResponseRemote?.let {
it.message?.let { msg ->
emit(ApiResponseResult.error(msg, result.code().toString()))
}
}
}
}
}
fun logout(){

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.moneybox.minimb.feature.products.data

import com.moneybox.minimb.feature.products.model.AllProductsResponse
import com.moneybox.minimb.network.ApiResponseResult
import kotlinx.coroutines.flow.Flow
import javax.inject.Inject

class ProductRepository @Inject constructor(private val loginDataSource: ProductDataSource) {
suspend fun login(userMap : HashMap<String, String>): Flow<ApiResponseResult<AllProductsResponse>> {
return loginDataSource.login(userMap)
}
fun logout() {
// user = null
loginDataSource.logout()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.moneybox.minimb.feature.products.model

import com.google.gson.annotations.SerializedName

data class ProductResponse(
@SerializedName("Id")
val id: Int,
@SerializedName("Product")
val product: ProductDetailsResponse,
@SerializedName("Moneybox")
val moneybox: Float,
@SerializedName("PlanValue")
val planValue: Float
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.moneybox.minimb.feature.products.model

import com.google.gson.annotations.SerializedName

data class AllProductsResponse(
@SerializedName("TotalPlanValue")
val totalPlanValue: Float,
@SerializedName("TotalEarnings")
val totalEarnings: Float,
@SerializedName("TotalEarningsAsPercentage")
val totalEarningsAsPercentage: Float? = null,
@SerializedName("ProductResponses")
val products: List<ProductResponse>,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.moneybox.minimb.feature.products.model

import com.google.gson.annotations.SerializedName

data class ProductDetailsResponse(
@SerializedName("FriendlyName")
val friendlyName: String
)

0 comments on commit 4cbaf70

Please sign in to comment.