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

[둘리] 3, 4단계 쇼핑 장바구니 제출합니다. #33

Merged
merged 47 commits into from
May 28, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
6f04e7e
refactor: 함수 간소화
hyemdooly May 15, 2023
e7af72c
refactor: supportActionBar Label 설정 삭제, manifest 이용
hyemdooly May 15, 2023
6977e5f
refactor: test 코드 수정
hyemdooly May 15, 2023
8c85cf2
feat: ProductList 상품 장바구니 추가 뷰 수정
hyemdooly May 16, 2023
723c091
docs: 3단계 요구사항 정리
hyemdooly May 16, 2023
b528d57
feat: 장바구니 버튼 생성
hyemdooly May 16, 2023
fd660c5
feat: ProductDetail 수량 선택 Dialog 구현
hyemdooly May 16, 2023
e9a1b6c
feat: CartActivity 하단 뷰 구현
hyemdooly May 16, 2023
7181e9b
feat: CartActivity Item layout 변경사항 수정
hyemdooly May 16, 2023
27b2a1b
feat: cart badge 생성
hyemdooly May 17, 2023
dd70d3b
feat: ProductListActivity List Count 구현
hyemdooly May 17, 2023
e230169
feat: ProductListActivity AppBar Cart Badge 구현
hyemdooly May 17, 2023
15dc571
feat: ProductDetailActivity 마지막으로 본 상품 startActivity
hyemdooly May 17, 2023
588a1ee
feat: ProductDetailActivity 다른 액티비티 실행 시 Stack 조절
hyemdooly May 17, 2023
dc79515
feat: Cart 아이콘 장바구니 비었으면 Gone으로 수정
hyemdooly May 17, 2023
7d0a2e3
feat: Cart 아이콘 장바구니 비었으면 Gone으로 수정
hyemdooly May 17, 2023
8f145f4
Merge remote-tracking branch 'origin/step4' into step4
hyemdooly May 17, 2023
9370658
feat: ProductListPresenter에서 삭제했던 최근 본 상품 복구
hyemdooly May 18, 2023
0337194
refactor: domain 코드 이동, ktlintformat
hyemdooly May 18, 2023
3e7fc30
feat: CartActivity 상품 개수 업데이트 구현
hyemdooly May 18, 2023
1c419ad
feat: CartActivity, CartSystem 선택 구현 (리팩토링 필수)
hyemdooly May 18, 2023
49e6293
feat: ProductListActivity <-> CartActivity 데이터 동일하게 연동
hyemdooly May 18, 2023
3200e3a
refactor: CartActivity LiveData 활용 리팩터링
hyemdooly May 19, 2023
cbcd2f4
refactor: DataBinding format 수정
hyemdooly May 19, 2023
01b5db9
fix: CartActivity 버그 수정
hyemdooly May 20, 2023
57a2b4d
refactor: ProductListActivity Presenter 리팩터링
hyemdooly May 20, 2023
f6d3645
fix: ProductListActivity Presenter 리팩터링 및 버그 수정
hyemdooly May 20, 2023
b5e1269
refactor: CartPresenterTest 코드 수정에 맞게 리팩터링 및 수정
hyemdooly May 20, 2023
dc3106f
refactor: ProductDetailPresenterTest 리팩터링 및 수정
hyemdooly May 20, 2023
47cb4a5
refactor: ProductListPresenterTest 수정, CartPresenterTest 테스트 통과 안되는 …
hyemdooly May 20, 2023
e23cdba
refactor: formatting
hyemdooly May 20, 2023
65cade1
feat: 4단계 MockServer 구현 및 적용
hyemdooly May 21, 2023
b3e732f
refactor: 강제종료 버그 수정, 패키지 정리
hyemdooly May 21, 2023
6869b1f
fix: 최근 본 상품 반대로 나오는 버그 수정, ProductDetialActivity 다이얼로그 dismiss 추가
hyemdooly May 21, 2023
ebdc9bd
docs: README 업데이트
hyemdooly May 21, 2023
ba1d77f
fix: 갯수 제한 걸리는 버그 수정
hyemdooly May 23, 2023
2797d74
Merge remote-tracking branch 'origin/step4' into step4
hyemdooly May 23, 2023
5cf4f06
refactor: CartProductModel의 isChecked, count variable -> valuable로 변경
hyemdooly May 27, 2023
c291ea5
refactor: ProductModel variable -> valuable로 수정
hyemdooly May 27, 2023
508e204
refactor: backing property 변수 위치 수정
hyemdooly May 27, 2023
b04a4af
refactor: lateinit var -> by lazy로 최대한 수정
hyemdooly May 27, 2023
8d09837
refactor: presenter에서 데이터를 내려주도록 수정
hyemdooly May 27, 2023
a9268da
refactor: AppCompatButton -> Button으로 수정
hyemdooly May 27, 2023
9bac38d
refactor: 요구사항에 없는 내용 삭제
hyemdooly May 27, 2023
261e924
refactor: 테스트코드 로직 최대한 삭제
hyemdooly May 27, 2023
9ec4930
refactor: ProductViewHolder 생성자에서 onClick 등록
hyemdooly May 27, 2023
1227d57
refactor: plus, minus 한계치 수정
hyemdooly May 27, 2023
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
Prev Previous commit
Next Next commit
refactor: 강제종료 버그 수정, 패키지 정리
  • Loading branch information
