-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor: 메서드명 getParameterValues()를 getArgs()로 변경 * feat: 필드 주입 기능 구현 * feat: 종속 항목 맵 초기화 기능 구현 * test: 뷰모델 생성자/필드 주입 테스트 작성 * refactor: CartRepository에서 Dao를 주입받도록 변경 * refactor: 장바구니 화면에서 CartProduct 목록을 가지고 있도록 변경 * feat: Qualifier를 사용하여 인터페이스 구분하는 기능 구현 * chore: di 모듈화 * refactor: 부모 자식 타입을 매칭하는 코드 리팩토링 * refactor: 모듈 제공하는 함수 리팩토링 * refactor: ViewModel에서 Repository 어노테이션을 지정하도록 변경 * refactor: 캐시 클래스로 한 번 생성한 객체 관리하도록 변경 * refactor: 타입 변환하는 Map을 SubTypeConverter로 분리 * refactor: 패키지 분리 * feat: DependencyInjector 초기화 기능 구현 * test: 기능 변경에 따른 테스트 코드 재작성 * refactor: CartRepository 파일 분리 * refactor: 캐시에서 종속항목을 가져오는 함수를 operator로 변경 * fix: inject() 함수에서 생성한 객체를 캐싱하지 않는 버그 수정 * fix: InMemoryCartRepository에서 상품 하나 제거하면 모두 사라지는 버그 수정 * fix: SubTypeConverter, Cache 삭제 안 되는 버그 수정 * refactor: @InMemoryProductRepositoryQualifier 애노테이션 제거 * chore: di 모듈 자바 버전 11로 통일 * refactor: di 모듈에서 안드로이드 의존성 제거 * test: DependencyInjectorTest를 app모듈로 이동 * refactor: 일단 커밋 * refactor: 일단 커밋 * refactor: SubTypeProvider 제거 * test: DependencyInjector 코드 변경에 따른 테스트 코드 수정 * test: DependencyInjector 재귀 주입 테스트 작성 * test: 테스트 코드 함수명 변경 * test: @Inject이 붙은 멤버가 복수개여도 정상 주입되는지 확인하는 테스트 코드 작성 * test: 클래스 멤버 프로퍼티가 복수인 경우 Inject 애노테이션이 없는 멤버에 주입하지 않는 것을 확인하는 테스트 코드 작성 * test: 생성자 주입 실패 테스트 케이스 작성(식별자 애노테이션이 없는 경우) * refactor: 코드 포맷팅 * refactor: 인터페이스 타입인 필드에 식별자 애노테이션을 추가하지 않았을 때 예외 발생을 검증하는 테스트 코드 작성 * refactor: CartProductEntity를 mapping할 때 인자명을 지정하여 명시적으로 변경
- Loading branch information
Showing
43 changed files
with
721 additions
and
143 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 3 additions & 8 deletions
11
app/src/main/java/woowacourse/shopping/ShoppingApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package woowacourse.shopping | ||
|
||
import android.app.Application | ||
import woowacourse.shopping.data.repository.DefaultCartRepository | ||
import woowacourse.shopping.data.repository.DefaultProductRepository | ||
import woowacourse.shopping.di.injector.modules | ||
import woowacourse.shopping.repository.CartRepository | ||
import woowacourse.shopping.repository.ProductRepository | ||
import com.woowacourse.bunadi.dsl.modules | ||
import woowacourse.shopping.ui.common.di.module.DaoModule | ||
|
||
class ShoppingApplication : Application() { | ||
override fun onCreate() { | ||
super.onCreate() | ||
|
||
modules { | ||
inject<ProductRepository>(DefaultProductRepository()) | ||
inject<CartRepository>(DefaultCartRepository()) | ||
module(DaoModule(this@ShoppingApplication)) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
app/src/main/java/woowacourse/shopping/data/mapper/CartMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package woowacourse.shopping.data.mapper | ||
|
||
import woowacourse.shopping.data.CartProductEntity | ||
import woowacourse.shopping.model.CartProduct | ||
import woowacourse.shopping.model.Product | ||
|
||
fun Product.toEntity(): CartProductEntity = CartProductEntity( | ||
name = name, | ||
price = price, | ||
imageUrl = imageUrl, | ||
) | ||
|
||
fun List<CartProductEntity>.toDomain(): List<CartProduct> = map { cartProductEntity -> | ||
CartProduct( | ||
product = Product( | ||
name = cartProductEntity.name, | ||
price = cartProductEntity.price, | ||
imageUrl = cartProductEntity.imageUrl, | ||
), | ||
id = cartProductEntity.id, | ||
createdAt = cartProductEntity.createdAt, | ||
) | ||
} |
12 changes: 0 additions & 12 deletions
12
app/src/main/java/woowacourse/shopping/data/mapper/ProductMapper.kt
This file was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
app/src/main/java/woowacourse/shopping/data/repository/DatabaseCartRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package woowacourse.shopping.data.repository | ||
|
||
import com.woowacourse.bunadi.annotation.Singleton | ||
import woowacourse.shopping.data.CartProductDao | ||
import woowacourse.shopping.data.mapper.toDomain | ||
import woowacourse.shopping.data.mapper.toEntity | ||
import woowacourse.shopping.model.CartProduct | ||
import woowacourse.shopping.model.Product | ||
import woowacourse.shopping.repository.CartRepository | ||
|
||
@Singleton | ||
class DatabaseCartRepository( | ||
private val dao: CartProductDao, | ||
) : CartRepository { | ||
override suspend fun addCartProduct(product: Product) { | ||
dao.insert(product.toEntity()) | ||
} | ||
|
||
override suspend fun getAllCartProducts(): List<CartProduct> { | ||
return dao.getAll().toDomain() | ||
} | ||
|
||
override suspend fun deleteCartProduct(id: Long) { | ||
dao.delete(id) | ||
} | ||
} |
18 changes: 0 additions & 18 deletions
18
app/src/main/java/woowacourse/shopping/data/repository/DefaultCartRepository.kt
This file was deleted.
Oops, something went wrong.
2 changes: 2 additions & 0 deletions
2
app/src/main/java/woowacourse/shopping/data/repository/DefaultProductRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
app/src/main/java/woowacourse/shopping/data/repository/InMemoryCartRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package woowacourse.shopping.data.repository | ||
|
||
import com.woowacourse.bunadi.annotation.Singleton | ||
import woowacourse.shopping.data.CartProductEntity | ||
import woowacourse.shopping.data.mapper.toDomain | ||
import woowacourse.shopping.data.mapper.toEntity | ||
import woowacourse.shopping.model.CartProduct | ||
import woowacourse.shopping.model.Product | ||
import woowacourse.shopping.repository.CartRepository | ||
|
||
@Singleton | ||
class InMemoryCartRepository : CartRepository { | ||
private val cartProducts = mutableListOf<CartProductEntity>() | ||
private var lastId: Long = 0 | ||
|
||
override suspend fun addCartProduct(product: Product) { | ||
cartProducts.add(product.toEntity().apply { id = ++lastId }) | ||
} | ||
|
||
override suspend fun getAllCartProducts(): List<CartProduct> { | ||
return cartProducts.toDomain() | ||
} | ||
|
||
override suspend fun deleteCartProduct(id: Long) { | ||
cartProducts.removeIf { it.id == id } | ||
} | ||
} |
46 changes: 0 additions & 46 deletions
46
app/src/main/java/woowacourse/shopping/di/injector/DependencyInjector.kt
This file was deleted.
Oops, something went wrong.
9 changes: 0 additions & 9 deletions
9
app/src/main/java/woowacourse/shopping/di/util/UtilFunctions.kt
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
app/src/main/java/woowacourse/shopping/ui/common/di/module/DaoModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package woowacourse.shopping.ui.common.di.module | ||
|
||
import android.content.Context | ||
import androidx.room.Room | ||
import com.woowacourse.bunadi.module.Module | ||
import woowacourse.shopping.data.CartProductDao | ||
import woowacourse.shopping.data.ShoppingDatabase | ||
|
||
class DaoModule(private val context: Context) : Module { | ||
fun provideCartProductDao(): CartProductDao = Room.databaseBuilder( | ||
context, | ||
ShoppingDatabase::class.java, | ||
ShoppingDatabase.DATABASE_NAME, | ||
).build().cartProductDao() | ||
} |
15 changes: 15 additions & 0 deletions
15
app/src/main/java/woowacourse/shopping/ui/common/di/qualifier/Qualifier.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package woowacourse.shopping.ui.common.di.qualifier | ||
|
||
import com.woowacourse.bunadi.annotation.Qualifier | ||
import woowacourse.shopping.data.repository.DatabaseCartRepository | ||
import woowacourse.shopping.data.repository.DefaultProductRepository | ||
import woowacourse.shopping.data.repository.InMemoryCartRepository | ||
|
||
@Qualifier(DefaultProductRepository::class) | ||
annotation class DefaultProductRepositoryQualifier | ||
|
||
@Qualifier(InMemoryCartRepository::class) | ||
annotation class InMemoryCartRepositoryQualifier | ||
|
||
@Qualifier(DatabaseCartRepository::class) | ||
annotation class DatabaseCartRepositoryQualifier |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.