Skip to content

Commit

Permalink
MARA-83 : FE API 연동 테스트 리팩토링 3차 (#41)
Browse files Browse the repository at this point in the history
* FriendRefrigeratorResponse userId 추가

* IngredientDetail 조회시 iconImage 경로 추가

* ingradientImage -> iconImage 변수명 변경
  • Loading branch information
jhkang1517 authored Feb 24, 2024
1 parent f7c439b commit 1470f35
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<FriendRefrigeratorIngredient>
) {
constructor(user: User, refrigerator: Refrigerator, ingredientList: List<Ingredient>) : this(
userId = user.userId,
nickname = user.nickname,
refrigeratorId = refrigerator.refrigeratorId,
friendRefrigeratorIngredientGroupList = ingredientList.map { FriendRefrigeratorIngredient(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ class IngredientDetailController(
size = 10
)
pageable: Pageable,
location: IngredientLocation,
@PathVariable(name = "id") refrigeratorId: Long
): CommonResponse<Page<IngredientDetailResponse>> {
return success(ingredientDetailService.getIngredientDetailList(refrigeratorId, pageable))
return success(ingredientDetailService.getIngredientDetailList(refrigeratorId, location, pageable))
}

@GetMapping("/count")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ interface CustomIngredientDetailRepository {

fun findByRefrigerator(
refrigerator: Refrigerator,
location: IngredientLocation,
pageable: Pageable
): Page<IngredientDetail>

Expand Down Expand Up @@ -50,13 +51,21 @@ class CustomIngredientDetailRepositoryImpl(
.fetch()
}

override fun findByRefrigerator(refrigerator: Refrigerator, pageable: Pageable): Page<IngredientDetail> {
override fun findByRefrigerator(refrigerator: Refrigerator, location: IngredientLocation, pageable: Pageable): Page<IngredientDetail> {
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!! }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,11 @@ class IngredientDetailService(
return IngredientDetailResponse(ingredientDetail)
}

fun getIngredientDetailList(refrigeratorId: Long, pageable: Pageable): Page<IngredientDetailResponse> {
fun getIngredientDetailList(refrigeratorId: Long, location: IngredientLocation, pageable: Pageable): Page<IngredientDetailResponse> {
val refrigerator = refrigeratorRepository.findById(refrigeratorId)
.orElseThrow { NoSuchElementException("해당 냉장고가 존재하지 않습니다. ID: $refrigeratorId") }
val ingredientDetailList =
ingredientDetailRepository.findByRefrigerator(refrigerator, pageable)
ingredientDetailRepository.findByRefrigerator(refrigerator, location, pageable)
return ingredientDetailList.toIngredientDetailResponseListPage()
}

Expand Down

0 comments on commit 1470f35

Please sign in to comment.