Explorar o código

Forgot password API response issue resolved, now sending forgotPasswordRequest in a model instead of just String

Khubaib hai 2 semanas
pai
achega
6ed71d224e

+ 5 - 0
app/src/main/java/com/fastest/pass/forgotpassword/data/model/ForgotPasswordRequest.kt

@@ -0,0 +1,5 @@
+package com.fastest.pass.forgotpassword.data.model
+
+data class ForgotPasswordRequest(
+    val email: String
+)

+ 2 - 1
app/src/main/java/com/fastest/pass/forgotpassword/data/remote/ForgotPasswordApiService.kt

@@ -1,6 +1,7 @@
 package com.fastest.pass.forgotpassword.data.remote
 
 import com.fastest.pass.app.WebResponse
+import com.fastest.pass.forgotpassword.data.model.ForgotPasswordRequest
 import retrofit2.http.Body
 import retrofit2.http.Headers
 import retrofit2.http.POST
@@ -9,5 +10,5 @@ import java.util.Objects
 interface ForgotPasswordApiService {
 
     @POST("forgot-password")
-    suspend fun forgotPassword(@Body email: String) : WebResponse<Objects>
+    suspend fun forgotPassword(@Body forgotPasswordRequest: ForgotPasswordRequest) : WebResponse<Objects>
 }

+ 3 - 2
app/src/main/java/com/fastest/pass/forgotpassword/data/repository/ForgotPasswordRepositoryImpl.kt

@@ -1,6 +1,7 @@
 package com.fastest.pass.forgotpassword.data.repository
 
 import com.fastest.pass.app.WebResponse
+import com.fastest.pass.forgotpassword.data.model.ForgotPasswordRequest
 import com.fastest.pass.forgotpassword.data.remote.ForgotPasswordApiService
 import com.fastest.pass.forgotpassword.domain.repository.ForgotPasswordRepository
 import java.util.Objects
@@ -9,8 +10,8 @@ import javax.inject.Inject
 class ForgotPasswordRepositoryImpl @Inject constructor(
     private val forgotPasswordApiService: ForgotPasswordApiService
 ) : ForgotPasswordRepository{
-    override suspend fun forgotPasswordRepository(email: String): WebResponse<Objects> {
-        return forgotPasswordApiService.forgotPassword(email)
+    override suspend fun forgotPasswordRepository(forgotPasswordRequest: ForgotPasswordRequest): WebResponse<Objects> {
+        return forgotPasswordApiService.forgotPassword(forgotPasswordRequest)
     }
 
 }

+ 2 - 1
app/src/main/java/com/fastest/pass/forgotpassword/domain/repository/ForgotPasswordRepository.kt

@@ -1,8 +1,9 @@
 package com.fastest.pass.forgotpassword.domain.repository
 
 import com.fastest.pass.app.WebResponse
+import com.fastest.pass.forgotpassword.data.model.ForgotPasswordRequest
 import java.util.Objects
 
 interface ForgotPasswordRepository {
-    suspend fun forgotPasswordRepository(email: String) : WebResponse<Objects>
+    suspend fun forgotPasswordRepository(forgotPasswordRequest: ForgotPasswordRequest) : WebResponse<Objects>
 }

+ 5 - 2
app/src/main/java/com/fastest/pass/forgotpassword/domain/usecase/ForgotPasswordUseCase.kt

@@ -1,16 +1,19 @@
 package com.fastest.pass.forgotpassword.domain.usecase
 
+import android.util.Log
 import com.fastest.pass.app.BaseUseCase
 import com.fastest.pass.app.WebResponse
+import com.fastest.pass.forgotpassword.data.model.ForgotPasswordRequest
 import com.fastest.pass.forgotpassword.domain.repository.ForgotPasswordRepository
 import java.util.Objects
 import javax.inject.Inject
 
 class ForgotPasswordUseCase @Inject constructor(
     private val forgotPasswordRepository: ForgotPasswordRepository
-) : BaseUseCase<String, WebResponse<Objects>>(){
+) : BaseUseCase<ForgotPasswordRequest, WebResponse<Objects>>(){
 
-    override suspend fun execute(params: String): WebResponse<Objects> {
+    override suspend fun execute(params: ForgotPasswordRequest): WebResponse<Objects> {
+        Log.d("forgotPasswordResponse", "params = ${params.email}")
         return forgotPasswordRepository.forgotPasswordRepository(params)
     }
 }

+ 3 - 1
app/src/main/java/com/fastest/pass/forgotpassword/presentation/viewmodels/ForgotPasswordViewmodel.kt

@@ -8,6 +8,7 @@ import androidx.lifecycle.viewModelScope
 import com.fastest.pass.app.Result
 import com.fastest.pass.app.UIState
 import com.fastest.pass.app.WebResponse
+import com.fastest.pass.forgotpassword.data.model.ForgotPasswordRequest
 import com.fastest.pass.forgotpassword.domain.usecase.ForgotPasswordUseCase
 import com.fastest.pass.forgotpassword.utils.ForgotPasswordRoute
 import com.fastest.pass.login.utils.LoginRoute
@@ -30,7 +31,8 @@ class ForgotPasswordViewmodel @Inject constructor(
 
     fun forgotPassword(email: String) {
         viewModelScope.launch {
-            forgotPasswordUseCase(email) { result ->
+            val request = ForgotPasswordRequest(email)
+            forgotPasswordUseCase(request) { result ->
                 Log.d("forgotPasswordResponse", "result = $result")
                 when (result) {
                     is Result.Loading -> {

+ 11 - 0
app/src/main/java/com/fastest/pass/home/presentation/ui/fragment/HomeFragment.kt

@@ -1,6 +1,7 @@
 package com.fastest.pass.home.presentation.ui.fragment
 
 import android.os.Bundle
+import android.util.Log
 import android.view.LayoutInflater
 import android.view.View
 import android.view.ViewGroup
@@ -15,6 +16,7 @@ import androidx.compose.ui.res.colorResource
 import androidx.fragment.app.viewModels
 import com.fastest.pass.app.BaseFragment
 import com.fastest.pass.R
+import com.fastest.pass.helpers.BasePreferenceHelper
 import com.fastest.pass.home.presentation.ui.components.ClickType
 import com.fastest.pass.home.presentation.ui.components.HomeScreen
 import com.fastest.pass.home.presentation.viewmodels.HomeViewModel
@@ -31,6 +33,8 @@ class HomeFragment : BaseFragment() {
 
     @Inject
     lateinit var navigation: HomeNavigation
+    @Inject
+    lateinit var basePreferenceHelper: BasePreferenceHelper
 
     override fun onCreate(savedInstanceState: Bundle?) {
         super.onCreate(savedInstanceState)
@@ -53,6 +57,13 @@ class HomeFragment : BaseFragment() {
                                 .background(colorResource(id = R.color.home_background_color))
                                 .padding(paddingValues.calculateBottomPadding())
                         ) {
+                            val userinfo = basePreferenceHelper.getUserInfo()
+                            val id = userinfo?.id
+                            val email = userinfo?.email
+
+                            val saltKey = "$id$email"
+                            Log.d("saltKey", "saltKey = $saltKey")
+
                             HomeScreen { clickType ->
                                 when (clickType) {
                                     ClickType.GOTO_ADD_NEW_ITEMS -> {