generated from NOW-SOPT-ANDROID/now-sopt-android-template
-
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
1 parent
f639c9a
commit 06dbdef
Showing
12 changed files
with
81 additions
and
84 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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
37 changes: 37 additions & 0 deletions
37
app/src/main/java/com/sopt/now/data/repositoryimpl/AuthRepositoryImpl.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,37 @@ | ||
package com.sopt.now.data.repositoryimpl | ||
|
||
import com.sopt.now.data.api.AuthService | ||
import com.sopt.now.data.dto.response.BaseResponse | ||
import com.sopt.now.data.dto.toBaseResponseEntity | ||
import com.sopt.now.data.dto.toRequestLoginDto | ||
import com.sopt.now.data.dto.toRequestSignUpDto | ||
import com.sopt.now.data.repositoryimpl.extension.getResponseErrorMessage | ||
import com.sopt.now.data.repositoryimpl.extension.handleThrowable | ||
import com.sopt.now.domain.entity.ApiError | ||
import com.sopt.now.domain.entity.AuthRequestModel | ||
import com.sopt.now.domain.entity.BaseResponseEntity | ||
import com.sopt.now.domain.repository.AuthRepository | ||
import retrofit2.Response | ||
|
||
class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository { | ||
override suspend fun login(authData: AuthRequestModel): Result<Int?> = | ||
runCatching { | ||
val response: Response<BaseResponse<Unit>> = authService.login(authData.toRequestLoginDto()) | ||
if (response.isSuccessful) { | ||
response.headers()["location"]?.toInt() | ||
} | ||
else{ | ||
throw ApiError(response.getResponseErrorMessage()) | ||
} | ||
} | ||
|
||
override suspend fun signUp(authData: AuthRequestModel): Result<BaseResponseEntity> { | ||
return runCatching { | ||
authService.signUp(authData.toRequestSignUpDto()).toBaseResponseEntity() | ||
}.onFailure { throwable -> | ||
return throwable.handleThrowable() | ||
} | ||
} | ||
|
||
|
||
} |
2 changes: 1 addition & 1 deletion
2
...domain/entity/request/AuthRequestModel.kt → ...opt/now/domain/entity/AuthRequestModel.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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package com.sopt.now.domain.entity.request | ||
package com.sopt.now.domain.entity | ||
|
||
|
||
data class AuthRequestModel( | ||
|
9 changes: 4 additions & 5 deletions
9
app/src/main/java/com/sopt/now/domain/repository/AuthRepository.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 |
---|---|---|
@@ -1,10 +1,9 @@ | ||
package com.sopt.now.domain.repository | ||
|
||
import com.sopt.now.data.dto.response.BaseResponse | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import retrofit2.Response | ||
import com.sopt.now.domain.entity.AuthRequestModel | ||
import com.sopt.now.domain.entity.BaseResponseEntity | ||
|
||
interface AuthRepository { | ||
suspend fun logIn(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>> | ||
suspend fun signUp(authData: AuthRequestModel): Result<Response<BaseResponse<Unit>>> | ||
suspend fun login(authData: AuthRequestModel): Result<Int?> | ||
suspend fun signUp(authData: AuthRequestModel): Result<BaseResponseEntity> | ||
} |
8 changes: 3 additions & 5 deletions
8
app/src/main/java/com/sopt/now/domain/usecase/LogInUseCase.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 |
---|---|---|
@@ -1,12 +1,10 @@ | ||
package com.sopt.now.domain.usecase | ||
|
||
import com.sopt.now.data.dto.response.BaseResponse | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.entity.AuthRequestModel | ||
import com.sopt.now.domain.repository.AuthRepository | ||
import retrofit2.Response | ||
|
||
class LogInUseCase(private val authRepository: AuthRepository) { | ||
|
||
suspend operator fun invoke(request: AuthRequestModel):Result<Response<BaseResponse<Unit>>> = | ||
authRepository.logIn(request) | ||
suspend operator fun invoke(request: AuthRequestModel):Result<Int?> = | ||
authRepository.login(request) | ||
} |
7 changes: 3 additions & 4 deletions
7
app/src/main/java/com/sopt/now/domain/usecase/SignUpUseCase.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 |
---|---|---|
@@ -1,12 +1,11 @@ | ||
package com.sopt.now.domain.usecase | ||
|
||
import com.sopt.now.data.dto.response.BaseResponse | ||
import com.sopt.now.domain.entity.request.AuthRequestModel | ||
import com.sopt.now.domain.entity.AuthRequestModel | ||
import com.sopt.now.domain.entity.BaseResponseEntity | ||
import com.sopt.now.domain.repository.AuthRepository | ||
import retrofit2.Response | ||
|
||
class SignUpUseCase(private val authRepository: AuthRepository) { | ||
|
||
suspend operator fun invoke(request: AuthRequestModel):Result<Response<BaseResponse<Unit>>> = | ||
suspend operator fun invoke(request: AuthRequestModel):Result<BaseResponseEntity> = | ||
authRepository.signUp(request) | ||
} |
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
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
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