Skip to content

Commit

Permalink
Merge pull request #8 from AND-SOPT-ANDROID/week4
Browse files Browse the repository at this point in the history
Week4
  • Loading branch information
sayyyho authored Dec 8, 2024
2 parents 37ff795 + 9e716f4 commit dd450f5
Show file tree
Hide file tree
Showing 18 changed files with 557 additions and 98 deletions.
35 changes: 32 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
import java.util.Properties

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
id("kotlin-kapt")
id("com.google.dagger.hilt.android")
}


val properties = Properties().apply {
load(project.rootProject.file("local.properties").inputStream())
}

android {
Expand All @@ -16,6 +26,7 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
buildConfigField("String", "BASE_URL", properties["base.url"].toString())
}

buildTypes {
Expand All @@ -36,6 +47,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
}

Expand All @@ -49,14 +61,31 @@ dependencies {
implementation(libs.androidx.ui.graphics)
implementation(libs.androidx.ui.tooling.preview)
implementation(libs.androidx.material3)
implementation(libs.androidx.espresso.core)
implementation(libs.androidx.navigation.compose)

implementation(libs.androidx.navigation.runtime.ktx)
implementation(libs.androidx.runtime.livedata)
testImplementation(libs.junit)
androidTestImplementation(libs.androidx.junit)
androidTestImplementation(libs.androidx.espresso.core)
androidTestImplementation(platform(libs.androidx.compose.bom))
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
implementation(libs.androidx.lifecycle.viewmodel.compose)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.material)
// Network
implementation(platform(libs.okhttp.bom))
implementation(libs.okhttp)
implementation(libs.okhttp.logging.interceptor)
implementation(libs.retrofit)
implementation(libs.retrofit.kotlin.serialization.converter)
implementation(libs.kotlinx.serialization.json)
//hilt
implementation(libs.hilt.android.v2511)
kapt(libs.hilt.compiler.v2511)
implementation(libs.androidx.hilt.navigation.compose)
}

kapt {
correctErrorTypes = true
}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<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=".MyApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -11,6 +13,7 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ANDANDROID"
android:usesCleartextTraffic="true"
tools:targetApi="31">

<activity android:name=".MainActivity"
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/sopt/and/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ import org.sopt.and.signin.SignInScreen
import org.sopt.and.ui.theme.ANDANDROIDTheme
import org.sopt.and.viewmodel.SignViewModel

import dagger.hilt.android.AndroidEntryPoint
import dagger.hilt.android.HiltAndroidApp

@AndroidEntryPoint
class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
Expand Down
7 changes: 7 additions & 0 deletions app/src/main/java/org/sopt/and/MyApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.sopt.and

import android.app.Application
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class MyApplication : Application()
60 changes: 60 additions & 0 deletions app/src/main/java/org/sopt/and/api/Api.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package org.sopt.and.api

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
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ApiFactory {
private const val BASE_URL: String = BuildConfig.BASE_URL

@Provides
@Singleton
fun provideOkHttpClient(): OkHttpClient {
val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}
return OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build()
}

@Provides
@Singleton
fun provideRetrofit(client: OkHttpClient): Retrofit {
return Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

@Provides
@Singleton
fun provideUserRegistrationService(retrofit: Retrofit): UserRegistrationService {
return retrofit.create(UserRegistrationService::class.java)
}

@Provides
@Singleton
fun provideLoginService(retrofit: Retrofit): LoginService {
return retrofit.create(LoginService::class.java)
}

@Provides
@Singleton
fun provideHobbyService(retrofit: Retrofit): HobbyService {
return retrofit.create(HobbyService::class.java)
}

}
25 changes: 25 additions & 0 deletions app/src/main/java/org/sopt/and/api/Auth.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.and.api

import org.sopt.and.dto.RequestLoginData
import org.sopt.and.dto.RequestUserRegistrationData
import org.sopt.and.dto.ResponseLogin
import org.sopt.and.dto.ResponseUserRegistration
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST


interface UserRegistrationService {
@POST("/user")
suspend fun postUserRegistration(
@Body userRequest: RequestUserRegistrationData
): Response<ResponseUserRegistration>
}

interface LoginService {
@POST("/login")
suspend fun postLogin(
@Body loginRequeset: RequestLoginData
): Response<ResponseLogin>
}

13 changes: 13 additions & 0 deletions app/src/main/java/org/sopt/and/api/Hobby.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sopt.and.api

import org.sopt.and.dto.ResponseMyHobbyData
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Header

interface HobbyService {
@GET("/user/my-hobby")
suspend fun getHobby(
@Header("token") token: String?
): Response<ResponseMyHobbyData>
}
4 changes: 2 additions & 2 deletions app/src/main/java/org/sopt/and/components/SignButton.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ fun AuthSignButton(
buttonText: String,
validateAction: () -> Boolean,
onSuccess: () -> Unit,
onFailure: () -> Unit,
onFailure: () -> Unit, // @Composable 제거
modifier: Modifier = Modifier,
buttonColor: Color = Color.Blue
) {
Expand All @@ -28,7 +28,7 @@ fun AuthSignButton(
if (validateAction()) {
onSuccess()
} else {
onFailure()
onFailure() // 일반 함수 호출
}
}
},
Expand Down
9 changes: 5 additions & 4 deletions app/src/main/java/org/sopt/and/components/SignTextField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,20 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.input.PasswordVisualTransformation
import androidx.compose.ui.text.input.TextFieldValue
import androidx.compose.ui.text.input.VisualTransformation
import androidx.compose.ui.unit.sp

@Composable
fun CustomTextField(
labelResId: Int,
textValue: String,
onTextChanged: (String) -> Unit,
textValue: TextFieldValue,
onTextChanged: (TextFieldValue) -> Unit,
isPasswordField: Boolean = false,
isPasswordVisible: Boolean = false,
onPasswordToggle: (() -> Unit)? = null,
showHint: Boolean = false, // 추가된 파라미터
hintResId: Int? = null, // 추가된 파라미터
showHint: Boolean = false,
hintResId: Int? = null,
modifier: Modifier = Modifier
) {
Column {
Expand Down
48 changes: 48 additions & 0 deletions app/src/main/java/org/sopt/and/dto/Auth.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package org.sopt.and.dto

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/* 유저 등록 */
@Serializable
data class RequestUserRegistrationData(
@SerialName("username")
val userName: String,
@SerialName("password")
val password: String,
@SerialName("hobby")
val hobby: String
)

@Serializable
data class ResponseUserRegistration(
@SerialName("result")
val result: ResultUserNo
)

@Serializable
data class ResultUserNo(
@SerialName("no")
val no: Int
)

/* 로그인 */
@Serializable
data class RequestLoginData(
@SerialName("username")
val userName: String,
@SerialName("password")
val password: String
)

@Serializable
data class ResponseLogin(
@SerialName("result")
val result: ResultToken
)

@Serializable
data class ResultToken(
@SerialName("token")
val token: String
)
18 changes: 18 additions & 0 deletions app/src/main/java/org/sopt/and/dto/My.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.and.dto


import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/* 내 취미 조회 */
@Serializable
data class ResponseMyHobbyData(
@SerialName("result")
val result: ResponseMyHobbyDataResult
)

@Serializable
data class ResponseMyHobbyDataResult(
@SerialName("hobby")
val hobby: String
)
Loading

0 comments on commit dd450f5

Please sign in to comment.