generated from AND-SOPT-ANDROID/and-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
Showing
11 changed files
with
179 additions
and
29 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
app/src/main/java/org/sopt/and/data/datasource/remote/AuthRemoteDataSource.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,13 @@ | ||
package org.sopt.and.data.datasource.remote | ||
|
||
import org.sopt.and.data.model.request.RequestUserLoginDto | ||
import org.sopt.and.data.model.request.RequestUserRegisterDto | ||
import org.sopt.and.data.model.response.ResponseLoginTokenDto | ||
import org.sopt.and.data.model.response.ResponseRegisterNumberDto | ||
import org.sopt.and.presentation.util.BaseResponse | ||
|
||
interface AuthRemoteDataSource { | ||
suspend fun register(requestUserRegisterDto: RequestUserRegisterDto): BaseResponse<ResponseRegisterNumberDto> | ||
|
||
suspend fun login(requestUserLoginDto: RequestUserLoginDto): BaseResponse<ResponseLoginTokenDto> | ||
} |
20 changes: 20 additions & 0 deletions
20
app/src/main/java/org/sopt/and/data/datasourceImpl/remote/AuthRemoteDataSourceImpl.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,20 @@ | ||
package org.sopt.and.data.datasourceImpl.remote | ||
|
||
import org.sopt.and.data.datasource.remote.AuthRemoteDataSource | ||
import org.sopt.and.data.model.request.RequestUserLoginDto | ||
import org.sopt.and.data.model.request.RequestUserRegisterDto | ||
import org.sopt.and.data.model.response.ResponseLoginTokenDto | ||
import org.sopt.and.data.model.response.ResponseRegisterNumberDto | ||
import org.sopt.and.data.service.AuthService | ||
import org.sopt.and.presentation.util.BaseResponse | ||
import javax.inject.Inject | ||
|
||
class AuthRemoteDataSourceImpl @Inject constructor( | ||
private val authService: AuthService | ||
) : AuthRemoteDataSource { | ||
override suspend fun register(requestUserRegisterDto: RequestUserRegisterDto): BaseResponse<ResponseRegisterNumberDto> = | ||
authService.postRegister(requestUserRegisterDto) | ||
|
||
override suspend fun login(requestUserLoginDto: RequestUserLoginDto): BaseResponse<ResponseLoginTokenDto> = | ||
authService.postLogin(requestUserLoginDto) | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/sopt/and/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,16 @@ | ||
package org.sopt.and.data.repositoryImpl | ||
|
||
import org.sopt.and.data.datasource.remote.AuthRemoteDataSource | ||
import org.sopt.and.domain.model.UserIdEntity | ||
import org.sopt.and.domain.model.UserRegisterEntity | ||
import org.sopt.and.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
private val authRemoteDataSource: AuthRemoteDataSource | ||
) : AuthRepository { | ||
override suspend fun postRegister(userRegisterEntity: UserRegisterEntity): Result<UserIdEntity> = | ||
runCatching { | ||
authRemoteDataSource.register(requestUserRegisterDto = userRegisterEntity.toRequestUserRegisterDto()).result.toUserIdEntity() | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
app/src/main/java/org/sopt/and/data/service/AuthService.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,26 @@ | ||
package org.sopt.and.data.service | ||
|
||
import org.sopt.and.data.model.request.RequestUserLoginDto | ||
import org.sopt.and.data.model.request.RequestUserRegisterDto | ||
import org.sopt.and.data.model.response.ResponseLoginTokenDto | ||
import org.sopt.and.data.model.response.ResponseRegisterNumberDto | ||
import org.sopt.and.presentation.util.BaseResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("/$USER") | ||
suspend fun postRegister( | ||
@Body body: RequestUserRegisterDto | ||
): BaseResponse<ResponseRegisterNumberDto> | ||
|
||
@POST("/$LOGIN") | ||
suspend fun postLogin( | ||
@Body body: RequestUserLoginDto | ||
): BaseResponse<ResponseLoginTokenDto> | ||
|
||
companion object { | ||
const val USER = "user" | ||
const val LOGIN = "login" | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package org.sopt.and.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.repositoryImpl.AuthRepositoryImpl | ||
import org.sopt.and.domain.repository.AuthRepository | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class RepositoryModule { | ||
@Binds | ||
@Singleton | ||
abstract fun bindsAuthRepository(authRepositoryImpl: AuthRepositoryImpl): AuthRepository | ||
} |
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,18 @@ | ||
package org.sopt.and.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.service.AuthService | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ServiceModule { | ||
@Provides | ||
@Singleton | ||
fun providesAuthService(@Wave retrofit: Retrofit): AuthService = | ||
retrofit.create(AuthService::class.java) | ||
} |
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,18 @@ | ||
package org.sopt.and.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.domain.repository.AuthRepository | ||
import org.sopt.and.domain.usecase.PostUserRegisterUseCase | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
class UseCaseModule { | ||
@Provides | ||
@Singleton | ||
fun providesUserRegisterUseCase(authRepository: AuthRepository): PostUserRegisterUseCase = | ||
PostUserRegisterUseCase(authRepository = authRepository) | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/sopt/and/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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.domain.model.UserIdEntity | ||
import org.sopt.and.domain.model.UserRegisterEntity | ||
|
||
interface AuthRepository { | ||
suspend fun postRegister(userRegisterEntity: UserRegisterEntity): Result<UserIdEntity> | ||
} |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/sopt/and/domain/usecase/PostUserRegisterUseCase.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,12 @@ | ||
package org.sopt.and.domain.usecase | ||
|
||
import org.sopt.and.domain.model.UserIdEntity | ||
import org.sopt.and.domain.model.UserRegisterEntity | ||
import org.sopt.and.domain.repository.AuthRepository | ||
|
||
class PostUserRegisterUseCase( | ||
private val authRepository: AuthRepository | ||
) { | ||
suspend operator fun invoke(userRegisterEntity: UserRegisterEntity): Result<UserIdEntity> = | ||
authRepository.postRegister(userRegisterEntity = userRegisterEntity) | ||
} |
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