-
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.
Browse files
Browse the repository at this point in the history
#330 ์ํ ๊ฒ์ ๋์ ์ฟผ๋ฆฌ๋ก ๋ณ๊ฒฝ
- Loading branch information
Showing
6 changed files
with
62 additions
and
73 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
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/icebutler_server/food/repository/FoodCustom.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,9 @@ | ||
package com.example.icebutler_server.food.repository; | ||
|
||
import com.example.icebutler_server.food.entity.Food; | ||
|
||
import java.util.List; | ||
|
||
public interface FoodCustom { | ||
List<Food> searchFood(String category, String word); | ||
} |
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
34 changes: 34 additions & 0 deletions
34
src/main/java/com/example/icebutler_server/food/repository/FoodRepositoryImpl.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,34 @@ | ||
package com.example.icebutler_server.food.repository; | ||
|
||
import com.example.icebutler_server.food.entity.Food; | ||
import com.example.icebutler_server.food.entity.FoodCategory; | ||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
import static com.example.icebutler_server.food.entity.QFood.food; | ||
|
||
@RequiredArgsConstructor | ||
public class FoodRepositoryImpl implements FoodCustom { | ||
private final JPAQueryFactory jpaQueryFactory; | ||
|
||
|
||
@Override | ||
public List<Food> searchFood(String category, String word) { | ||
return jpaQueryFactory | ||
.selectFrom(food) | ||
.where(categoryEq(category), nameContains(word)) | ||
.fetch(); | ||
} | ||
|
||
private BooleanExpression categoryEq(String category) { | ||
return StringUtils.isEmpty(category) ? null : food.foodCategory.eq(FoodCategory.getFoodCategoryByName(category)); | ||
} | ||
|
||
private BooleanExpression nameContains(String word) { | ||
return StringUtils.isEmpty(word) ? null : food.foodName.contains(word); | ||
} | ||
} |
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