-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: 꿀조합 검색 기능 controller 및 dto 추가 * feat: 검색어가 포함된 상품이 있는 꿀조합 목록 조회하는 RecipeRepository 메서드 추가 * feat: 꿀조합 검색 기능 구현 * test: 꿀조합 검색 관련 repository 테스트 추가 * test: 꿀조합 검색 관련 인수 테스트 추가
- Loading branch information
1 parent
d50f559
commit 1f43c9e
Showing
9 changed files
with
304 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
backend/src/main/java/com/funeat/recipe/dto/SearchRecipeResultDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
package com.funeat.recipe.dto; | ||
|
||
import com.funeat.product.domain.Product; | ||
import com.funeat.recipe.domain.Recipe; | ||
import com.funeat.recipe.domain.RecipeImage; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class SearchRecipeResultDto { | ||
|
||
private final Long id; | ||
private final String image; | ||
private final String title; | ||
private final RecipeAuthorDto author; | ||
private final List<ProductRecipeDto> products; | ||
private final Long favoriteCount; | ||
private final LocalDateTime createdAt; | ||
|
||
public SearchRecipeResultDto(final Long id, final String image, final String title, final RecipeAuthorDto author, | ||
final List<ProductRecipeDto> products, final Long favoriteCount, | ||
final LocalDateTime createdAt) { | ||
this.id = id; | ||
this.image = image; | ||
this.title = title; | ||
this.author = author; | ||
this.products = products; | ||
this.favoriteCount = favoriteCount; | ||
this.createdAt = createdAt; | ||
} | ||
|
||
public static SearchRecipeResultDto toDto(final Recipe recipe, final List<RecipeImage> images, | ||
final List<Product> products) { | ||
final List<ProductRecipeDto> productRecipes = products.stream() | ||
.map(ProductRecipeDto::toDto) | ||
.collect(Collectors.toList()); | ||
|
||
if (images.isEmpty()) { | ||
return new SearchRecipeResultDto(recipe.getId(), null, recipe.getTitle(), | ||
RecipeAuthorDto.toDto(recipe.getMember()), productRecipes, recipe.getFavoriteCount(), | ||
recipe.getCreatedAt()); | ||
} | ||
return new SearchRecipeResultDto(recipe.getId(), images.get(0).getImage(), recipe.getTitle(), | ||
RecipeAuthorDto.toDto(recipe.getMember()), productRecipes, recipe.getFavoriteCount(), | ||
recipe.getCreatedAt()); | ||
} | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public String getImage() { | ||
return image; | ||
} | ||
|
||
public String getTitle() { | ||
return title; | ||
} | ||
|
||
public RecipeAuthorDto getAuthor() { | ||
return author; | ||
} | ||
|
||
public List<ProductRecipeDto> getProducts() { | ||
return products; | ||
} | ||
|
||
public Long getFavoriteCount() { | ||
return favoriteCount; | ||
} | ||
|
||
public LocalDateTime getCreatedAt() { | ||
return createdAt; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
backend/src/main/java/com/funeat/recipe/dto/SearchRecipeResultsResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.funeat.recipe.dto; | ||
|
||
import com.funeat.common.dto.PageDto; | ||
import java.util.List; | ||
|
||
public class SearchRecipeResultsResponse { | ||
|
||
private final PageDto page; | ||
private final List<SearchRecipeResultDto> recipes; | ||
|
||
public SearchRecipeResultsResponse(final PageDto page, final List<SearchRecipeResultDto> recipes) { | ||
this.page = page; | ||
this.recipes = recipes; | ||
} | ||
|
||
public static SearchRecipeResultsResponse toResponse(final PageDto page, | ||
final List<SearchRecipeResultDto> recipes) { | ||
return new SearchRecipeResultsResponse(page, recipes); | ||
} | ||
|
||
public PageDto getPage() { | ||
return page; | ||
} | ||
|
||
public List<SearchRecipeResultDto> getRecipes() { | ||
return recipes; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.