From 3f135cca0591b67bbe831b883fd6b35221ddaaad Mon Sep 17 00:00:00 2001 From: gurdl7011 Date: Fri, 17 Nov 2023 18:51:56 +0900 Subject: [PATCH] =?UTF-8?q?=E2=AD=90=EF=B8=8F=20::=20shop=20all=20list?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../shop/presentation/ShopController.kt | 4 ++++ .../dto/response/ShopAllListResponse.kt | 6 ++++++ .../dto/response/ShopAllResponse.kt | 10 ++++++++++ .../onui/domain/shop/service/ShopService.kt | 3 +++ .../domain/shop/service/ShopServiceImpl.kt | 19 +++++++++++++++++-- 5 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllListResponse.kt create mode 100644 src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllResponse.kt diff --git a/src/main/kotlin/com/example/onui/domain/shop/presentation/ShopController.kt b/src/main/kotlin/com/example/onui/domain/shop/presentation/ShopController.kt index a450c98..21cf66c 100644 --- a/src/main/kotlin/com/example/onui/domain/shop/presentation/ShopController.kt +++ b/src/main/kotlin/com/example/onui/domain/shop/presentation/ShopController.kt @@ -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 @@ -20,4 +21,7 @@ class ShopController( @GetMapping fun getShop(): ShopListResponse = shopService.getShopList() + + @GetMapping("/all") + fun getAllShop(): ShopAllListResponse = shopService.getAllShopList() } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllListResponse.kt b/src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllListResponse.kt new file mode 100644 index 0000000..54e3482 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllListResponse.kt @@ -0,0 +1,6 @@ +package com.example.onui.domain.shop.presentation.dto.response + +data class ShopAllListResponse( + + val themeList: MutableList +) diff --git a/src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllResponse.kt b/src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllResponse.kt new file mode 100644 index 0000000..d48a5d9 --- /dev/null +++ b/src/main/kotlin/com/example/onui/domain/shop/presentation/dto/response/ShopAllResponse.kt @@ -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 +) diff --git a/src/main/kotlin/com/example/onui/domain/shop/service/ShopService.kt b/src/main/kotlin/com/example/onui/domain/shop/service/ShopService.kt index 9632944..3758afa 100644 --- a/src/main/kotlin/com/example/onui/domain/shop/service/ShopService.kt +++ b/src/main/kotlin/com/example/onui/domain/shop/service/ShopService.kt @@ -1,5 +1,6 @@ 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 { @@ -7,4 +8,6 @@ interface ShopService { fun buy(id: String): ShopListResponse fun getShopList(): ShopListResponse + + fun getAllShopList(): ShopAllListResponse } \ No newline at end of file diff --git a/src/main/kotlin/com/example/onui/domain/shop/service/ShopServiceImpl.kt b/src/main/kotlin/com/example/onui/domain/shop/service/ShopServiceImpl.kt index a316317..ca83305 100644 --- a/src/main/kotlin/com/example/onui/domain/shop/service/ShopServiceImpl.kt +++ b/src/main/kotlin/com/example/onui/domain/shop/service/ShopServiceImpl.kt @@ -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 @@ -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 @@ -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))