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

[Week7] 7주차 필수과제 #16

Open
wants to merge 40 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
0ebb8fc
chore #13: move component to presentation layer
hyeeum Dec 4, 2024
f512b35
add #13: add core package
hyeeum Dec 4, 2024
1248207
chore #13: add Route and edit navigation package
hyeeum Dec 4, 2024
0f51c4f
chore #13: divide component to each package
hyeeum Dec 4, 2024
0a6499f
feature #13: MyUseCase
hyeeum Dec 6, 2024
13738ee
chore #13: apply MyUseCase
hyeeum Dec 6, 2024
e8cc88b
feature #13: SignInUseCase
hyeeum Dec 6, 2024
e4170ab
chore #13: apply SignInUseCase
hyeeum Dec 6, 2024
833364c
feature #13: SignUpUseCase
hyeeum Dec 6, 2024
8383bee
chore #13: apply SignUpUseCase
hyeeum Dec 6, 2024
094db33
feature #13: SignInRepositoryImpl
hyeeum Dec 6, 2024
fdf4887
feature #13: SignUpRepositoryImpl
hyeeum Dec 6, 2024
7cb7dc7
feature #13: MyRepositoryImpl
hyeeum Dec 6, 2024
f228e2f
feature #13: MyRepository
hyeeum Dec 6, 2024
a7ba597
feature #13: SignInRepository
hyeeum Dec 6, 2024
859d8e8
feature #13: SignUpRepository
hyeeum Dec 6, 2024
ad24c45
feature #13: AuthService
hyeeum Dec 6, 2024
0ca0bed
feature #13: MyService
hyeeum Dec 6, 2024
0b0d469
feature #13: MyDataSourceImpl
hyeeum Dec 6, 2024
bcba10b
feature #13: AuthDataSourceImpl
hyeeum Dec 6, 2024
9f0cd0e
feature #13: AuthDataSource
hyeeum Dec 6, 2024
66fa970
feature #13: MyDataSource
hyeeum Dec 6, 2024
92f4d78
chore #13: DataSourceModule
hyeeum Dec 6, 2024
2bf2804
chore #13: RepositoryModule
hyeeum Dec 6, 2024
ce45e9e
chore #13: ServiceModule
hyeeum Dec 6, 2024
374274f
chore #13: edit DataSourceModule function naming
hyeeum Dec 6, 2024
59fae34
Add #15: SignUpEvent
hyeeum Dec 17, 2024
a799136
Chore #15: apply SignUpEvent
hyeeum Dec 17, 2024
0388bd4
Chore #15: apply SignUpEvent
hyeeum Dec 17, 2024
03a85c7
Add #15: SignInEvent
hyeeum Dec 17, 2024
006ffb2
Chore #15: apply SignInEvent
hyeeum Dec 17, 2024
c690d8a
Chore #15: apply Timber
hyeeum Dec 17, 2024
b0e0fb6
Chore #15: SignUpContract
hyeeum Dec 17, 2024
63c27e9
Delete #15: delete origin SignUpEvent,SideEffect,State
hyeeum Dec 17, 2024
a1fe2e6
Delete #15: delete origin SignInEvent,SideEffect,State
hyeeum Dec 17, 2024
11aa8c3
Chore #15: SignInContract
hyeeum Dec 17, 2024
f724a13
Delete #15: delete origin MySideEffect,State
hyeeum Dec 17, 2024
e4b6858
Chore #15: MyContract
hyeeum Dec 17, 2024
40aa62c
Feature #15: set BaseViewModel
hyeeum Jan 5, 2025
cc2f3b3
Refactor #15: APPJAM Refactor
hyeeum Jan 5, 2025
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
3 changes: 3 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,7 @@ dependencies {
// Network
implementation(platform(libs.okhttp.bom))
implementation(libs.bundles.network)

//timer
implementation(libs.timber)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and.component
package org.sopt.and.core.component

import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
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.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
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.component

import androidx.compose.foundation.background
import androidx.compose.foundation.clickable
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.component

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.fillMaxSize
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.and
package org.sopt.and.core.extension

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

interface MainTabRoute : Route
3 changes: 3 additions & 0 deletions app/src/main/java/org/sopt/and/core/navigation/Route.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.sopt.and.core.navigation

interface Route
52 changes: 52 additions & 0 deletions app/src/main/java/org/sopt/and/core/util/BaseViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package org.sopt.and.core.util

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.channels.Channel
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.SharedFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asSharedFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.receiveAsFlow
import kotlinx.coroutines.launch

abstract class BaseViewModel<State : UiState, SideEffect : UiSideEffect, Intent : UiEvent>() :
ViewModel() {
private val initialState: State by lazy { createInitialState() }
abstract fun createInitialState(): State

private val _state = MutableStateFlow<State>(initialState)
val uiState: StateFlow<State>
get() = _state.asStateFlow()
val currentState: State
get() = uiState.value

private val _event: MutableSharedFlow<Intent> = MutableSharedFlow()
val event: SharedFlow<Intent>
get() = _event.asSharedFlow()

private val _sideEffect: Channel<SideEffect> = Channel()
val sideEffect: Flow<SideEffect>
get() = _sideEffect.receiveAsFlow()

fun setState(reduce: State.() -> State) {
_state.value = currentState.reduce()
}

open fun setIntent(intent: Intent) {
dispatchIntent(intent)
}

private fun dispatchIntent(intent: Intent) = viewModelScope.launch {
handleEvent(intent)
}

protected abstract suspend fun handleEvent(intent: Intent)

fun setSideEffect(sideEffect: () -> SideEffect) {
viewModelScope.launch { _sideEffect.send(sideEffect()) }
}
}
8 changes: 8 additions & 0 deletions app/src/main/java/org/sopt/and/core/util/LoadState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.and.core.util

enum class LoadState {
Idle,
Loading,
Success,
Failure
}
3 changes: 3 additions & 0 deletions app/src/main/java/org/sopt/and/core/util/UiEvent.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.sopt.and.core.util

interface UiEvent
3 changes: 3 additions & 0 deletions app/src/main/java/org/sopt/and/core/util/UiSideEffect.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.sopt.and.core.util

interface UiSideEffect
3 changes: 3 additions & 0 deletions app/src/main/java/org/sopt/and/core/util/UiState.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.sopt.and.core.util

interface UiState
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ 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.ResponseUserHobbyDto
import org.sopt.and.data.dto.response.ResponseSignInDto
import org.sopt.and.data.dto.response.ResponseSignUpDto

interface WavveDataSource {
interface AuthDataSource {
suspend fun postSignUp(requestSignUpDto: RequestSignUpDto): BaseResponse<ResponseSignUpDto>
suspend fun postSignIn(requestSignInDto: RequestSignInDto): BaseResponse<ResponseSignInDto>
suspend fun getUserHobby(): BaseResponse<ResponseUserHobbyDto>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.sopt.and.data.datasource

import org.sopt.and.data.dto.response.BaseResponse
import org.sopt.and.data.dto.response.ResponseUserHobbyDto

interface MyDataSource {
suspend fun getUserHobby(): BaseResponse<ResponseUserHobbyDto>
}
Original file line number Diff line number Diff line change
@@ -1,25 +1,20 @@
package org.sopt.and.data.datasourceimpl

import org.sopt.and.data.datasource.WavveDataSource
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.ResponseUserHobbyDto
import org.sopt.and.data.dto.response.ResponseSignInDto
import org.sopt.and.data.dto.response.ResponseSignUpDto
import org.sopt.and.data.service.WavveService
import org.sopt.and.data.service.AuthService
import javax.inject.Inject

class WavveDataSourceImpl @Inject constructor(
private val wavveService: WavveService
) : WavveDataSource {
class AuthDataSourceImpl @Inject constructor(
private val authService: AuthService
) : AuthDataSource {
override suspend fun postSignUp(requestSignUpDto: RequestSignUpDto): BaseResponse<ResponseSignUpDto> =
wavveService.postSignUp(requestSignUpDto)
authService.postSignUp(requestSignUpDto)

override suspend fun postSignIn(requestSignInDto: RequestSignInDto): BaseResponse<ResponseSignInDto> =
wavveService.postSignIn(requestSignInDto)

override suspend fun getUserHobby(): BaseResponse<ResponseUserHobbyDto> =
wavveService.getUserHobby()

authService.postSignIn(requestSignInDto)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.and.data.datasourceimpl

import org.sopt.and.data.datasource.MyDataSource
import org.sopt.and.data.dto.response.BaseResponse
import org.sopt.and.data.dto.response.ResponseUserHobbyDto
import org.sopt.and.data.service.MyService
import javax.inject.Inject

class MyDataSourceImpl @Inject constructor(
private val myService: MyService
) : MyDataSource {
override suspend fun getUserHobby(): BaseResponse<ResponseUserHobbyDto> =
myService.getUserHobby()
}
12 changes: 9 additions & 3 deletions app/src/main/java/org/sopt/and/data/di/DataSourceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.and.data.datasource.WavveDataSource
import org.sopt.and.data.datasourceimpl.WavveDataSourceImpl
import org.sopt.and.data.datasource.AuthDataSource
import org.sopt.and.data.datasource.MyDataSource
import org.sopt.and.data.datasourceimpl.AuthDataSourceImpl
import org.sopt.and.data.datasourceimpl.MyDataSourceImpl
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal abstract class DataSourceModule {
@Binds
@Singleton
abstract fun bindsDataSource(myDataSourceImpl: WavveDataSourceImpl): WavveDataSource
abstract fun bindsAuthDataSource(authDataSourceImpl: AuthDataSourceImpl): AuthDataSource

@Binds
@Singleton
abstract fun bindsMyDataSource(MyDataSourceImpl: MyDataSourceImpl): MyDataSource
}

4 changes: 2 additions & 2 deletions app/src/main/java/org/sopt/and/data/di/NetworkModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import okhttp3.logging.HttpLoggingInterceptor
import org.sopt.and.BuildConfig
import org.sopt.and.sharedpreference.User
import retrofit2.Retrofit
import timber.log.Timber
import javax.inject.Singleton

@Module
Expand All @@ -36,13 +37,12 @@ object NetworkModule {
@Provides
fun provideLoggingInterceptor(): HttpLoggingInterceptor {
return HttpLoggingInterceptor { message ->
Log.d("Retrofit2", "CONNECTION INFO -> $message")
Timber.tag("Retrofit2").d("CONNECTION INFO -> $message")
}.apply {
level = HttpLoggingInterceptor.Level.BODY
}
}


@Singleton
@Provides
fun provideAuthInterceptor(user: User): AuthInterceptor {
Expand Down
26 changes: 21 additions & 5 deletions app/src/main/java/org/sopt/and/data/di/RepositoryModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,32 @@ import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.and.data.repositoryimpl.WavveRepositoryImpl
import org.sopt.and.domain.repository.WavveRepository
import org.sopt.and.data.repositoryimpl.MyRepositoryImpl
import org.sopt.and.data.repositoryimpl.SignInRepositoryImpl
import org.sopt.and.data.repositoryimpl.SignUpRepositoryImpl
import org.sopt.and.domain.repository.MyRepository
import org.sopt.and.domain.repository.SignInRepository
import org.sopt.and.domain.repository.SignUpRepository
import javax.inject.Singleton

@Module
@InstallIn(SingletonComponent::class)
internal abstract class RepositoryModule {
@Binds
@Singleton
abstract fun bindsRepository(
myRepositoryImpl: WavveRepositoryImpl
): WavveRepository
abstract fun bindsSignInRepository(
signInRepositoryImpl: SignInRepositoryImpl
): SignInRepository
Comment on lines +20 to +22

Choose a reason for hiding this comment

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

Repository랑 RepositoryImpl을 구분하는 이유는 무엇인가요? 어차피 구현체 하나라서 인터페이스 없이 Repository를 구체 클래스로 제공해도 무방할 것 같아서요


@Binds
@Singleton
abstract fun bindsSignUpRepository(
signUpRepositoryImpl: SignUpRepositoryImpl
): SignUpRepository

@Binds
@Singleton
abstract fun bindsMyRepository(
myRepositoryImpl: MyRepositoryImpl
): MyRepository
}
12 changes: 9 additions & 3 deletions app/src/main/java/org/sopt/and/data/di/ServiceModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ import dagger.Module
import dagger.Provides
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import org.sopt.and.data.service.WavveService
import org.sopt.and.data.service.AuthService
import org.sopt.and.data.service.MyService
import retrofit2.Retrofit
import javax.inject.Singleton

Expand All @@ -13,6 +14,11 @@ import javax.inject.Singleton
object ServiceModule {
@Provides
@Singleton
fun providerService(retrofit: Retrofit): WavveService =
retrofit.create(WavveService::class.java)
fun providerAuthService(retrofit: Retrofit): AuthService =
retrofit.create(AuthService::class.java)

@Provides
@Singleton
fun providerMyService(retrofit: Retrofit): MyService =
retrofit.create(MyService::class.java)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.and.data.repositoryimpl

import org.sopt.and.data.datasource.MyDataSource
import org.sopt.and.domain.entity.response.ResponseHobbyEntity
import org.sopt.and.domain.repository.MyRepository
import javax.inject.Inject

class MyRepositoryImpl @Inject constructor(
private val myDataSource: MyDataSource
) : MyRepository {
override suspend fun getHobby(): Result<ResponseHobbyEntity> = runCatching {
myDataSource.getUserHobby().result.toEntity()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.sopt.and.data.repositoryimpl

import org.sopt.and.data.datasource.AuthDataSource
import org.sopt.and.data.dto.request.toDto
import org.sopt.and.domain.entity.request.RequestSignInEntity
import org.sopt.and.domain.entity.response.ResponseSignInEntity
import org.sopt.and.domain.repository.SignInRepository
import javax.inject.Inject

class SignInRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource
) : SignInRepository {
override suspend fun signIn(body: RequestSignInEntity): Result<ResponseSignInEntity> =
runCatching {
authDataSource.postSignIn(body.toDto()).result.toEntity()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.sopt.and.data.repositoryimpl

import org.sopt.and.data.datasource.AuthDataSource
import org.sopt.and.data.dto.request.toDto
import org.sopt.and.domain.entity.request.RequestSignUpEntity
import org.sopt.and.domain.entity.response.ResponseSignUpEntity
import org.sopt.and.domain.repository.SignUpRepository
import javax.inject.Inject

class SignUpRepositoryImpl @Inject constructor(
private val authDataSource: AuthDataSource
) : SignUpRepository {
override suspend fun signUp(body: RequestSignUpEntity): Result<ResponseSignUpEntity> =
runCatching {
authDataSource.postSignUp(body.toDto()).result.toEntity()
}
}

This file was deleted.

Loading