-
Notifications
You must be signed in to change notification settings - Fork 39
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
๐ 4๋จ๊ณ - ์ฅ๋ฐ๊ตฌ๋(์๋) #125
base: dothebestmayb
Are you sure you want to change the base?
Changes from all commits
629e84c
5b0959f
f07f842
3c62ca3
23ee0cd
725c508
0460aa6
12570fb
c1bded6
0fd44a7
59ef046
b176b37
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package nextstep.shoppingcart.data.datasource | ||
|
||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.MutableStateFlow | ||
import kotlinx.coroutines.flow.asStateFlow | ||
import nextstep.shoppingcart.data.model.ProductEntity | ||
|
||
/** | ||
* Room๊ณผ ๊ฐ์ ์ญํ ์ ํ๋ค๊ณ ๊ฐ์ ํ๊ณ ์์ฑํ์ต๋๋ค. | ||
*/ | ||
class ProductLocalDataSource { | ||
|
||
private val _itemsFlow = MutableStateFlow<List<ProductEntity>>(emptyList()) | ||
val itemsFlow: Flow<List<ProductEntity>> = _itemsFlow.asStateFlow() | ||
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ผ๋ฐ Flow๋ก ์ ์ธํ๋ฉด ๋ฐ์ดํฐ๋ฅผ ๋ณ๊ฒฝํ ์ ์์ด์ StateFlow๋ก ์ ์ธํ์ต๋๋ค. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ์ด ๋ฐฉ๋ฒ ๋ง๊ณ ๋ ์ค๋ฅด๋๊ฒ ์ง๊ธ์ ์๋ค์ ๐ |
||
|
||
fun replaceAll(items: List<ProductEntity>) { | ||
_itemsFlow.value = items | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,137 +1,137 @@ | ||
package nextstep.shoppingcart.data.datasource | ||
|
||
import kotlinx.coroutines.delay | ||
import nextstep.shoppingcart.data.model.ProductEntity | ||
import nextstep.shoppingcart.data.model.ProductResponse | ||
import java.util.UUID | ||
import kotlin.random.Random | ||
|
||
class ProductRemoteDataSource { | ||
|
||
private val random = Random(System.currentTimeMillis()) | ||
|
||
suspend fun fetch(): List<ProductEntity> { | ||
suspend fun fetch(): List<ProductResponse> { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. API๋ก๋ถํฐ ์ ๋ณด๋ฅผ ๋ถ๋ฌ์ค๋ ๋ฐ์ดํฐ๋ XxxResponse๋ก ์ด๋ฆ์ ๋ณ๊ฒฝํ๊ณ |
||
delay(random.nextLong(300L, 1000L)) | ||
|
||
return dummyProducts | ||
} | ||
|
||
companion object { | ||
internal val dummyProducts = listOf( | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/200/300", | ||
name = "์น์ฆ๋ฒ๊ฑฐ", | ||
price = 5500 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/250/350", | ||
name = "ํํผ๋ก๋ ํผ์", | ||
price = 13900 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/180/280", | ||
name = "์ด์ฝ๋ฆฟ ์ผ์ดํฌ", | ||
price = 8900 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/220/320", | ||
name = "์์ด์ค ์๋ฉ๋ฆฌ์นด๋ ธ", | ||
price = 4100 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/240/360", | ||
name = "ํ๋ผ์ด๋ ์นํจ", | ||
price = 16900 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/190/290", | ||
name = "๋ธ๊ธฐ ํ๋ฅดํธ", | ||
price = 7500 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/210/310", | ||
name = "ํฌ๋ก์์", | ||
price = 3200 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/230/330", | ||
name = "์ฐ์ด ๋ฎ๋ฐฅ", | ||
price = 13500 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/200/250", | ||
name = "์คํ ์ดํฌ", | ||
price = 28900 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/260/360", | ||
name = "๋ง์นด๋กฑ ์ธํธ", | ||
price = 9600 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/180/300", | ||
name = "์ด๋ฐฅ ๋ชจ๋ ", | ||
price = 19800 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/240/340", | ||
name = "๋์คํฐ ์๋ฆฌ", | ||
price = 49900 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/210/290", | ||
name = "๋ชจ์นด ๋ผ๋ผ", | ||
price = 4600 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/220/350", | ||
name = "๋ถ๊ณ ๊ธฐ ๋ฎ๋ฐฅ", | ||
price = 12500 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/250/320", | ||
name = "๋ง๊ณ ๋น์", | ||
price = 11000 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/230/300", | ||
name = "์น์ฆ ์ผ์ดํฌ", | ||
price = 7200 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/200/280", | ||
name = "๋ฐ๋ฒ ํ ํญ๋ฆฝ", | ||
price = 27800 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/260/340", | ||
name = "์์ฐ ํ์คํ", | ||
price = 15800 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/190/310", | ||
name = "ํฐ๋ผ๋ฏธ์", | ||
price = 8800 | ||
), | ||
ProductEntity( | ||
ProductResponse( | ||
id = UUID.randomUUID().toString(), | ||
imageUrl = "https://picsum.photos/220/300", | ||
name = "ํ์ฝ ์นํจ", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package nextstep.shoppingcart.data.mapper | ||
|
||
import nextstep.shoppingcart.data.model.ProductEntity | ||
import nextstep.shoppingcart.data.model.ProductResponse | ||
|
||
fun ProductResponse.toEntity(): ProductEntity { | ||
return ProductEntity( | ||
id = id, | ||
imageUrl = imageUrl, | ||
name = name, | ||
price = price, | ||
) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package nextstep.shoppingcart.data.model | ||
|
||
data class ProductResponse( | ||
val id: String, | ||
val imageUrl: String, | ||
val name: String, | ||
val price: Int, | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CartRepository์์ ์ฅ๋ฐ๊ตฌ๋์ ๋ด๊ธด ์์ดํ ์ ๋ณด๋ฅผ ๊ฐ์ง๊ณ ์๋ CartLocalDataSource๋ฅผ ProductLocalDataSource๋ก ์ด๋ฆ์ ๋ณ๊ฒฝํ๊ณ ProdcutRepository๋ก ์ฎ๊ฒผ์ต๋๋ค.