Skip to content

Commit

Permalink
Merge pull request #12 from Vaibhav2002/callbacks_to_coroutines_migra…
Browse files Browse the repository at this point in the history
…tion

Callbacks to coroutines migration
  • Loading branch information
hellosagar authored Oct 6, 2022
2 parents abec3cc + 504a09a commit c33b0f4
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,4 @@ amplify/backend/api/sampleapi/transform.conf.json
app/src/main/java/dev/amplifyframework/
app/src/main/java/dev/sagar/assigmenthub/data/entities/
app/src/main/java/dev/sagar/assigmenthub/data/remote/
app/src/main/res/mipmap-anydpi-v26/
app/src/main/res/mipmap-anydpi-v26/
16 changes: 0 additions & 16 deletions .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 1 addition & 3 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -7,86 +7,82 @@ import com.amplifyframework.auth.options.AuthSignUpOptions
import dev.sagar.assigmenthub.utils.ResponseModel
import timber.log.Timber
import javax.inject.Inject
import kotlin.coroutines.resume
import kotlin.coroutines.suspendCoroutine

class AuthRepo @Inject constructor(
private val auth: AuthCategory
) {

fun signUpTeacher(
suspend fun signUpTeacher(
email: String,
name: String,
password: String,
callback: (ResponseModel<String>) -> Unit
) {

val attributes: ArrayList<AuthUserAttribute> = ArrayList()
attributes.add(AuthUserAttribute(AuthUserAttributeKey.email(), email))
attributes.add(AuthUserAttribute(AuthUserAttributeKey.name(), name))

password: String
) = suspendCoroutine<ResponseModel<String>> {
val attributes = listOf(
AuthUserAttribute(AuthUserAttributeKey.email(), email),
AuthUserAttribute(AuthUserAttributeKey.name(), name)
)
auth.signUp(
email,
password,
AuthSignUpOptions.builder().userAttributes(attributes).build(),
{ result ->
Timber.i("signUpTeacher result: $result")
callback(ResponseModel.Success("Teacher signUp"))
it.resume(ResponseModel.Success("Teacher signUp"))
},
{ error ->
Timber.e("signUpTeacher error $error")
callback(ResponseModel.Error(error, error.recoverySuggestion))
it.resume(ResponseModel.Error(error, error.recoverySuggestion))
}
)
}

fun signInTeacher(
suspend fun signInTeacher(
email: String,
password: String,
callback: (ResponseModel<String>) -> Unit
) {

password: String
) = suspendCoroutine<ResponseModel<String>> {
auth.signIn(
email,
password,
{ result ->
Timber.i("signInTeacher $result")
callback(ResponseModel.Success("Teacher signIn $result"))
it.resume(ResponseModel.Success("Teacher signIn $result"))
},
{ error ->
Timber.e("signInTeacher $error) ")
callback(ResponseModel.Error(error, error.recoverySuggestion))
it.resume(ResponseModel.Error(error, error.recoverySuggestion))
}
)
}

fun confirmTeacher(
suspend fun confirmTeacher(
email: String,
otp: String,
callback: (ResponseModel<String>) -> Unit
) {

otp: String
) = suspendCoroutine<ResponseModel<String>> {
auth.confirmSignUp(
email,
otp,
{ result ->
Timber.i("confirmTeacher $result")
callback(ResponseModel.Success("Teacher confirmed!"))
it.resume(ResponseModel.Success("Teacher confirmed!"))
},
{ error ->
Timber.e("confirmTeacher $error")
callback(ResponseModel.Error(error, error.recoverySuggestion))
it.resume(ResponseModel.Error(error, error.recoverySuggestion))
}
)
}

fun signOutTeacher(callback: (ResponseModel<String>) -> Unit) {
suspend fun signOutTeacher() = suspendCoroutine<ResponseModel<String>> {
auth.signOut(
{
Timber.i("signOutTeacher success")
callback(ResponseModel.Success("signOutTeacher success"))
it.resume(ResponseModel.Success("signOutTeacher success"))
},
{ error ->
Timber.e("signOutTeacher $error")
callback(ResponseModel.Error(error, error.recoverySuggestion))
it.resume(ResponseModel.Error(error, error.recoverySuggestion))
}
)
}
Expand Down
Loading

0 comments on commit c33b0f4

Please sign in to comment.