hyemdooly committed May 21, 2023
commit b3e732fac14e01fb4c3198da1144830e0abac28e
3 changes: 0 additions & 3 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,4 @@ dependencies {
implementation("com.github.bumptech.glide:glide:4.15.1")
testImplementation("io.mockk:mockk:1.13.5")
testImplementation("androidx.arch.core:core-testing:2.2.0")
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.okhttp3:mockwebserver:4.10.0")
implementation("org.json:json:20210307")
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.model.CartProduct

class CartDBHelper(context: Context) : SQLiteOpenHelper(context, "cart", null, 1) {
override fun onCreate(db: SQLiteDatabase?) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package woowacourse.shopping.data
package woowacourse.shopping.data.repository

import android.content.Context
import woowacourse.shopping.data.db.CartDBHelper
import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.repository.CartRepository

class CartDbRepository(context: Context) : CartRepository {
private val dbHelper = CartDBHelper(context)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package woowacourse.shopping.data
package woowacourse.shopping.data.repository

import woowacourse.shopping.domain.Price
import woowacourse.shopping.domain.Product
import woowacourse.shopping.domain.ProductRepository
import woowacourse.shopping.domain.model.Price
import woowacourse.shopping.domain.model.Product
import woowacourse.shopping.domain.repository.ProductRepository

object ProductMockRepository : ProductRepository {
private val products = listOf(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package woowacourse.shopping.data
package woowacourse.shopping.data.repository

import android.content.Context
import woowacourse.shopping.data.db.RecentViewedDBHelper
import woowacourse.shopping.domain.RecentViewedRepository
import woowacourse.shopping.domain.repository.RecentViewedRepository

class RecentViewedDbRepository(context: Context) :
RecentViewedRepository {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package woowacourse.shopping.model

import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.Product
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.model.Product

fun CartProduct.toUiModel(isChecked: Boolean = false, product: Product): CartProductModel =
CartProductModel(isChecked, id, product.name, product.imageUrl, count, product.price.price)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
package woowacourse.shopping.model

import woowacourse.shopping.domain.Product
import woowacourse.shopping.domain.model.Product

fun Product.toUiModel(count: Int = 0) = ProductModel(id, name, imageUrl, price.price, count)
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@ import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.appcompat.app.AppCompatActivity
import woowacourse.shopping.data.CartDbRepository
import woowacourse.shopping.data.MockServer
import woowacourse.shopping.data.ProductMockRepository
import woowacourse.shopping.data.ProductRemoteRepository
import woowacourse.shopping.data.repository.CartDbRepository
import woowacourse.shopping.domain.repository.ProductRemoteRepository
import woowacourse.shopping.databinding.ActivityCartBinding
import woowacourse.shopping.domain.data.MockServer
import woowacourse.shopping.model.CartProductModel
import woowacourse.shopping.view.productlist.ProductListActivity

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package woowacourse.shopping.view.cart

import androidx.lifecycle.LiveData
import woowacourse.shopping.domain.CartPageStatus
import woowacourse.shopping.domain.CartSystemResult
import woowacourse.shopping.domain.cartsystem.CartPageStatus
import woowacourse.shopping.domain.cartsystem.CartSystemResult
import woowacourse.shopping.model.CartProductModel

interface CartContract {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package woowacourse.shopping.view.cart

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import woowacourse.shopping.domain.CartPageStatus
import woowacourse.shopping.domain.CartPagination
import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.domain.CartSystem
import woowacourse.shopping.domain.CartSystemResult
import woowacourse.shopping.domain.ProductRepository
import woowacourse.shopping.domain.cartsystem.CartPageStatus
import woowacourse.shopping.domain.pagination.CartPagination
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.cartsystem.CartSystem
import woowacourse.shopping.domain.cartsystem.CartSystemResult
import woowacourse.shopping.domain.repository.ProductRepository
import woowacourse.shopping.model.CartProductModel
import woowacourse.shopping.model.toDomain
import woowacourse.shopping.model.toUiModel
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package woowacourse.shopping.view.cart

import woowacourse.shopping.domain.CartPageStatus
import woowacourse.shopping.domain.cartsystem.CartPageStatus
import woowacourse.shopping.model.CartProductModel

sealed interface CartViewItem {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import com.bumptech.glide.Glide
import woowacourse.shopping.R
import woowacourse.shopping.data.CartDbRepository
import woowacourse.shopping.data.RecentViewedDbRepository
import woowacourse.shopping.data.repository.CartDbRepository
import woowacourse.shopping.data.repository.RecentViewedDbRepository
import woowacourse.shopping.databinding.ActivityProductDetailBinding
import woowacourse.shopping.databinding.DialogCountBinding
import woowacourse.shopping.model.ProductModel
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package woowacourse.shopping.view.productdetail

import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.domain.RecentViewedRepository
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.repository.RecentViewedRepository
import woowacourse.shopping.model.ProductModel

class ProductDetailPresenter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ import android.widget.Toast
import androidx.activity.result.contract.ActivityResultContracts
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.GridLayoutManager
import okhttp3.mockwebserver.MockWebServer
import woowacourse.shopping.R
import woowacourse.shopping.data.*
import woowacourse.shopping.data.repository.CartDbRepository
import woowacourse.shopping.data.repository.RecentViewedDbRepository
import woowacourse.shopping.databinding.ActivityProductListBinding
import woowacourse.shopping.domain.data.MockServer
import woowacourse.shopping.domain.repository.ProductRemoteRepository
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.view.cart.CartActivity
import woowacourse.shopping.view.productdetail.ProductDetailActivity
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package woowacourse.shopping.view.productlist

import woowacourse.shopping.domain.*
import woowacourse.shopping.domain.model.Product
import woowacourse.shopping.domain.pagination.ProductListPagination
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.repository.ProductRepository
import woowacourse.shopping.domain.repository.RecentViewedRepository
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.model.toUiModel

Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_cart_pagination.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<variable
name="status"
type="woowacourse.shopping.domain.CartPageStatus" />
type="woowacourse.shopping.domain.cartsystem.CartPageStatus" />

<variable
name="onItemClick"
Expand Down
12 changes: 6 additions & 6 deletions app/src/test/java/woowacourse/shopping/CartPresenterTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import woowacourse.shopping.domain.CartPageStatus
import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.domain.Price
import woowacourse.shopping.domain.Product
import woowacourse.shopping.domain.ProductRepository
import woowacourse.shopping.domain.cartsystem.CartPageStatus
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.model.Price
import woowacourse.shopping.domain.model.Product
import woowacourse.shopping.domain.repository.ProductRepository
import woowacourse.shopping.model.CartProductModel
import woowacourse.shopping.view.cart.CartContract
import woowacourse.shopping.view.cart.CartPresenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.domain.RecentViewedRepository
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.repository.RecentViewedRepository
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.view.productdetail.ProductDetailContract
import woowacourse.shopping.view.productdetail.ProductDetailPresenter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,12 @@ import junit.framework.Assert.assertNull
import org.junit.Assert.assertEquals
import org.junit.Before
import org.junit.Test
import woowacourse.shopping.domain.*
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.model.Price
import woowacourse.shopping.domain.model.Product
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.repository.ProductRepository
import woowacourse.shopping.domain.repository.RecentViewedRepository
import woowacourse.shopping.model.ProductModel
import woowacourse.shopping.view.productlist.ProductListContract
import woowacourse.shopping.view.productlist.ProductListPresenter
Expand Down
7 changes: 5 additions & 2 deletions domain/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ plugins {
}

java {
sourceCompatibility = JavaVersion.VERSION_1_7
targetCompatibility = JavaVersion.VERSION_1_7
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}

dependencies {
implementation("com.squareup.okhttp3:okhttp:4.10.0")
implementation("com.squareup.okhttp3:mockwebserver:4.10.0")
implementation("org.json:json:20210307")
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.cartsystem

data class CartPageStatus(
val isPrevEnabled: Boolean,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.cartsystem

import woowacourse.shopping.domain.repository.ProductRepository
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.model.Price

class CartSystem(
private val productRepository: ProductRepository
Expand All @@ -17,7 +21,6 @@ class CartSystem(
val price = productRepository.find(product.id).price
_selectedProducts.add(CartSystemProduct(product, price))
totalPrice += price * product.count
println("Add : $_selectedProducts | total: $totalPrice")
return CartSystemResult(totalPrice.price, _selectedProducts.size)
}
return deselectProduct(product.id)
Expand All @@ -28,19 +31,16 @@ class CartSystem(
?: throw java.lang.IllegalArgumentException()
totalPrice -= product.price * product.cartProduct.count
_selectedProducts.remove(product)
println("Delete : $product | total: $totalPrice")
return CartSystemResult(totalPrice.price, _selectedProducts.size)
}

fun updateProduct(id: Int, count: Int): CartSystemResult {
val index = _selectedProducts.indexOfFirst { it.cartProduct.id == id }
if (index == -1) return CartSystemResult(totalPrice.price, _selectedProducts.size)

println("Before : ${_selectedProducts[index]}")
val diff = count - _selectedProducts[index].cartProduct.count
totalPrice += _selectedProducts[index].price.price * diff
_selectedProducts[index] = CartSystemProduct(CartProduct(id, count), _selectedProducts[index].price)
println("After : ${_selectedProducts[index]}")

return CartSystemResult(totalPrice.price, _selectedProducts.size)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package woowacourse.shopping.domain.cartsystem

import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.model.Price

data class CartSystemProduct(val cartProduct: CartProduct, val price: Price)
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.cartsystem

data class CartSystemResult(val totalPrice: Int, val totalCount: Int)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.shopping.data
package woowacourse.shopping.domain.data

import okhttp3.mockwebserver.Dispatcher
import okhttp3.mockwebserver.MockResponse
Expand Down Expand Up @@ -29,6 +29,13 @@ class MockServer {
.setResponseCode(200)
.setBody(getProducts(0, 100))
}
path.startsWith("/products/") -> {
val productId = path.substringAfterLast("/")
MockResponse()
.setHeader("Content-Type", "application/json")
.setResponseCode(200)
.setBody(getProductById(productId))
}
path.startsWith("/products") -> {
val parameters = getParameters(path)
val offset = parameters["mark"]?.toIntOrNull()
Expand All @@ -39,13 +46,6 @@ class MockServer {
.setResponseCode(200)
.setBody(getProducts(offset, count))
}
path.startsWith("/products/") -> {
val productId = path.substringAfterLast("/")
MockResponse()
.setHeader("Content-Type", "application/json")
.setResponseCode(200)
.setBody(getProductById(productId))
}
else -> {
MockResponse().setResponseCode(404)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.model

data class CartProduct(val id: Int, val count: Int)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.model

@JvmInline
value class Price(val price: Int) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.model

data class Product(val id: Int, val name: String, val imageUrl: String, val price: Price) {
companion object
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.pagination

import woowacourse.shopping.domain.CartProduct
import woowacourse.shopping.domain.CartRepository
import woowacourse.shopping.domain.CartPageStatus
import woowacourse.shopping.domain.NextPagination
import woowacourse.shopping.domain.PrevPagination
import woowacourse.shopping.domain.model.CartProduct
import woowacourse.shopping.domain.repository.CartRepository
import woowacourse.shopping.domain.cartsystem.CartPageStatus

class CartPagination(private val rangeSize: Int, private val cartRepository: CartRepository) :
NextPagination<CartProduct>, PrevPagination<CartProduct> {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.pagination

interface NextPagination<T> {
val isNextEnabled: Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.pagination

interface PrevPagination<T> {
val isPrevEnabled: Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
package woowacourse.shopping.domain
package woowacourse.shopping.domain.pagination

import woowacourse.shopping.domain.model.Product
import woowacourse.shopping.domain.pagination.NextPagination
import woowacourse.shopping.domain.repository.ProductRepository

class ProductListPagination(
private val rangeSize: Int,
Expand Down
Loading