Skip to content

Commit

Permalink
Merge pull request #164 from Team-Ampersand/feature/163_write_the_log…
Browse files Browse the repository at this point in the history
…ic_find_password

🔀 :: (#163) write the logic find password
  • Loading branch information
diejdkll authored Feb 29, 2024
2 parents 3227898 + a902f30 commit 7b5a23d
Show file tree
Hide file tree
Showing 23 changed files with 483 additions and 254 deletions.
2 changes: 2 additions & 0 deletions app/src/main/java/com/msg/dotori/DotoriNavHost.kt
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,13 @@ fun DotoriNavHost(
navigateToLogin = { navController.navigateToLogin() }
)
passwordAuthenticationScreen(
viewModelStoreOwner = viewModelStoreOwner,
navigateToBack = { navController.popBackStack() },
navigateToLogin = { navController.navigateToLogin() },
navigateToFindPassword = { navController.navigateToFindPassword() }
)
findPasswordScreen(
viewModelStoreOwner = viewModelStoreOwner,
navigateToBack = { navController.popBackStack() },
navigateToLogin = { navController.navigateToLogin() }
)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.data.remote.datasource.auth

import com.msg.data.remote.dto.auth.ChangePasswordRequest
import com.msg.data.remote.dto.auth.LoginRequest
import com.msg.data.remote.dto.auth.LoginResponse
import com.msg.data.remote.dto.auth.SignUpRequest
Expand All @@ -10,4 +11,6 @@ interface AuthDataSource {
suspend fun tokenReissue(): LoginResponse

suspend fun signUp(body: SignUpRequest)

suspend fun changePassword(body: ChangePasswordRequest)
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.data.remote.datasource.auth

import com.msg.data.remote.dto.auth.ChangePasswordRequest
import com.msg.data.remote.dto.auth.LoginRequest
import com.msg.data.remote.dto.auth.LoginResponse
import com.msg.data.remote.dto.auth.SignUpRequest
Expand All @@ -21,4 +22,8 @@ class AuthDataSourceImpl @Inject constructor(
override suspend fun signUp(body: SignUpRequest) = safeApiCall {
authApi.signUp(body)
}

override suspend fun changePassword(body: ChangePasswordRequest) = safeApiCall {
authApi.changePassword(body)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.msg.data.remote.dto.email.EmailVerifyRequest
import com.msg.data.remote.dto.email.SendEmailRequest

interface EmailDataSource {
suspend fun sendEmail(body: SendEmailRequest)
suspend fun sendSignUpEmail(body: SendEmailRequest)

suspend fun sendPasswordEmail(body: SendEmailRequest)

suspend fun emailVerify(body: EmailVerifyRequest)
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,12 @@ import javax.inject.Inject
class EmailDataSourceImpl @Inject constructor(
private val emailApi: EmailApi
): EmailDataSource {
override suspend fun sendEmail(body: SendEmailRequest) = safeApiCall {
emailApi.sendEmail(body)
override suspend fun sendSignUpEmail(body: SendEmailRequest) = safeApiCall {
emailApi.sendSignUpEmail(body)
}

override suspend fun sendPasswordEmail(body: SendEmailRequest) = safeApiCall {
emailApi.sendPasswordEmail(body)
}

override suspend fun emailVerify(body: EmailVerifyRequest) = safeApiCall {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.msg.data.remote.dto.auth

import com.msg.domain.model.auth.ChangePasswordRequestModel

data class ChangePasswordRequest(
val email: String,
val newPassword: String
)

fun ChangePasswordRequestModel.asChangePasswordRequest() = ChangePasswordRequest(
email = email,
newPassword = newPassword
)
6 changes: 6 additions & 0 deletions data/src/main/java/com/msg/data/remote/network/AuthApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.msg.data.remote.network
import com.msg.data.remote.dto.auth.LoginRequest
import com.msg.data.remote.dto.auth.LoginResponse
import com.msg.data.remote.dto.auth.SignUpRequest
import com.msg.data.remote.dto.auth.ChangePasswordRequest
import retrofit2.http.Body
import retrofit2.http.PATCH
import retrofit2.http.POST
Expand All @@ -20,4 +21,9 @@ interface AuthApi {
suspend fun signUp(
@Body body: SignUpRequest
)

@PATCH("auth/password")
suspend fun changePassword(
@Body body: ChangePasswordRequest
)
}
7 changes: 6 additions & 1 deletion data/src/main/java/com/msg/data/remote/network/EmailApi.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import retrofit2.http.POST

interface EmailApi {
@POST("email/signup")
suspend fun sendEmail(
suspend fun sendSignUpEmail(
@Body body: SendEmailRequest
)

@POST("email/password")
suspend fun sendPasswordEmail(
@Body body: SendEmailRequest
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ package com.msg.data.repository

import com.msg.data.local.datasource.LocalDataSource
import com.msg.data.remote.datasource.auth.AuthDataSource
import com.msg.data.remote.dto.auth.asChangePasswordRequest
import com.msg.data.remote.dto.auth.asLoginRequest
import com.msg.data.remote.dto.auth.asLoginResponseModel
import com.msg.data.remote.dto.auth.asSignUpRequest
import com.msg.domain.model.auth.ChangePasswordRequestModel
import com.msg.domain.model.auth.LoginRequestModel
import com.msg.domain.model.auth.LoginResponseModel
import com.msg.domain.model.auth.SignUpRequestModel
Expand Down Expand Up @@ -35,4 +37,6 @@ class AuthRepositoryImpl @Inject constructor(
override suspend fun getRole(): String = localDataSource.getRole().first()

override suspend fun signUp(body: SignUpRequestModel) = authDataSource.signUp(body.asSignUpRequest())

override suspend fun changePassword(body: ChangePasswordRequestModel) = authDataSource.changePassword(body.asChangePasswordRequest())
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@ import javax.inject.Inject
class EmailRepositoryImpl @Inject constructor(
private val emailDataSource: EmailDataSource
): EmailRepository {
override suspend fun sendEmail(body: SendEmailRequestModel) = emailDataSource.sendEmail(body.asSendEmailRequest())
override suspend fun sendSignUpEmail(body: SendEmailRequestModel) = emailDataSource.sendSignUpEmail(body.asSendEmailRequest())

override suspend fun sendPasswordEmail(body: SendEmailRequestModel) = emailDataSource.sendPasswordEmail(body.asSendEmailRequest())

override suspend fun emailVerify(body: EmailVerifyRequestModel) = emailDataSource.emailVerify(body.asEmailVerifyRequest())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.msg.domain.model.auth

data class ChangePasswordRequestModel(
val email: String,
val newPassword: String
)
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.msg.domain.repository

import com.msg.domain.model.auth.ChangePasswordRequestModel
import com.msg.domain.model.auth.LoginRequestModel
import com.msg.domain.model.auth.LoginResponseModel
import com.msg.domain.model.auth.SignUpRequestModel
Expand All @@ -20,4 +21,6 @@ interface AuthRepository {
suspend fun getRole(): String

suspend fun signUp(body: SignUpRequestModel)

suspend fun changePassword(body: ChangePasswordRequestModel)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import com.msg.domain.model.email.EmailVerifyRequestModel
import com.msg.domain.model.email.SendEmailRequestModel

interface EmailRepository {
suspend fun sendEmail(body: SendEmailRequestModel)
suspend fun sendSignUpEmail(body: SendEmailRequestModel)

suspend fun sendPasswordEmail(body: SendEmailRequestModel)

suspend fun emailVerify(body: EmailVerifyRequestModel)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.msg.domain.usecase.auth

import com.msg.domain.model.auth.ChangePasswordRequestModel
import com.msg.domain.repository.AuthRepository
import javax.inject.Inject

class ChangePasswordUseCase @Inject constructor(
private val repository: AuthRepository
) {
suspend operator fun invoke(body: ChangePasswordRequestModel) = kotlin.runCatching { repository.changePassword(body) }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.msg.domain.usecase.email

import com.msg.domain.model.email.SendEmailRequestModel
import com.msg.domain.repository.EmailRepository
import javax.inject.Inject

class SendPasswordEmailUseCase @Inject constructor(
private val repository: EmailRepository
) {
suspend operator fun invoke(body: SendEmailRequestModel) = kotlin.runCatching { repository.sendPasswordEmail(body) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import com.msg.domain.model.email.SendEmailRequestModel
import com.msg.domain.repository.EmailRepository
import javax.inject.Inject

class SendEmailUseCase @Inject constructor(
class SendSignUpEmailUseCase @Inject constructor(
private val repository: EmailRepository
) {
suspend operator fun invoke(body: SendEmailRequestModel) = kotlin.runCatching { repository.sendEmail(body) }
suspend operator fun invoke(body: SendEmailRequestModel) = kotlin.runCatching { repository.sendSignUpEmail(body) }
}
Loading

0 comments on commit 7b5a23d

Please sign in to comment.