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
1 parent
064446b
commit 9f1c6a1
Showing
19 changed files
with
307 additions
and
2 deletions.
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
app/src/main/java/org/sopt/and/data/datasource/AuthDatasource.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,11 @@ | ||
package org.sopt.and.data.datasource | ||
|
||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.request.SignUpRequest | ||
import org.sopt.and.data.dto.response.SignUpResponse | ||
|
||
interface AuthDatasource { | ||
suspend fun postSignUp( | ||
request: SignUpRequest, | ||
): BaseResponse<SignUpResponse> | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/org/sopt/and/data/datasourceimpl/AuthDatasourceImpl.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.datasourceimpl | ||
|
||
import org.sopt.and.data.datasource.AuthDatasource | ||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.request.SignUpRequest | ||
import org.sopt.and.data.dto.response.SignUpResponse | ||
import org.sopt.and.data.service.AuthService | ||
import javax.inject.Inject | ||
|
||
class AuthDatasourceImpl @Inject constructor( | ||
private val authService: AuthService, | ||
) : AuthDatasource { | ||
override suspend fun postSignUp( | ||
request: SignUpRequest | ||
): BaseResponse<SignUpResponse> = authService.postSignUp(request) | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/sopt/and/data/di/DataSourceModule.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,17 @@ | ||
package org.sopt.and.data.di | ||
|
||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.datasource.AuthDatasource | ||
import org.sopt.and.data.datasourceimpl.AuthDatasourceImpl | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class DataSourceModule { | ||
@Binds | ||
@Singleton | ||
abstract fun bindAuthDataSource(authDatasourceImpl: AuthDatasourceImpl): AuthDatasource | ||
} |
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/sopt/and/data/di/RepositoryModule.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,17 @@ | ||
package org.sopt.and.data.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 bindAuthRepository(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,58 @@ | ||
package org.sopt.and.data.di | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.and.BuildConfig.BASE_URL | ||
import org.sopt.and.data.di.qualifier.Wavve | ||
import retrofit2.Converter | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object RetrofitModule { | ||
@Provides | ||
@Singleton | ||
fun provideJson(): Json = Json { | ||
ignoreUnknownKeys = true | ||
prettyPrint = true | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideJsonConverter(json: Json): Converter.Factory = | ||
json.asConverterFactory("application/json".toMediaType()) | ||
|
||
@Provides | ||
@Singleton | ||
fun provideLoggingInterceptor() = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideClient( | ||
loggingInterceptor: HttpLoggingInterceptor, | ||
) = OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.build() | ||
|
||
@Provides | ||
@Singleton | ||
@Wavve | ||
fun provideRetrofit( | ||
client: OkHttpClient, | ||
factory: Converter.Factory | ||
): Retrofit = Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(factory) | ||
.build() | ||
} |
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,19 @@ | ||
package org.sopt.and.data.di | ||
|
||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import org.sopt.and.data.di.qualifier.Wavve | ||
import org.sopt.and.data.service.AuthService | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ServiceModule { | ||
@Provides | ||
@Singleton | ||
fun provideAuthService(@Wavve retrofit: Retrofit): AuthService = | ||
retrofit.create(AuthService::class.java) | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/sopt/and/data/di/qualifier/RetrofitQualifier.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,7 @@ | ||
package org.sopt.and.data.di.qualifier | ||
|
||
import javax.inject.Qualifier | ||
|
||
@Qualifier | ||
@Retention(AnnotationRetention.BINARY) | ||
annotation class Wavve |
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,10 @@ | ||
package org.sopt.and.data.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class BaseResponse<T>( | ||
@SerialName("result") | ||
val result: T, | ||
) |
14 changes: 14 additions & 0 deletions
14
app/src/main/java/org/sopt/and/data/dto/request/SignUpRequest.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,14 @@ | ||
package org.sopt.and.data.dto.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SignUpRequest( | ||
@SerialName("username") | ||
val username: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("hobby") | ||
val hobby: String, | ||
) |
12 changes: 12 additions & 0 deletions
12
app/src/main/java/org/sopt/and/data/dto/response/SignUpResponse.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.data.dto.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class SignUpResponse( | ||
@SerialName("no") | ||
val no: Int? = null, | ||
@SerialName("code") | ||
val code: String? = null, | ||
) |
10 changes: 10 additions & 0 deletions
10
app/src/main/java/org/sopt/and/data/mapper/SignUpRequestMapper.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,10 @@ | ||
package org.sopt.and.data.mapper | ||
|
||
import org.sopt.and.data.dto.request.SignUpRequest | ||
import org.sopt.and.domain.entitiy.signup.SignUpRequestModel | ||
|
||
fun SignUpRequestModel.toSignUpRequestDto(): SignUpRequest = SignUpRequest( | ||
username = this.username, | ||
password = this.password, | ||
hobby = this.hobby, | ||
) |
9 changes: 9 additions & 0 deletions
9
app/src/main/java/org/sopt/and/data/mapper/SignUpResponseMapper.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,9 @@ | ||
package org.sopt.and.data.mapper | ||
|
||
import org.sopt.and.data.dto.response.SignUpResponse | ||
import org.sopt.and.domain.entitiy.signup.SignUpResponseModel | ||
|
||
fun SignUpResponse.toSignUpResponseModel(): SignUpResponseModel = SignUpResponseModel( | ||
no = this.no, | ||
code = this.code | ||
) |
28 changes: 28 additions & 0 deletions
28
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,28 @@ | ||
package org.sopt.and.data.repositoryimpl | ||
|
||
import org.sopt.and.data.datasource.AuthDatasource | ||
import org.sopt.and.data.mapper.toSignUpRequestDto | ||
import org.sopt.and.data.mapper.toSignUpResponseModel | ||
import org.sopt.and.domain.entitiy.signup.SignUpRequestModel | ||
import org.sopt.and.domain.entitiy.signup.SignUpResponseModel | ||
import org.sopt.and.domain.repository.AuthRepository | ||
import javax.inject.Inject | ||
|
||
class AuthRepositoryImpl @Inject constructor( | ||
private val authDatasource: AuthDatasource | ||
) : AuthRepository { | ||
override suspend fun postSignUp( | ||
username: String, | ||
password: String, | ||
hobby: String | ||
): Result<SignUpResponseModel> = | ||
kotlin.runCatching { | ||
authDatasource.postSignUp( | ||
SignUpRequestModel( | ||
username = username, | ||
password = password, | ||
hobby = hobby, | ||
).toSignUpRequestDto() | ||
).result.toSignUpResponseModel() | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
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,14 @@ | ||
package org.sopt.and.data.service | ||
|
||
import org.sopt.and.data.dto.BaseResponse | ||
import org.sopt.and.data.dto.request.SignUpRequest | ||
import org.sopt.and.data.dto.response.SignUpResponse | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface AuthService { | ||
@POST("user") | ||
suspend fun postSignUp( | ||
@Body body: SignUpRequest, | ||
): BaseResponse<SignUpResponse> | ||
} |
7 changes: 7 additions & 0 deletions
7
app/src/main/java/org/sopt/and/domain/entitiy/signup/SignUpRequestModel.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,7 @@ | ||
package org.sopt.and.domain.entitiy.signup | ||
|
||
data class SignUpRequestModel( | ||
val username: String, | ||
val password: String, | ||
val hobby: String, | ||
) |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/org/sopt/and/domain/entitiy/signup/SignUpResponseModel.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,6 @@ | ||
package org.sopt.and.domain.entitiy.signup | ||
|
||
data class SignUpResponseModel( | ||
val no: Int?, | ||
val code: String?, | ||
) |
11 changes: 11 additions & 0 deletions
11
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,11 @@ | ||
package org.sopt.and.domain.repository | ||
|
||
import org.sopt.and.domain.entitiy.signup.SignUpResponseModel | ||
|
||
interface AuthRepository { | ||
suspend fun postSignUp( | ||
username: String, | ||
password: String, | ||
hobby: String, | ||
): Result<SignUpResponseModel> | ||
} |
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