-
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.
Merge pull request #25 from Yoon-Chan/login-feature
Login feature
- Loading branch information
Showing
18 changed files
with
272 additions
and
18 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.example.app | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class App : Application() |
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,40 @@ | ||
package com.example.data.di | ||
|
||
import com.example.data.BuildConfig | ||
import com.example.data.retrofit.UserService | ||
import com.google.gson.GsonBuilder | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import okhttp3.OkHttpClient | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
class RetrofitModule { | ||
|
||
@Provides | ||
fun provideOkHttp(): OkHttpClient { | ||
return OkHttpClient | ||
.Builder() | ||
.build() | ||
} | ||
|
||
@Provides | ||
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit { | ||
val gson = GsonBuilder() | ||
.setLenient() | ||
.create(); | ||
return Retrofit.Builder() | ||
.baseUrl("${BuildConfig.api_key}/api/") | ||
.addConverterFactory(GsonConverterFactory.create(gson)) | ||
.client(okHttpClient) | ||
.build() | ||
} | ||
|
||
@Provides | ||
fun provideUserService(retrofit: Retrofit): UserService = retrofit.create(UserService::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,16 @@ | ||
package com.example.data.di | ||
|
||
import com.example.data.usecase.LoginUseCaseImpl | ||
import com.example.domain.usecase.login.LoginUseCase | ||
import dagger.Binds | ||
import dagger.Module | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
abstract class UserModule { | ||
|
||
@Binds | ||
abstract fun bindLoginUseCase(loginUseCase: LoginUseCaseImpl) : LoginUseCase | ||
} |
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 com.example.data.model | ||
|
||
data class CommonResponse<T>( | ||
val result: String, | ||
val data: T, | ||
val errorCode: String, | ||
val errorMessage: String, | ||
) |
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 com.example.data.model | ||
|
||
import com.google.gson.Gson | ||
import com.google.gson.annotations.SerializedName | ||
import okhttp3.RequestBody | ||
import okhttp3.RequestBody.Companion.toRequestBody | ||
|
||
data class LoginParam( | ||
@SerializedName("loginId") | ||
val loginId: String, | ||
@SerializedName("password") | ||
val password: String, | ||
) { | ||
fun toRequestBody(): RequestBody { | ||
return Gson().toJson(this).toRequestBody() | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
data/src/main/java/com/example/data/retrofit/UserService.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,15 @@ | ||
package com.example.data.retrofit | ||
|
||
import com.example.data.model.CommonResponse | ||
import okhttp3.RequestBody | ||
import retrofit2.http.Body | ||
import retrofit2.http.Headers | ||
import retrofit2.http.POST | ||
|
||
interface UserService { | ||
@POST("users/login") | ||
@Headers("Content-Type:application/json; charset=UTF-8") | ||
suspend fun login( | ||
@Body requestBody: RequestBody | ||
) : CommonResponse<String> | ||
} |
16 changes: 16 additions & 0 deletions
16
data/src/main/java/com/example/data/usecase/LoginUseCaseImpl.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 com.example.data.usecase | ||
|
||
import com.example.data.model.LoginParam | ||
import com.example.data.retrofit.UserService | ||
import com.example.domain.usecase.login.LoginUseCase | ||
import javax.inject.Inject | ||
import okhttp3.RequestBody | ||
|
||
class LoginUseCaseImpl @Inject constructor( | ||
private val userService: UserService | ||
): LoginUseCase { | ||
override suspend fun invoke(id: String, password: String): Result<String> = runCatching { | ||
val requestBody = LoginParam(id, password).toRequestBody() | ||
userService.login(requestBody).data | ||
} | ||
} |
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
Oops, something went wrong.