Skip to content

Commit

Permalink
⭐️ :: shop all list
Browse files Browse the repository at this point in the history
  • Loading branch information
gurdl0525 committed Nov 17, 2023
1 parent 40cfdf6 commit 3f135cc
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.example.onui.domain.shop.presentation

import com.example.onui.domain.shop.presentation.dto.response.ShopAllListResponse
import com.example.onui.domain.shop.presentation.dto.response.ShopListResponse
import com.example.onui.domain.shop.service.ShopService
import org.springframework.validation.annotation.Validated
Expand All @@ -20,4 +21,7 @@ class ShopController(

@GetMapping
fun getShop(): ShopListResponse = shopService.getShopList()

@GetMapping("/all")
fun getAllShop(): ShopAllListResponse = shopService.getAllShopList()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.example.onui.domain.shop.presentation.dto.response

data class ShopAllListResponse(

val themeList: MutableList<ShopAllResponse>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.example.onui.domain.shop.presentation.dto.response

data class ShopAllResponse(

val themeId: String,

val price: Long,

val isBought: Boolean
)
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.example.onui.domain.shop.service

import com.example.onui.domain.shop.presentation.dto.response.ShopAllListResponse
import com.example.onui.domain.shop.presentation.dto.response.ShopListResponse

interface ShopService {

fun buy(id: String): ShopListResponse

fun getShopList(): ShopListResponse

fun getAllShopList(): ShopAllListResponse
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.example.onui.domain.shop.entity.BoughtTheme
import com.example.onui.domain.shop.exception.AlreadyBoughtThemeException
import com.example.onui.domain.shop.exception.CanNotBuyThemeException
import com.example.onui.domain.shop.presentation.dto.response.ShopAllListResponse
import com.example.onui.domain.shop.presentation.dto.response.ShopAllResponse
import com.example.onui.domain.shop.presentation.dto.response.ShopListResponse
import com.example.onui.domain.shop.repository.BoughtThemeRepository
import com.example.onui.domain.user.entity.User
Expand Down Expand Up @@ -30,8 +32,12 @@ class ShopServiceImpl(

val theme = themeRepository.findByIdOrNull(id) ?: throw ThemeNotFoundException

if (boughtThemeRepository.existsById(BoughtTheme.IdClass(theme.id, user.id)) || theme.price == 0L)
throw AlreadyBoughtThemeException
if (boughtThemeRepository.existsById(
BoughtTheme.IdClass(
theme.id, user.id
)
) || theme.price == 0L
) throw AlreadyBoughtThemeException

val rice = user.rice - theme.price

Expand All @@ -46,6 +52,15 @@ class ShopServiceImpl(
}

override fun getShopList(): ShopListResponse = getShopList(userFacade.getCurrentUser())
override fun getAllShopList(): ShopAllListResponse {
val user = userFacade.getCurrentUser()

return ShopAllListResponse(themeRepository.findAll().map {
ShopAllResponse(
it.id, it.price, it.price == 0L || boughtThemeRepository.existsById(BoughtTheme.IdClass(it.id, user.id))
)
}.toMutableList())
}

private fun getShopList(user: User) = ShopListResponse(themeRepository.findAll().filter {
it.price != 0L && !boughtThemeRepository.existsById(BoughtTheme.IdClass(it.id, user.id))
Expand Down

0 comments on commit 3f135cc

Please sign in to comment.