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

Week4 #8

Open
wants to merge 11 commits into
base: develop
Choose a base branch
from
Open
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
19 changes: 16 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
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
compileSdk = 35

defaultConfig {
applicationId = "org.sopt.and"
minSdk = 28
targetSdk = 34
targetSdk = 35
versionCode = 1
versionName = "1.0"

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

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

Expand Down Expand Up @@ -65,4 +72,10 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
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)
}
23 changes: 4 additions & 19 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,26 +13,9 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.ANDANDROID"
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".MyActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".HomeActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".SearchActivity"
android:exported="false" />

<activity
android:name=".MainActivity"
android:exported="true"
Expand Down
37 changes: 18 additions & 19 deletions app/src/main/java/org/sopt/and/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,20 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.runtime.remember
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.ui.Modifier
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewmodel.compose.viewModel
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.rememberNavController
import org.sopt.and.ui.theme.ANDANDROIDTheme
import androidx.navigation.compose.composable
import androidx.navigation.toRoute

//๋กœ๊ทธ์ธ ์„ฑ๊ณต ์‹œ ๋กœ๊ทธ์ธํ•œ ์ด๋ฉ”์ผ์„ viewmodel์— ๋‹ด์•„ ์ „์—ญ๋ณ€์ˆ˜๋กœ ๊ด€๋ฆฌ..
class UserViewModel : ViewModel() {

private val _email = MutableLiveData<String>()
val email: LiveData<String> = _email

fun setEmail(newEmail: String) {
_email.value = newEmail
}
}
import org.sopt.and.presentation.loginScreen.LoginScreen
import org.sopt.and.presentation.mypageScreen.MypageScreen
import org.sopt.and.presentation.searchScreen.SearchScreen
import org.sopt.and.presentation.signupScreen.SignUpScreen
import org.sopt.and.presentation.homeScreen.HomeScreen
import org.sopt.and.presentation.homeScreen.HomeViewModel
import org.sopt.and.presentation.main.UserViewModel
import org.sopt.and.presentation.mypageScreen.MypageViewModel

class MainActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Expand All @@ -41,6 +35,7 @@ class MainActivity : ComponentActivity() {
Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding ->
val navController = rememberNavController()
val userViewModel: UserViewModel = viewModel()
val mypageViewModel : MypageViewModel = viewModel()

NavHost(
navController = navController,
Expand All @@ -49,8 +44,8 @@ class MainActivity : ComponentActivity() {
){
composable<SignUpScreen> {
SignUpScreen(
navigateToLoginScreen = {
emailText, passwordText -> navController.navigate(LoginScreen(emailText, passwordText))
navigateToLoginScreen = { userNameText, passwordText ->
navController.navigate(LoginScreen(userNameText, passwordText))
}
)
}
Expand All @@ -60,19 +55,22 @@ class MainActivity : ComponentActivity() {
val scope = rememberCoroutineScope()
val snackbarHostState = remember { SnackbarHostState() }
LoginScreen(
emailText = item.emailText,
userNameText = item.userNameText,
passwordText = item.passwordText,
scope = scope,
snackbarHostState = snackbarHostState,
navigateToHomeScreen = {
navController.navigate("home")
}
},
userViewModel = userViewModel,
mypageViewModel = mypageViewModel
)
}

composable("home") {
HomeScreen(
navController = navController,
homeViewModel = HomeViewModel()
)
}

Expand All @@ -86,7 +84,8 @@ class MainActivity : ComponentActivity() {

MypageScreen(
navController = navController,
userViewModel = userViewModel
userViewModel = userViewModel,
mypageViewModel = mypageViewModel
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.and.model.dto.login

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

//์š”์ฒญํ•  ๋•Œ๋Š” username๋งŒ ๊ฐ€์ง€๊ณ  ์š”์ฒญ (uniqueํ•ด์•ผ ํ•จ)
@Serializable
data class RequestGetUserDto(
@SerialName("username")
val userName: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.and.model.dto.login

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

@Serializable
data class ResponseGetUserFailDto(
@SerialName("code")
val no: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.and.model.dto.login

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

@Serializable
data class ResponseGetUserSuccessDto(
@SerialName("result")
val result: UserResult
)

@Serializable
data class UserResult(
@SerialName("token")
val token: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.and.model.dto.login

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

@Serializable
data class ResponseGetUserWrapperDto(
@SerialName("success")
val success: ResponseGetUserSuccessDto,
@SerialName("failed")
val failed: ResponseGetUserFailDto
)
Copy link
Contributor

Choose a reason for hiding this comment

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

์ด๊ฑฐ ์ด๋Ÿฐ ์‹์œผ๋กœ ๋งŒ๋“ค์–ด๋„ ํ†ต์‹  ์ž˜ ์ด๋ฃจ์–ด ์ง€๋‚˜์š”?
์„ฑ๊ณต์˜ ๊ฒฝ์šฐ์—๋Š” success์— ๋Œ€ํ•œ ๊ฒƒ๋งŒ ์‹คํŒจ์˜ ๊ฒฝ์šฐ์—๋Š” failed ๋งŒ ๋‚ด๋ ค๋ณด๋‚ด์ฃผ์–ด ์ง๋ ฌํ™”๊ฐ€ ์ž˜ ์•ˆ ๋  ๊ฒƒ ๊ฐ™์€๋ฐ ์ž˜ ๋™์ž‘ํ•˜๋‚˜์š”?

Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.and.model.dto.mypage

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

//์š”์ฒญํ•  ๋•Œ๋Š” token๋งŒ ๊ฐ€์ง€๊ณ  ์š”์ฒญ
@Serializable
data class RequestGetUserHobbyDto(
@SerialName("token")
val token: String,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.sopt.and.model.dto.mypage

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

@Serializable
data class ResponseGetUserHobbyFailDto(
@SerialName("code")
val no: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.and.model.dto.mypage

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

@Serializable
data class ResponseGetUserHobbySuccessDto(
@SerialName("result")
val result: HobbyResult? = null,
)

@Serializable
data class HobbyResult(
@SerialName("hobby")
val userHobby: String? = null,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.and.model.dto.mypage

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.and.model.dto.login.ResponseGetUserFailDto
import org.sopt.and.model.dto.login.ResponseGetUserSuccessDto

@Serializable
data class ResponseGetUserHobbyWrapperDto(
@SerialName("success")
val success: ResponseGetUserHobbySuccessDto,
@SerialName("failed")
val failed: ResponseGetUserHobbyFailDto
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.and.model.dto.signup

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

@Serializable
data class RequestCreateUserDto(
@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,16 @@
package org.sopt.and.model.dto.signup

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

@Serializable
data class ResponseCreateUserFailDto(
@SerialName("failed")
val code: FailureResult
)

@Serializable
data class FailureResult(
@SerialName("code")
val no: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.and.model.dto.signup

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

@Serializable
data class ResponseCreateUserSuccessDto(
@SerialName("success")
val result: UserResult
)

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

Choose a reason for hiding this comment

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

DTO์ž‘์„ฑ์ด ๋งค์šฐ ์ž์„ธํ•˜๋„ค์š”๐Ÿ‘ ๋ž˜ํผํด๋ž˜์Šค๋ฅผ ๋„ฃ์€ ์ด์œ ๊ฐ€ ์žˆ๋‚˜์š”? ๊ถ๊ธˆํ•ด์„œ!!!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

์„œ๋ฒ„ ์š”์ฒญ์ด ์„ฑ๊ณตํ•œ ๊ฒฝ์šฐ์™€ ์‹คํŒจํ•œ ๊ฒฝ์šฐ์— ์‚ฌ์šฉํ•˜๋Š” DTO๊ฐ€ ๋ถ„๋ฆฌ๋˜์–ด ์žˆ๋Š”๋ฐ, ์‘๋‹ต ํƒ€์ž…์€ ๋Š˜ ํ•˜๋‚˜์—ฌ์•ผ ํ•˜๋‹ˆ.. ๋ถ„๊ธฐ ์ฒ˜๋ฆฌ๋ฅผ ํ•˜๋Š” ๊ฒƒ๋ณด๋‹จ WrapperDTO ์•ˆ์— failedDTO๋ž‘ successDTO๋ฅผ ํ•จ๊ป˜ ๋„ฃ์–ด๋‘๊ณ  ๋Š˜ WrapperDTO๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” ๋ฐฉ์‹์ด ๋งž๋‹ค๊ณ  ์ƒ๊ฐํ–ˆ์–ด์š”! ๊ทธ๋Ÿฐ๋ฐ ํ•ฉ์„ธ ๋•Œ ์žฌ๋ฏผ๋‹˜๊ป˜ ๊ผญ ๊ทธ๋ ‡๊ฒŒ ํ•˜์ง€ ์•Š์•„๋„ ๋œ๋‹ค๋Š” ๋ง์”€์„ ๋“ค์–ด์„œ (๊ทธ๋ฆฌ๊ณ  ์ด๊ฒŒ ์ง€๊ธˆ ์—๋Ÿฌ์˜ ์›์ธ ๊ฐ™์•„์„œ ๐Ÿ˜… ๋ฐฉ์‹์„ ์ˆ˜์ •ํ•ด๋ณผ ์˜ˆ์ •์ž…๋‹ˆ๋‹น)

Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.and.model.dto.signup

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

@Serializable
data class ResponseCreateUserWrapperDto( //ํŠน์ • ์œ ์ € ํ•œ ๋ช…์˜ ์‘๋‹ต DTO
@SerialName("success")
val success: ResponseCreateUserSuccessDto,
@SerialName("failed")
val failed: ResponseCreateUserFailDto
)


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

import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
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

object ApiFactory {
private const val BASE_URL: String = BuildConfig.BASE_URL

private val loggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

private val client = OkHttpClient.Builder()
.addInterceptor(loggingInterceptor)
.build()

val retrofit: Retrofit by lazy {
Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType()))
.build()
}

inline fun <reified T> create(): T = retrofit.create(T::class.java)
}

//์ด userService๋ฅผ, ์„œ๋ฒ„๋ฅผ ๋ถ™์ด๋Š” ๋ถ€๋ถ„์—์„œ ์‚ฌ์šฉํ•ด์•ผ ํ•จ.
//Viewmodel์—์„œ ์ด userService์— ์ ‘๊ทผํ•˜๋ฉด ๋จ.
object ServicePool {
val userService = ApiFactory.create<UserService>()
}
Loading