-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
aveek
committed
Jun 19, 2022
1 parent
00f1d7b
commit 4cbaf70
Showing
9 changed files
with
105 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
...imb/feature/login/LoginActivityHandler.kt → ...e/login/utilities/LoginActivityHandler.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
...ure/products/src/main/java/com/moneybox/minimb/feature/products/api/ProductDataService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> | ||
} |
36 changes: 36 additions & 0 deletions
36
...ure/products/src/main/java/com/moneybox/minimb/feature/products/data/ProductDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(){ | ||
|
||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...ure/products/src/main/java/com/moneybox/minimb/feature/products/data/ProductRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
feature/products/src/main/java/com/moneybox/minimb/feature/products/model/AccountResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
14 changes: 14 additions & 0 deletions
14
.../products/src/main/java/com/moneybox/minimb/feature/products/model/AllProductsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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>, | ||
) |
8 changes: 8 additions & 0 deletions
8
...oducts/src/main/java/com/moneybox/minimb/feature/products/model/ProductDetailsResponse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |