-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
10abe09
commit d1f1926
Showing
7 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
3 changes: 2 additions & 1 deletion
3
src/main/java/capstone/recipable/domain/bookmark/repository/BookmarkRepository.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 |
---|---|---|
@@ -1,11 +1,12 @@ | ||
package capstone.recipable.domain.bookmark.repository; | ||
|
||
import capstone.recipable.domain.bookmark.entity.Bookmark; | ||
import capstone.recipable.domain.bookmark.repository.custom.BookmarkRepositoryCustom; | ||
import capstone.recipable.domain.user.entity.User; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
import java.util.List; | ||
|
||
public interface BookmarkRepository extends JpaRepository<Bookmark, Long> { | ||
public interface BookmarkRepository extends JpaRepository<Bookmark, Long>, BookmarkRepositoryCustom { | ||
List<Bookmark> findAllByUser(User user); | ||
} |
8 changes: 8 additions & 0 deletions
8
...n/java/capstone/recipable/domain/bookmark/repository/custom/BookmarkRepositoryCustom.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,8 @@ | ||
package capstone.recipable.domain.bookmark.repository.custom; | ||
|
||
import capstone.recipable.domain.recipe.entity.Recipe; | ||
import capstone.recipable.domain.user.entity.User; | ||
|
||
public interface BookmarkRepositoryCustom { | ||
boolean isBookmarked(User user, Recipe recipe); | ||
} |
22 changes: 22 additions & 0 deletions
22
...ain/java/capstone/recipable/domain/bookmark/repository/custom/BookmarkRepositoryImpl.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,22 @@ | ||
package capstone.recipable.domain.bookmark.repository.custom; | ||
|
||
import capstone.recipable.domain.recipe.entity.Recipe; | ||
import capstone.recipable.domain.user.entity.User; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
|
||
import static capstone.recipable.domain.bookmark.entity.QBookmark.bookmark; | ||
|
||
@RequiredArgsConstructor | ||
public class BookmarkRepositoryImpl implements BookmarkRepositoryCustom { | ||
|
||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
@Override | ||
public boolean isBookmarked(User user, Recipe recipe) { | ||
return jpaQueryFactory | ||
.selectFrom(bookmark) | ||
.where(bookmark.user.eq(user).and(bookmark.recipe.eq(recipe))) | ||
.fetchOne() != null; | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
src/main/java/capstone/recipable/domain/recipe/dto/response/CreateRecipeResponse.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,47 @@ | ||
package capstone.recipable.domain.recipe.dto.response; | ||
|
||
import capstone.recipable.domain.bookmark.repository.BookmarkRepository; | ||
import capstone.recipable.domain.recipe.entity.Recipe; | ||
import lombok.*; | ||
|
||
import java.util.List; | ||
|
||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@AllArgsConstructor(access = AccessLevel.PRIVATE) | ||
@Getter | ||
@Builder | ||
public class CreateRecipeResponse { | ||
private Long recipeId; | ||
|
||
private String recipeName; | ||
|
||
private String introduce; | ||
|
||
private String recipeImg; | ||
|
||
private String ingredients; | ||
|
||
private String recipeDetails; | ||
|
||
private List<RecipeVideoResponse> recipeVideoResponses; | ||
|
||
private boolean bookmark = false; | ||
|
||
public static CreateRecipeResponse of(Recipe recipe) { | ||
List<RecipeVideoResponse> responses = recipe.getRecipeVideos().stream() | ||
.map(recipeVideos -> RecipeVideoResponse.of(recipeVideos.getVideoUrl(), | ||
recipeVideos.getTitle(), | ||
recipeVideos.getThumbnail())) | ||
.toList(); | ||
|
||
return CreateRecipeResponse.builder() | ||
.recipeId(recipe.getId()) | ||
.recipeName(recipe.getRecipeName()) | ||
.introduce(recipe.getIntroduce()) | ||
.recipeImg(recipe.getRecipeImg()) | ||
.ingredients(recipe.getIngredients()) | ||
.recipeDetails(recipe.getRecipeDetails()) | ||
.recipeVideoResponses(responses) | ||
.build(); | ||
} | ||
} |
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