From 1470f35e7ee8c5320f7f1be9fd6856cd9ae4cad1 Mon Sep 17 00:00:00 2001 From: blackswitch <50973746+jhkang1517@users.noreply.github.com> Date: Sat, 24 Feb 2024 13:07:48 +0900 Subject: [PATCH] =?UTF-8?q?MARA-83=20:=20FE=20API=20=EC=97=B0=EB=8F=99=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EB=A6=AC=ED=8C=A9=ED=86=A0?= =?UTF-8?q?=EB=A7=81=203=EC=B0=A8=20(#41)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * FriendRefrigeratorResponse userId 추가 * IngredientDetail 조회시 iconImage 경로 추가 * ingradientImage -> iconImage 변수명 변경 --- .../server/domain/friend/FriendRefrigeratorDto.kt | 2 ++ .../ingredient/IngredientDetailController.kt | 3 ++- .../domain/ingredient/IngredientDetailDto.kt | 2 ++ .../ingredient/IngredientDetailRepository.kt | 15 ++++++++++++--- .../domain/ingredient/IngredientDetailService.kt | 4 ++-- 5 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorDto.kt b/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorDto.kt index b05f02e..fd4d582 100644 --- a/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorDto.kt +++ b/src/main/kotlin/mara/server/domain/friend/FriendRefrigeratorDto.kt @@ -5,11 +5,13 @@ import mara.server.domain.refrigerator.Refrigerator import mara.server.domain.user.User data class FriendRefrigeratorResponse( + var userId: Long, val nickname: String, val refrigeratorId: Long, val friendRefrigeratorIngredientGroupList: List ) { constructor(user: User, refrigerator: Refrigerator, ingredientList: List) : this( + userId = user.userId, nickname = user.nickname, refrigeratorId = refrigerator.refrigeratorId, friendRefrigeratorIngredientGroupList = ingredientList.map { FriendRefrigeratorIngredient(it) } diff --git a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailController.kt b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailController.kt index 3646f02..0c488ee 100644 --- a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailController.kt +++ b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailController.kt @@ -43,9 +43,10 @@ class IngredientDetailController( size = 10 ) pageable: Pageable, + location: IngredientLocation, @PathVariable(name = "id") refrigeratorId: Long ): CommonResponse> { - return success(ingredientDetailService.getIngredientDetailList(refrigeratorId, pageable)) + return success(ingredientDetailService.getIngredientDetailList(refrigeratorId, location, pageable)) } @GetMapping("/count") diff --git a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailDto.kt b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailDto.kt index 19b05e1..22d8067 100644 --- a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailDto.kt +++ b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailDto.kt @@ -27,6 +27,7 @@ data class IngredientDetailUpdateRequest( data class IngredientDetailResponse( val ingredientDetailId: Long, + val iconImage: String, val name: String, val quantity: Int, val location: IngredientLocation, @@ -38,6 +39,7 @@ data class IngredientDetailResponse( constructor(ingredientDetail: IngredientDetail) : this( ingredientDetailId = ingredientDetail.ingredientDetailId, + iconImage = ingredientDetail.ingredient.iconImage, name = ingredientDetail.name, quantity = ingredientDetail.quantity, location = ingredientDetail.location, diff --git a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailRepository.kt b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailRepository.kt index 36839d8..2a0aff8 100644 --- a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailRepository.kt +++ b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailRepository.kt @@ -20,6 +20,7 @@ interface CustomIngredientDetailRepository { fun findByRefrigerator( refrigerator: Refrigerator, + location: IngredientLocation, pageable: Pageable ): Page @@ -50,13 +51,21 @@ class CustomIngredientDetailRepositoryImpl( .fetch() } - override fun findByRefrigerator(refrigerator: Refrigerator, pageable: Pageable): Page { + override fun findByRefrigerator(refrigerator: Refrigerator, location: IngredientLocation, pageable: Pageable): Page { val results = queryFactory.selectFrom(ingredientDetail) - .where(ingredientDetail.refrigerator.eq(refrigerator).and(ingredientDetail.isDeleted.isFalse)) + .where( + ingredientDetail.refrigerator.eq(refrigerator).and(ingredientDetail.isDeleted.isFalse).and( + ingredientDetail.location.eq(location) + ) + ) .offset(pageable.offset).limit(pageable.pageSize.toLong()).fetch() val count = queryFactory.select(ingredientDetail.count()).from(ingredientDetail) - .where(ingredientDetail.refrigerator.eq(refrigerator).and(ingredientDetail.isDeleted.isFalse)).fetchOne() + .where( + ingredientDetail.refrigerator.eq(refrigerator).and(ingredientDetail.isDeleted.isFalse).and( + ingredientDetail.location.eq(location) + ) + ).fetchOne() return PageableExecutionUtils.getPage(results, pageable) { count!! } } diff --git a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailService.kt b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailService.kt index c4eac94..9ff5a11 100644 --- a/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailService.kt +++ b/src/main/kotlin/mara/server/domain/ingredient/IngredientDetailService.kt @@ -53,11 +53,11 @@ class IngredientDetailService( return IngredientDetailResponse(ingredientDetail) } - fun getIngredientDetailList(refrigeratorId: Long, pageable: Pageable): Page { + fun getIngredientDetailList(refrigeratorId: Long, location: IngredientLocation, pageable: Pageable): Page { val refrigerator = refrigeratorRepository.findById(refrigeratorId) .orElseThrow { NoSuchElementException("해당 냉장고가 존재하지 않습니다. ID: $refrigeratorId") } val ingredientDetailList = - ingredientDetailRepository.findByRefrigerator(refrigerator, pageable) + ingredientDetailRepository.findByRefrigerator(refrigerator, location, pageable) return ingredientDetailList.toIngredientDetailResponseListPage() }