Skip to content
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

Merged
merged 4 commits into from
Apr 18, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .github/workflows/android_ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ jobs:
cache: gradle

- name: Run tests
run: ./gradlew test
run: |
echo sdk.dir=~/Android/Sdk >> local.properties
echo api_key=\"${{ secrets.API_KEY }}\" >> local.properties
./gradlew test

- name: Upload test report
uses: actions/upload-artifact@v4
Expand Down Expand Up @@ -110,6 +113,7 @@ jobs:
- name: Grant execute permission for gradlew
run: |
echo sdk.dir=~/Android/Sdk >> local.properties
echo api_key=\"${{ secrets.API_KEY }}\" >> local.properties
chmod +x gradlew
- name: Build with Gradle
run: |
Expand Down
2 changes: 2 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,8 @@ dependencies {
implementation(libs.converter.gson)
implementation(libs.hilt.android)
ksp(libs.hilt.android.compiler)
ksp(libs.dagger.compiler) // Dagger compiler
ksp(libs.hilt.compiler) // Hilt compiler
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.orbit.viewmodel)
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

<uses-permission android:name="android.permission.INTERNET"/>

<application
android:name="com.example.app.App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:usesCleartextTraffic="true"
android:theme="@style/Theme.SnsProject"
tools:targetApi="31">

Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/com.example.app/App.kt
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()
19 changes: 19 additions & 0 deletions data/build.gradle.kts
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
Expand All @@ -14,6 +19,9 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")

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)

buildConfigField("String", "api_key", properties["api_key"] as String)
manifestPlaceholders["api_key"] = properties["api_key"] as String
}

buildTypes {
Expand All @@ -32,6 +40,9 @@ android {
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
buildConfig = true
}
}

dependencies {
Expand All @@ -48,4 +59,12 @@ dependencies {
ksp(libs.hilt.android.compiler)

implementation(project(":domain"))

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)

//retrofit

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:comment-spacing reported by reviewdog 🐶
Missing space after //

implementation(libs.retrofit)
implementation(libs.converter.gson)

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)

//okhttp

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:comment-spacing reported by reviewdog 🐶
Missing space after //

implementation(libs.okhttp)
implementation(libs.logging.interceptor)
}
40 changes: 40 additions & 0 deletions data/src/main/java/com/example/data/di/RetrofitModule.kt
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶
Class body should not start with blank line

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)

@Provides
fun provideOkHttp(): OkHttpClient {
return OkHttpClient
.Builder()
.build()
}

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)

@Provides

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

fun provideRetrofit(okHttpClient: OkHttpClient): Retrofit {
val gson = GsonBuilder()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

.setLenient()
.create();

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-semi reported by reviewdog 🐶
Unnecessary semicolon

return Retrofit.Builder()
.baseUrl("${BuildConfig.api_key}/api/")
.addConverterFactory(GsonConverterFactory.create(gson))
.client(okHttpClient)
.build()
}

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)

@Provides

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:blank-line-before-declaration reported by reviewdog 🐶
Expected a blank line for this declaration

fun provideUserService(retrofit: Retrofit): UserService = retrofit.create(UserService::class.java)

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)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-blank-line-before-rbrace reported by reviewdog 🐶
Unexpected blank line(s) before "}"

}
16 changes: 16 additions & 0 deletions data/src/main/java/com/example/data/di/UserModule.kt
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 {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-empty-first-line-in-class-body reported by reviewdog 🐶
Class body should not start with blank line

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)

@Binds
abstract fun bindLoginUseCase(loginUseCase: LoginUseCaseImpl) : LoginUseCase

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"

}
8 changes: 8 additions & 0 deletions data/src/main/java/com/example/data/model/CommonResponse.kt
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,
)
17 changes: 17 additions & 0 deletions data/src/main/java/com/example/data/model/LoginParam.kt
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 data/src/main/java/com/example/data/retrofit/UserService.kt
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

) : CommonResponse<String>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-return-type-spacing reported by reviewdog 🐶
Unexpected whitespace

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Unexpected spacing before ":"

}
16 changes: 16 additions & 0 deletions data/src/main/java/com/example/data/usecase/LoginUseCaseImpl.kt
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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:no-unused-imports reported by reviewdog 🐶
Unused import


class LoginUseCaseImpl @Inject constructor(

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:annotation reported by reviewdog 🐶
Expected newline before annotation

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:annotation reported by reviewdog 🐶
Expected newline after last annotation

private val userService: UserService

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:trailing-comma-on-declaration-site reported by reviewdog 🐶
Missing trailing comma before ")"

): LoginUseCase {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:colon-spacing reported by reviewdog 🐶
Missing spacing before ":"

override suspend fun invoke(id: String, password: String): Result<String> = runCatching {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-signature reported by reviewdog 🐶
Newline expected after opening parenthesis

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-signature reported by reviewdog 🐶
Parameter should start on a newline

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-signature reported by reviewdog 🐶
Newline expected before closing parenthesis

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:multiline-expression-wrapping reported by reviewdog 🐶
A multiline expression should start on a new line

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚫 [ktlint] standard:function-signature reported by reviewdog 🐶
Newline expected before expression body

val requestBody = LoginParam(id, password).toRequestBody()
userService.login(requestBody).data
}
}
13 changes: 12 additions & 1 deletion domain/build.gradle.kts
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
Expand All @@ -12,6 +17,9 @@ android {

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles("consumer-rules.pro")

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)

