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

[FEAT/#9] 6주차 과제 #10

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
10 changes: 10 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ plugins {
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.hilt.android)
id("kotlin-kapt")
}

val properties = Properties().apply {
Expand Down Expand Up @@ -46,6 +48,9 @@ android {
compose = true
buildConfig = true
}
hilt {
enableAggregatingTask = false
}
Comment on lines +51 to +53

Choose a reason for hiding this comment

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

이 친구를 왜 추가해야할까요?
추가를 하지 않고도 할 수 있는데 어떻게 수정하면 좋을까요?

}

dependencies {
Expand Down Expand Up @@ -75,4 +80,9 @@ dependencies {
implementation(libs.retrofit)
implementation(libs.retrofit.kotlin.serialization.converter)
implementation(libs.kotlinx.serialization.json)

// Hilt
implementation(libs.hilt.android)
implementation(libs.hilt.navigation.compose)
kapt(libs.hilt.compiler)
}
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".WavveApplication"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand Down
10 changes: 6 additions & 4 deletions app/src/main/java/org/sopt/and/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,17 @@ import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.compose.rememberNavController
import dagger.hilt.android.AndroidEntryPoint
import org.sopt.and.feature.nav.BottomNavigation
import org.sopt.and.feature.signin.SignInScreen
import org.sopt.and.feature.signup.SignUpScreen
import org.sopt.and.ui.theme.ANDANDROIDTheme
import org.sopt.and.utils.KeyStorage.AUTH_PREFS
import org.sopt.and.utils.KeyStorage.HOME
import org.sopt.and.utils.KeyStorage.SIGN_IN
import org.sopt.and.utils.KeyStorage.SIGN_UP
import org.sopt.and.core.utils.KeyStorage.AUTH_PREFS
import org.sopt.and.core.utils.KeyStorage.HOME
import org.sopt.and.core.utils.KeyStorage.SIGN_IN
import org.sopt.and.core.utils.KeyStorage.SIGN_UP
Comment on lines +24 to +27

Choose a reason for hiding this comment

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

보통 core 패키징에는 어떤 친구들을 넣어두시는지 궁금합니다 ~


@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/WavveApplication.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 WavveApplication : Application()
36 changes: 0 additions & 36 deletions app/src/main/java/org/sopt/and/api/ApiFactory.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.annotation.StringRes
import androidx.compose.foundation.Image
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.compose.material3.ScrollableTabRow
import androidx.compose.material3.Tab
Expand All @@ -15,7 +15,7 @@ import androidx.compose.ui.res.stringResource
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import org.sopt.and.R
import org.sopt.and.model.TabMenuItem
import org.sopt.and.feature.model.TabMenuItem

@Composable
fun TabMenu(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.fillMaxWidth
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.layout.Arrangement
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.designsystem.component

import androidx.compose.foundation.Image
import androidx.compose.foundation.background
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.utils
package org.sopt.and.core.utils

object KeyStorage {
const val TEXTFIELD_MAX_LENGTH = 8
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.utils
package org.sopt.and.core.utils.context

import android.content.Context
import android.widget.Toast
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.utils
package org.sopt.and.core.utils.modifier

import androidx.compose.foundation.clickable
import androidx.compose.foundation.interaction.MutableInteractionSource
Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/org/sopt/and/data/datasource/AuthDataSource.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.and.data.datasource

import org.sopt.and.data.dto.request.RequestSignInDto
import org.sopt.and.data.dto.request.RequestSignUpDto
import org.sopt.and.data.dto.response.BaseResponse
import org.sopt.and.data.dto.response.ResponseHobbyDto
import org.sopt.and.data.dto.response.ResponseSignInDto
import org.sopt.and.data.dto.response.ResponseSignUpDto

interface AuthDataSource {

Choose a reason for hiding this comment

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

Auth기능과 getBobby 구현이 한 DataSource파일에 합쳐진 것 같아서 나중에는 분리해서 제작하는 것도 좋아보여요!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

오 넵 참고할게요-! 감사합니다

suspend fun signUp(request: RequestSignUpDto): BaseResponse<ResponseSignUpDto>

suspend fun signIn(request: RequestSignInDto): BaseResponse<ResponseSignInDto>

suspend fun getHobby(request: String): BaseResponse<ResponseHobbyDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.sopt.and.data.datasourceimpl

import org.sopt.and.data.datasource.AuthDataSource
import org.sopt.and.data.dto.request.RequestSignInDto
import org.sopt.and.data.dto.request.RequestSignUpDto
import org.sopt.and.data.dto.response.BaseResponse
import org.sopt.and.data.dto.response.ResponseHobbyDto
import org.sopt.and.data.dto.response.ResponseSignInDto
import org.sopt.and.data.dto.response.ResponseSignUpDto
import org.sopt.and.data.service.AuthService
import javax.inject.Inject

class AuthDataSourceImpl @Inject constructor(
private val authService: AuthService
) : AuthDataSource {
override suspend fun signUp(request: RequestSignUpDto): BaseResponse<ResponseSignUpDto> =
authService.signUp(request)

override suspend fun signIn(request: RequestSignInDto): BaseResponse<ResponseSignInDto> =
authService.signIn(request)

override suspend fun getHobby(request: String): BaseResponse<ResponseHobbyDto> =
authService.getHobby(request)
}
18 changes: 18 additions & 0 deletions app/src/main/java/org/sopt/and/data/di/ApiModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.and.data.di

import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.and.data.service.AuthService
import retrofit2.Retrofit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object ApiModule {
@Provides
@Singleton
fun provideAuthService(retrofit: Retrofit): AuthService =
retrofit.create(AuthService::class.java)

Choose a reason for hiding this comment

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

Suggested change
@Provides
@Singleton
fun provideAuthService(retrofit: Retrofit): AuthService =
retrofit.create(AuthService::class.java)
@Provides
@Singleton
fun provideAuthService(retrofit: Retrofit): AuthService =
retrofit.create()

이런식으로만 작성하셔도 될겁니다

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

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.and.data.datasource.AuthDataSource
import org.sopt.and.data.datasourceimpl.AuthDataSourceImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindsAuthDataSource(authDataSourceImpl: AuthDataSourceImpl): AuthDataSource
}
74 changes: 74 additions & 0 deletions app/src/main/java/org/sopt/and/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package org.sopt.and.data.di

import android.content.Context
import android.content.SharedPreferences
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.android.qualifiers.ApplicationContext
import dagger.hilt.components.SingletonComponent
import kotlinx.serialization.ExperimentalSerializationApi
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 java.util.concurrent.TimeUnit
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
object NetworkModule {
@Provides
@Singleton
fun providesOkHttpClient(
loggingInterceptor: HttpLoggingInterceptor,
// authInterceptor: Interceptor
): OkHttpClient =
OkHttpClient.Builder().apply {
connectTimeout(10, TimeUnit.SECONDS)
writeTimeout(10, TimeUnit.SECONDS)
readTimeout(10, TimeUnit.SECONDS)
// addInterceptor(authInterceptor)
}.build()

@Provides
@Singleton
fun providesJson(): Json =
Json {
isLenient = true
prettyPrint = true
explicitNulls = false
ignoreUnknownKeys = true
}

@Provides
@Singleton
fun provideLoggingInterceptor(): HttpLoggingInterceptor = HttpLoggingInterceptor().apply {
level = HttpLoggingInterceptor.Level.BODY
}

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

@Provides
@Singleton
fun provideSharedPreferences(
@ApplicationContext context: Context
): SharedPreferences {
return context.getSharedPreferences("APP_PREFS", Context.MODE_PRIVATE)
}

Choose a reason for hiding this comment

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

sharedPreferences 객체를 di를 활용하면 요렇게 관리해줄 수 있군요!!

Choose a reason for hiding this comment

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

Network에 관련된 친구라고 보기는 애매해서 따로 Module을 분리해주어도 좋을 것 같네요

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

import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.and.data.repositoryimpl.AuthRepositoryImpl
import org.sopt.and.domain.repository.AuthRepository
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindAuthRepository(authRepositoryImpl: AuthRepositoryImpl): AuthRepository
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.api.dto.request
package org.sopt.and.data.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.api.dto.request
package org.sopt.and.data.dto.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.api.dto.response
package org.sopt.and.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.api.dto.response
package org.sopt.and.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.api.dto.response
package org.sopt.and.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Loading