-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Login feature #25
Login feature #25
Changes from 3 commits
418e1ad
0a67037
96a0879
1ee64ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
import java.util.Properties | ||
|
||
plugins { | ||
id("com.android.library") | ||
id("org.jetbrains.kotlin.android") | ||
alias(libs.plugins.kotlin.serialization) | ||
id("com.google.devtools.ksp") | ||
} | ||
|
||
val properties = Properties() | ||
properties.load(project.rootProject.file("local.properties").inputStream()) | ||
|
||
android { | ||
namespace = "com.example.data" | ||
compileSdk = 34 | ||
|
@@ -14,6 +19,9 @@ android { | |
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
|
||
buildConfigField("String", "api_key", properties["api_key"] as String) | ||
manifestPlaceholders["api_key"] = properties["api_key"] as String | ||
} | ||
|
||
buildTypes { | ||
|
@@ -32,6 +40,9 @@ android { | |
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
buildFeatures { | ||
buildConfig = true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
@@ -48,4 +59,12 @@ dependencies { | |
ksp(libs.hilt.android.compiler) | ||
|
||
implementation(project(":domain")) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
//retrofit | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:comment-spacing reported by reviewdog 🐶 |
||
implementation(libs.retrofit) | ||
implementation(libs.converter.gson) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
//okhttp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:comment-spacing reported by reviewdog 🐶 |
||
implementation(libs.okhttp) | ||
implementation(libs.logging.interceptor) | ||
} |
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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Provides | ||
fun provideOkHttp(): OkHttpClient { | ||
return OkHttpClient | ||
.Builder() | ||
.build() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Provides | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit { | ||
val gson = GsonBuilder() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 |
||
.setLenient() | ||
.create(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-semi reported by reviewdog 🐶 |
||
return Retrofit.Builder() | ||
.baseUrl("${BuildConfig.api_key}/api/") | ||
.addConverterFactory(GsonConverterFactory.create(gson)) | ||
.client(okHttpClient) | ||
.build() | ||
} | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Provides | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶 |
||
fun provideUserService(retrofit: Retrofit): UserService = retrofit.create(UserService::class.java) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶 |
||
} |
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 { | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
@Binds | ||
abstract fun bindLoginUseCase(loginUseCase: LoginUseCaseImpl) : LoginUseCase | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
} |
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, | ||
) |
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() | ||
} | ||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
) : CommonResponse<String> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
} |
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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-unused-imports reported by reviewdog 🐶 |
||
|
||
class LoginUseCaseImpl @Inject constructor( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:annotation reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:annotation reported by reviewdog 🐶 |
||
private val userService: UserService | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶 |
||
): LoginUseCase { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶 |
||
override suspend fun invoke(id: String, password: String): Result<String> = runCatching { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:function-signature reported by reviewdog 🐶 |
||
val requestBody = LoginParam(id, password).toRequestBody() | ||
userService.login(requestBody).data | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
import java.util.Properties | ||
|
||
plugins { | ||
id("com.android.library") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
val properties = Properties() | ||
properties.load(project.rootProject.file("local.properties").inputStream()) | ||
|
||
android { | ||
namespace = "com.example.domain" | ||
compileSdk = 34 | ||
|
@@ -12,6 +17,9 @@ android { | |
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
consumerProguardFiles("consumer-rules.pro") | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶 |
||
buildConfigField("String", "api_key", properties["api_key"] as String) | ||
manifestPlaceholders["api_key"] = properties["api_key"] as String | ||
} | ||
|
||
buildTypes { | ||
|
@@ -30,6 +38,9 @@ android { | |
kotlinOptions { | ||
jvmTarget = "17" | ||
} | ||
buildFeatures { | ||
buildConfig = true | ||
} | ||
} | ||
|
||
dependencies { | ||
|
@@ -41,4 +52,4 @@ dependencies { | |
androidTestImplementation(libs.androidx.junit) | ||
androidTestImplementation(libs.androidx.espresso.core) | ||
|
||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🚫 [ktlint] standard:no-trailing-spaces reported by reviewdog 🐶
Trailing space(s)