buildConfigField("String", "api_key", properties["api_key"] as String)
manifestPlaceholders["api_key"] = properties["api_key"] as String
}

buildTypes {
Expand All @@ -30,6 +38,9 @@ android {
kotlinOptions {
jvmTarget = "17"
}
buildFeatures {
buildConfig = true
}
}

dependencies {
Expand All @@ -41,4 +52,4 @@ dependencies {
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)

}
}
11 changes: 11 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ lifecycle-runtime-ktx = "2.7.0"
material = "1.11.0"

navigation-compose = "2.7.7"
okhttp = "4.12.0"
orbit-compose = "7.0.1"
orbit-core = "7.0.1"
orbit-test = "7.0.1"
orbit-viewmodel = "7.0.1"
paging-compose = "3.3.0-beta01"
paging-runtime = "3.2.1"
Expand Down Expand Up @@ -47,11 +51,14 @@ androidx-room-compiler = { module = "androidx.room:room-compiler", version.ref =
androidx-room-runtime = { module = "androidx.room:room-runtime", version.ref = "room-runtime" }
coil-compose = { module = "io.coil-kt:coil-compose", version.ref = "coil-compose" }
converter-gson = { module = "com.squareup.retrofit2:converter-gson", version.ref = "converter-gson" }
dagger-compiler = { module = "com.google.dagger:dagger-compiler", version.ref = "hilt-android" }
hilt-android = { module = "com.google.dagger:hilt-android", version.ref = "hilt-android" }
hilt-android-compiler = { module = "com.google.dagger:hilt-android-compiler", version.ref = "hilt-android" }
hilt-compiler = { module = "com.google.dagger:hilt-compiler", version.ref = "hilt-android" }
junit = { module = "junit:junit", version.ref = "junit" }
kotlinx-coroutines-core = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-core", version.ref = "kotlinx-coroutines-core" }
material = { module = "com.google.android.material:material", version.ref = "material" }
logging-interceptor = { module = "com.squareup.okhttp3:logging-interceptor", version.ref = "okhttp" }

androidx-compose-ui= { group = "androidx.compose.ui", name= "ui" }
androidx-compose-ui-graphics= { group = "androidx.compose.ui", name= "ui-graphics" }
Expand All @@ -61,6 +68,10 @@ androidx-compose-compose-bom = {group= "androidx.compose", name = "compose-bom",
androidx-compose-ui-ui-test-junit4 = {group="androidx.compose.ui", name="ui-test-junit4"}
androidx-compose-ui-ui-tooling = {group="androidx.compose.ui", name="ui-tooling"}
androidx-compose-ui-ui-test-manifest = {group="androidx.compose.ui", name="ui-test-manifest"}
okhttp = { module = "com.squareup.okhttp3:okhttp", version.ref = "okhttp" }
orbit-compose = { module = "org.orbit-mvi:orbit-compose", version.ref = "orbit-compose" }
orbit-core = { module = "org.orbit-mvi:orbit-core", version.ref = "orbit-core" }
orbit-test = { module = "org.orbit-mvi:orbit-test", version.ref = "orbit-test" }
orbit-viewmodel = { module = "org.orbit-mvi:orbit-viewmodel", version.ref = "orbit-viewmodel" }
retrofit = { module = "com.squareup.retrofit2:retrofit", version.ref = "retrofit" }

Expand Down
7 changes: 7 additions & 0 deletions presentation/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id("com.google.devtools.ksp")
alias(libs.plugins.ktlint)
alias(libs.plugins.kotlin.serialization)
id("com.google.dagger.hilt.android")
}

android {
Expand Down Expand Up @@ -67,5 +68,11 @@ dependencies {
ksp(libs.hilt.android.compiler)
implementation(libs.androidx.hilt.navigation.compose)
implementation(libs.androidx.navigation.compose)
ksp(libs.dagger.compiler) // Dagger compiler
ksp(libs.hilt.compiler) // Hilt compiler
implementation(project(":domain"))
implementation(libs.orbit.core)
implementation(libs.orbit.viewmodel)
implementation(libs.orbit.compose)
testImplementation(libs.orbit.test)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@ import androidx.compose.material3.TextFieldDefaults
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.dp

@Composable
fun LoginTextField(
modifier: Modifier,
value: String,
visualTransformation: VisualTransformation = VisualTransformation.None,
onValueString: (String) -> Unit,
) {
TextField(
Expand All @@ -27,5 +29,6 @@ fun LoginTextField(
disabledIndicatorColor = Color.Transparent,
),
shape = RoundedCornerShape(8.dp),
visualTransformation = visualTransformation,
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Bundle
import androidx.activity.compose.setContent
import androidx.appcompat.app.AppCompatActivity
import com.example.presentation.ui.theme.SnsProjectTheme
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
class LoginActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
Loading
Loading