Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weโ€™ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/register food #51

Merged
merged 2 commits into from
Nov 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/FoodController.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ public CommonResponse<HomeResponseDto> getInfoFromHome(@Auth AuthInfo authInfo)
@Operation(summary = "ํŠน์ • ์นดํ…Œ๊ณ ๋ฆฌ์— ์†ํ•˜๋Š” ๋ฉ”๋‰ด ์กฐํšŒํ•˜๊ธฐ")
@GetMapping("/category/{categoryId}")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<List<FoodPreviewResponse>> getFoodByCategory(@PathVariable Long categoryId) {
return new CommonResponse<>(foodService.getFoodByCategory(categoryId));
public CommonResponse<List<FoodPreviewResponse>> getFoodByCategory(@Auth AuthInfo authInfo, @PathVariable Long categoryId) {
return new CommonResponse<>(foodService.getFoodByCategory(authInfo, categoryId));
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/kusitms/jipbap/food/FoodRepository.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.kusitms.jipbap.store.Store;
import com.kusitms.jipbap.store.StoreRepositoryExtension;
import com.kusitms.jipbap.user.User;
import com.kusitms.jipbap.user.entity.GlobalRegion;
import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;
Expand All @@ -11,6 +12,6 @@
public interface FoodRepository extends JpaRepository<Food, Long>, FoodRepositoryExtension {

List<Food> findAllByStore(Store store);

List<Food> findAllByCategory(Category category);
List<Food> findByStoreGlobalRegionAndCategory(GlobalRegion globalRegion, Category category);
}
9 changes: 7 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@
import com.kusitms.jipbap.food.exception.CategoryNotExistsException;
import com.kusitms.jipbap.food.exception.FoodNotExistsException;
import com.kusitms.jipbap.order.OrderRepository;
import com.kusitms.jipbap.security.AuthInfo;
import com.kusitms.jipbap.store.Store;
import com.kusitms.jipbap.store.StoreRepository;
import com.kusitms.jipbap.store.exception.StoreNotExistsException;
import com.kusitms.jipbap.user.User;
import com.kusitms.jipbap.user.UserRepository;
import com.kusitms.jipbap.user.entity.GlobalRegion;
import com.kusitms.jipbap.user.exception.UserNotFoundException;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
Expand Down Expand Up @@ -179,10 +181,13 @@ private List<FoodPreviewResponse> getLatestSellingFoodByRegion(Long globalRegion
return latestSellingFoodResponseList;
}

public List<FoodPreviewResponse> getFoodByCategory(Long categoryId){
public List<FoodPreviewResponse> getFoodByCategory(AuthInfo authInfo, Long categoryId){
User user = userRepository.findByEmail(authInfo.getEmail()).orElseThrow(()-> new UserNotFoundException("์œ ์ € ์ •๋ณด๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."));
Category category = categoryRepository.findById(categoryId).orElseThrow(()-> new CategoryNotExistsException("ํ•ด๋‹น ์นดํ…Œ๊ณ ๋ฆฌ Id๋Š” ์œ ํšจํ•˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค."));

List<Food> foodList = foodRepository.findAllByCategory(category);
GlobalRegion globalRegion = user.getGlobalRegion();

List<Food> foodList = foodRepository.findByStoreGlobalRegionAndCategory(globalRegion, category);

List<FoodPreviewResponse> foodDtoList = foodList.stream()
.map(food -> new FoodPreviewResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ public class FoodDetailResponse {
private String name;
private Long dollarPrice;
private Long canadaPrice;
private String description;
private String image;
private String description;
private String foodPackage;
private String informationDescription;
private String ingredient;
private List<FoodOptionResponse> foodOptionResponseList;
}
Loading