Skip to content

Commit

Permalink
[feat] #7 유저 등록 API 연동
Browse files Browse the repository at this point in the history
  • Loading branch information
t1nm1ksun committed Nov 11, 2024
1 parent 41f912f commit b085182
Show file tree
Hide file tree
Showing 22 changed files with 259 additions and 69 deletions.
20 changes: 20 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
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)
}

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

android {
namespace = "org.sopt.and"
compileSdk = 34
Expand All @@ -17,6 +23,8 @@ android {
versionName = "1.0"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

buildConfigField("String", "BASE_URL", properties["base.url"].toString())
}

buildTypes {
Expand All @@ -37,6 +45,7 @@ android {
}
buildFeatures {
compose = true
buildConfig = true
}
composeOptions {
kotlinCompilerExtensionVersion = "1.4.0"
Expand Down Expand Up @@ -70,4 +79,15 @@ dependencies {
implementation(libs.kotlinx.serialization.json)
implementation(libs.kotlinx.collections.immutable)

// 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)
implementation(libs.retrofit.v2110)
implementation(libs.converter.gson)
implementation(libs.coil.compose)

}
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,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:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_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=".presentation.main.MainActivity"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.and.data.model.request

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

@Serializable
data class RequestSignUpDto(
@SerialName("username")
val username: String,
@SerialName("password")
val password: String,
@SerialName("hobby")
val hobby: String
)


Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.sopt.and.data.model.response

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


@Serializable
data class ResponseSignUpDto(
@SerialName("result")
val result: Result
) {
@Serializable
data class Result(
@SerialName("no")
val no: Int
)
}

@Serializable
data class ResponseSignUpFailedDto(
@SerialName("code")
val code: String
)
21 changes: 21 additions & 0 deletions app/src/main/java/org/sopt/and/data/service/RetrofitInstance.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.sopt.and.data.service

import org.sopt.and.BuildConfig
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory

object RetrofitInstance {
private const val BASE_URL = BuildConfig.BASE_URL

private val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.build()
}

val userService: UserService by lazy {
retrofit.create(UserService::class.java)
}
}

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

import org.sopt.and.data.model.request.RequestSignUpDto
import org.sopt.and.data.model.response.ResponseSignUpDto
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.POST


interface UserService {
@POST("/user")
suspend fun postSignup(@Body requestDto: RequestSignUpDto): Response<ResponseSignUpDto>
}
3 changes: 2 additions & 1 deletion app/src/main/java/org/sopt/and/domain/User.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ package org.sopt.and.domain

data class User(
var email: String = "",
var password: String = ""
var password: String = "",
var hobby: String = ""
)
18 changes: 12 additions & 6 deletions app/src/main/java/org/sopt/and/presentation/component/TextField.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ import androidx.compose.ui.unit.dp
import org.sopt.and.R

@Composable
fun EmailTextField(
userEmail: MutableState<String>,
fun BaseTextField(
text: MutableState<String>,
placeHolder: String,
onValueChange: (String) -> Unit = {},
modifier: Modifier = Modifier
) {
val containerColor = Color(0xFF2F2F2F)
OutlinedTextField(
modifier = modifier.fillMaxWidth(),
value = userEmail.value,
value = text.value,
onValueChange = { newValue ->
userEmail.value = newValue
text.value = newValue
onValueChange(newValue)
},
placeholder = {
Expand Down Expand Up @@ -112,17 +112,23 @@ fun PasswordTextField(
private fun TextFieldPreview() {
val userEmail = remember { mutableStateOf("") }
val userPassword = remember { mutableStateOf("") }
val userHobby = remember { mutableStateOf("") }
val passwordVisible = remember { mutableStateOf(false) }

Column {
EmailTextField(
userEmail = userEmail,
BaseTextField(
text = userEmail,
placeHolder = stringResource(id = R.string.sign_up_email_placeholder)
)

PasswordTextField(
userPassword = userPassword,
passwordVisible = passwordVisible,
placeHolder = stringResource(id = R.string.sign_up_password_placeholder)
)
BaseTextField(
text = userHobby,
placeHolder = stringResource(id = R.string.sign_up_hobby_placeholder)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import kotlinx.collections.immutable.ImmutableList
import kotlinx.collections.immutable.persistentListOf
import org.sopt.and.ImageRatio.LARGE
import org.sopt.and.ImageRatio.SMALL
import org.sopt.and.R
import org.sopt.and.util.ImageRatio.LARGE
import org.sopt.and.util.ImageRatio.SMALL

@Composable
fun HomeViewLazyRow(images: ImmutableList<Int>, modifier: Modifier = Modifier) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@ import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.lifecycle.ViewModelProvider
import org.sopt.and.ui.theme.ANDANDROIDTheme

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()

setContent {
ANDANDROIDTheme {
MainScreen()
}
}
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.compose.material.icons.filled.Home
import androidx.compose.material.icons.filled.Person
import androidx.compose.material.icons.filled.Search
import androidx.compose.ui.graphics.vector.ImageVector
import org.sopt.and.Route
import org.sopt.and.util.Route


sealed class BottomNavItem(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController
import org.sopt.and.Route
import org.sopt.and.util.Route

@Composable
fun BottomNavigationBar(
Expand All @@ -34,7 +34,7 @@ fun BottomNavigationBar(
modifier: Modifier = Modifier
) {
val backStackEntry = navController.currentBackStackEntryAsState()
Column (modifier = modifier.background(color = Color(0xFF1B1B1B))){
Column(modifier = modifier.background(color = Color(0xFF1B1B1B))) {
Text(
text = "첫 결제 시 첫 달 100원!",
textAlign = TextAlign.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.toRoute
import org.sopt.and.Route
import org.sopt.and.presentation.home.HomeScreen
import org.sopt.and.presentation.mypage.MyPageScreen
import org.sopt.and.presentation.search.SearchScreen
import org.sopt.and.presentation.signin.SignInScreen
import org.sopt.and.presentation.signup.SignUpScreen
import org.sopt.and.util.Route

@Composable
fun NavGraph(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import androidx.lifecycle.viewmodel.compose.viewModel
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import org.sopt.and.R
import org.sopt.and.presentation.component.EmailTextField
import org.sopt.and.presentation.component.BaseTextField
import org.sopt.and.presentation.component.PasswordTextField
import org.sopt.and.presentation.component.TopBar
import org.sopt.and.util.noRippleClickable
Expand Down Expand Up @@ -73,8 +73,8 @@ fun SignInScreen(
.fillMaxWidth()
.padding(horizontal = 11.dp)
) {
EmailTextField(
userEmail = userEmail,
BaseTextField(
text = userEmail,
placeHolder = stringResource(id = R.string.sign_in_email_placeholder),
)
Spacer(modifier = Modifier.height(10.dp))
Expand Down Expand Up @@ -120,6 +120,7 @@ fun SignInScreen(
navigateToSignUp()
})
}
Spacer(modifier = modifier.height(40.dp))
Image(
painter = painterResource(id = R.drawable.img_sign_up_image),
contentDescription = "로그인 이미지",
Expand Down
Loading

0 comments on commit b085182

Please sign in to comment.