Skip to content

Commit

Permalink
feat: 알송파트 유즈케이스 적용 (#666)
Browse files Browse the repository at this point in the history
* refactor: 로그인 기능 유즈케이스 구현

* refactor: 이미 로그인이 되어 있는 디바이스인지 확인하는 기능에 유즈케이스 적용

* refactor: 네이밍 개선

* style: 필요 없어진 코드 제거

* refactor: 공모글 작성 기능에 유즈케이스 적용

* refactor: 유즈케이스를 도메인 레이어로 이동

* style: ktlint format 적용

* refactor: 이미지 업로드 기능에 유즈케이스 적용

* refactor: 이미지 업로드 기능에 유즈케이스 적용

* refactor: 공모글 수정 기능에 유즈케이스 적용

* refactor: 채팅방 목록 조회 기능에 유즈케이스 적용

* test: 댓글방 목록을 불러오는 유즈케이스 테스트

* test: 로그인 유즈케이스 테스트

* test: 유즈케이스 적용으로 인한 공모글 작성 뷰모델 테스트 수정

* test: 유즈케이스 적용으로 인한 댓글방 목록 조회 뷰모델 테스트 수정

* style: ktlint format 적용
  • Loading branch information
songpink authored Jan 6, 2025
1 parent 5d7a739 commit eb3dd28
Show file tree
Hide file tree
Showing 31 changed files with 635 additions and 203 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result

interface AuthRepository {
suspend fun saveLogin(
suspend fun postLogin(
accessToken: String,
fcmToken: String,
): Result<Member, DataError.Network>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AuthRepositoryImpl
constructor(
@AuthDataSourceQualifier private val authRemoteDataSource: AuthRemoteDataSource,
) : AuthRepository {
override suspend fun saveLogin(
override suspend fun postLogin(
accessToken: String,
fcmToken: String,
): Result<Member, DataError.Network> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zzang.chongdae.di.annotations

import javax.inject.Qualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class CheckAlreadyLoggedInUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class PostLoginUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class PostOfferingUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class UploadImageFileUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class PostProductImageOgUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class FetchOfferingDetailUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class PostOfferingModifyUseCaseQualifier

@Qualifier
@Retention(AnnotationRetention.BINARY)
annotation class UpdateCommentRoomsUseCaseQualifier
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package com.zzang.chongdae.di.module

import com.zzang.chongdae.di.annotations.CheckAlreadyLoggedInUseCaseQualifier
import com.zzang.chongdae.di.annotations.FetchOfferingDetailUseCaseQualifier
import com.zzang.chongdae.di.annotations.PostLoginUseCaseQualifier
import com.zzang.chongdae.di.annotations.PostOfferingModifyUseCaseQualifier
import com.zzang.chongdae.di.annotations.PostOfferingUseCaseQualifier
import com.zzang.chongdae.di.annotations.PostProductImageOgUseCaseQualifier
import com.zzang.chongdae.di.annotations.UpdateCommentRoomsUseCaseQualifier
import com.zzang.chongdae.di.annotations.UploadImageFileUseCaseQualifier
import com.zzang.chongdae.domain.usecase.comment.UpdateCommentRoomsUseCase
import com.zzang.chongdae.domain.usecase.comment.UpdateCommentRoomsUseCaseImpl
import com.zzang.chongdae.domain.usecase.login.CheckIfAlreadyLoggedInUseCase
import com.zzang.chongdae.domain.usecase.login.CheckIfAlreadyLoggedInUseCaseImpl
import com.zzang.chongdae.domain.usecase.login.PostLoginUseCase
import com.zzang.chongdae.domain.usecase.login.PostLoginUseCaseImpl
import com.zzang.chongdae.domain.usecase.offeringmodify.FetchOfferingDetailUseCase
import com.zzang.chongdae.domain.usecase.offeringmodify.FetchOfferingDetailUseCaseImpl
import com.zzang.chongdae.domain.usecase.offeringmodify.PostOfferingModifyUseCase
import com.zzang.chongdae.domain.usecase.offeringmodify.PostOfferingModifyUseCaseImpl
import com.zzang.chongdae.domain.usecase.write.PostOfferingUseCase
import com.zzang.chongdae.domain.usecase.write.PostOfferingUseCaseImpl
import com.zzang.chongdae.domain.usecase.write.PostProductImageOgUseCase
import com.zzang.chongdae.domain.usecase.write.PostProductImageOgUseCaseImpl
import com.zzang.chongdae.domain.usecase.write.UploadImageFileUseCase
import com.zzang.chongdae.domain.usecase.write.UploadImageFileUseCaseImpl
import dagger.Binds
import dagger.Module
import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent
import javax.inject.Singleton

@InstallIn(SingletonComponent::class)
@Module
abstract class UseCaseDependencyModule {
@Binds
@Singleton
@CheckAlreadyLoggedInUseCaseQualifier
abstract fun provideCheckIfAlreadyLoggedInUseCase(impl: CheckIfAlreadyLoggedInUseCaseImpl): CheckIfAlreadyLoggedInUseCase

@Binds
@Singleton
@PostLoginUseCaseQualifier
abstract fun providePostLoginUseCase(impl: PostLoginUseCaseImpl): PostLoginUseCase

@Binds
@Singleton
@PostOfferingUseCaseQualifier
abstract fun providePostOfferingUseCase(impl: PostOfferingUseCaseImpl): PostOfferingUseCase

@Binds
@Singleton
@UploadImageFileUseCaseQualifier
abstract fun provideUploadImageFileUseCase(impl: UploadImageFileUseCaseImpl): UploadImageFileUseCase

@Binds
@Singleton
@PostProductImageOgUseCaseQualifier
abstract fun providePostProductImageOgUseCase(impl: PostProductImageOgUseCaseImpl): PostProductImageOgUseCase

@Binds
@Singleton
@FetchOfferingDetailUseCaseQualifier
abstract fun provideFetchOfferingDetailUseCase(impl: FetchOfferingDetailUseCaseImpl): FetchOfferingDetailUseCase

@Binds
@Singleton
@PostOfferingModifyUseCaseQualifier
abstract fun providePostOfferingModifyUseCase(impl: PostOfferingModifyUseCaseImpl): PostOfferingModifyUseCase

@Binds
@Singleton
@UpdateCommentRoomsUseCaseQualifier
abstract fun provideUpdateCommentRoomsUseCase(impl: UpdateCommentRoomsUseCaseImpl): UpdateCommentRoomsUseCase
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zzang.chongdae.domain.usecase.comment

import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.domain.model.CommentRoom

interface UpdateCommentRoomsUseCase {
suspend operator fun invoke(): Result<List<CommentRoom>, DataError.Network>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zzang.chongdae.domain.usecase.comment

import com.zzang.chongdae.auth.repository.AuthRepository
import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.di.annotations.AuthRepositoryQualifier
import com.zzang.chongdae.di.annotations.CommentRoomsRepositoryQualifier
import com.zzang.chongdae.domain.model.CommentRoom
import com.zzang.chongdae.domain.repository.CommentRoomsRepository
import javax.inject.Inject

class UpdateCommentRoomsUseCaseImpl
@Inject
constructor(
@AuthRepositoryQualifier private val authRepository: AuthRepository,
@CommentRoomsRepositoryQualifier private val commentRoomsRepository: CommentRoomsRepository,
) : UpdateCommentRoomsUseCase {
override suspend fun invoke(): Result<List<CommentRoom>, DataError.Network> {
return when (val result = commentRoomsRepository.fetchCommentRooms()) {
is Result.Success -> Result.Success(result.data)
is Result.Error -> {
when (result.error) {
DataError.Network.UNAUTHORIZED -> {
when (authRepository.saveRefresh()) {
is Result.Success -> invoke()
is Result.Error -> result
}
}

else -> result
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.zzang.chongdae.domain.usecase.login

interface CheckIfAlreadyLoggedInUseCase {
suspend operator fun invoke(): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.zzang.chongdae.domain.usecase.login

import com.zzang.chongdae.common.datastore.UserPreferencesDataStore
import kotlinx.coroutines.flow.first
import javax.inject.Inject

class CheckIfAlreadyLoggedInUseCaseImpl
@Inject
constructor(
private val userPreferencesDataStore: UserPreferencesDataStore,
) : CheckIfAlreadyLoggedInUseCase {
override suspend fun invoke(): Boolean {
val accessToken = userPreferencesDataStore.accessTokenFlow.first()
return accessToken != null
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.zzang.chongdae.domain.usecase.login

import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result

interface PostLoginUseCase {
suspend operator fun invoke(
accessToken: String,
fcmToken: String,
): Result<Unit, DataError.Network>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.zzang.chongdae.domain.usecase.login

import com.zzang.chongdae.auth.repository.AuthRepository
import com.zzang.chongdae.common.datastore.UserPreferencesDataStore
import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.di.annotations.AuthRepositoryQualifier
import javax.inject.Inject

class PostLoginUseCaseImpl
@Inject
constructor(
@AuthRepositoryQualifier private val authRepository: AuthRepository,
private val userPreferencesDataStore: UserPreferencesDataStore,
) : PostLoginUseCase {
override suspend fun invoke(
accessToken: String,
fcmToken: String,
): Result<Unit, DataError.Network> {
return when (val result = authRepository.postLogin(accessToken, fcmToken)) {
is Result.Success -> {
userPreferencesDataStore.saveMember(result.data.memberId, result.data.nickName)
userPreferencesDataStore.saveFcmToken(fcmToken)
Result.Success(Unit)
}

is Result.Error -> result
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zzang.chongdae.domain.usecase.offeringmodify

import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.domain.model.OfferingDetail

interface FetchOfferingDetailUseCase {
suspend operator fun invoke(offeringId: Long): Result<OfferingDetail, DataError.Network>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package com.zzang.chongdae.domain.usecase.offeringmodify

import com.zzang.chongdae.auth.repository.AuthRepository
import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.di.annotations.AuthRepositoryQualifier
import com.zzang.chongdae.di.annotations.OfferingDetailRepositoryQualifier
import com.zzang.chongdae.domain.model.OfferingDetail
import com.zzang.chongdae.domain.repository.OfferingDetailRepository
import javax.inject.Inject

class FetchOfferingDetailUseCaseImpl
@Inject
constructor(
@OfferingDetailRepositoryQualifier private val offeringDetailRepository: OfferingDetailRepository,
@AuthRepositoryQualifier private val authRepository: AuthRepository,
) : FetchOfferingDetailUseCase {
override suspend fun invoke(offeringId: Long): Result<OfferingDetail, DataError.Network> {
return when (val result = offeringDetailRepository.fetchOfferingDetail(offeringId)) {
is Result.Success -> Result.Success(result.data)
is Result.Error -> {
when (result.error) {
DataError.Network.UNAUTHORIZED -> {
when (authRepository.saveRefresh()) {
is Result.Success -> invoke(offeringId)
is Result.Error -> result
}
}

else -> result
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.zzang.chongdae.domain.usecase.offeringmodify

import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.domain.model.OfferingModifyDomainRequest

interface PostOfferingModifyUseCase {
suspend operator fun invoke(
offeringId: Long,
offeringModifyDomainRequest: OfferingModifyDomainRequest,
): Result<Unit, DataError.Network>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package com.zzang.chongdae.domain.usecase.offeringmodify

import com.zzang.chongdae.auth.repository.AuthRepository
import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.di.annotations.AuthRepositoryQualifier
import com.zzang.chongdae.di.annotations.OfferingRepositoryQualifier
import com.zzang.chongdae.domain.model.OfferingModifyDomainRequest
import com.zzang.chongdae.domain.repository.OfferingRepository
import javax.inject.Inject

class PostOfferingModifyUseCaseImpl
@Inject
constructor(
@OfferingRepositoryQualifier private val offeringRepository: OfferingRepository,
@AuthRepositoryQualifier private val authRepository: AuthRepository,
) : PostOfferingModifyUseCase {
override suspend fun invoke(
offeringId: Long,
offeringModifyDomainRequest: OfferingModifyDomainRequest,
): Result<Unit, DataError.Network> {
return when (
val result =
offeringRepository.patchOffering(offeringId, offeringModifyDomainRequest)
) {
is Result.Success -> Result.Success(Unit)
is Result.Error -> {
when (result.error) {
DataError.Network.UNAUTHORIZED -> {
when (authRepository.saveRefresh()) {
is Result.Success -> invoke(offeringId, offeringModifyDomainRequest)
is Result.Error -> result
}
}

else -> result
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zzang.chongdae.domain.usecase.write

import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.domain.model.OfferingWrite

interface PostOfferingUseCase {
suspend operator fun invoke(offeringWrite: OfferingWrite): Result<Unit, DataError.Network>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package com.zzang.chongdae.domain.usecase.write

import com.zzang.chongdae.auth.repository.AuthRepository
import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.di.annotations.AuthRepositoryQualifier
import com.zzang.chongdae.di.annotations.OfferingRepositoryQualifier
import com.zzang.chongdae.domain.model.OfferingWrite
import com.zzang.chongdae.domain.repository.OfferingRepository
import javax.inject.Inject

class PostOfferingUseCaseImpl
@Inject
constructor(
@OfferingRepositoryQualifier private val offeringRepository: OfferingRepository,
@AuthRepositoryQualifier private val authRepository: AuthRepository,
) : PostOfferingUseCase {
override suspend fun invoke(offeringWrite: OfferingWrite): Result<Unit, DataError.Network> {
return when (val result = offeringRepository.saveOffering(offeringWrite)) {
is Result.Success -> Result.Success(Unit)
is Result.Error -> {
when (result.error) {
DataError.Network.UNAUTHORIZED -> {
when (authRepository.saveRefresh()) {
is Result.Success -> invoke(offeringWrite)
is Result.Error -> result
}
}
else -> result
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.zzang.chongdae.domain.usecase.write

import com.zzang.chongdae.common.handler.DataError
import com.zzang.chongdae.common.handler.Result
import com.zzang.chongdae.domain.model.ProductUrl

interface PostProductImageOgUseCase {
suspend operator fun invoke(productUrl: String): Result<ProductUrl, DataError.Network>
}
Loading

0 comments on commit eb3dd28

Please sign in to comment.