You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
97 lines
2.4 KiB
97 lines
2.4 KiB
package com.mousetech.gourmetj.persistence.service;
|
|
|
|
import java.io.Serializable;
|
|
import java.util.List;
|
|
import java.util.Optional;
|
|
|
|
import javax.enterprise.context.ApplicationScoped;
|
|
import javax.inject.Inject;
|
|
import javax.inject.Named;
|
|
import javax.persistence.NamedEntityGraph;
|
|
import javax.persistence.NamedNativeQuery;
|
|
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.data.jpa.repository.EntityGraph;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import com.mousetech.gourmetj.RecipeDetailBean;
|
|
import com.mousetech.gourmetj.persistence.dao.CategoryRepository;
|
|
import com.mousetech.gourmetj.persistence.dao.RecipeRepository;
|
|
import com.mousetech.gourmetj.persistence.dao.ShopcatRepository;
|
|
import com.mousetech.gourmetj.persistence.model.Category;
|
|
import com.mousetech.gourmetj.persistence.model.Ingredient;
|
|
import com.mousetech.gourmetj.persistence.model.Recipe;
|
|
import com.mousetech.gourmetj.persistence.model.Shopcat;
|
|
|
|
@Named
|
|
@ApplicationScoped
|
|
@Transactional
|
|
public class RecipeService implements Serializable {
|
|
|
|
private static final long serialVersionUID = 1L;
|
|
|
|
private static final Logger log =
|
|
LoggerFactory.getLogger(RecipeService.class);
|
|
|
|
@Inject
|
|
private RecipeRepository recipeRepository;
|
|
|
|
public List<Recipe> findAll() {
|
|
return recipeRepository.findAll();
|
|
}
|
|
|
|
public List<Recipe> findByTitle(String searchText) {
|
|
return recipeRepository
|
|
.findByTitleContaining(searchText);
|
|
}
|
|
|
|
public Recipe findByPrimaryKey(Long recipeId) {
|
|
return recipeRepository.findById(recipeId).orElse(null);
|
|
}
|
|
|
|
public Recipe findDetails(Long recipeId) {
|
|
return recipeRepository.findDetailsById(recipeId);
|
|
}
|
|
|
|
/**
|
|
* final String sql = "SELECT DISTINCT cuisine from recipe" +
|
|
* " where cuisine is not null and cuisine <> ''" + " ORDER
|
|
* BY cuisine ASC";
|
|
*
|
|
* @return
|
|
*/
|
|
|
|
public List<String> findCuisines() {
|
|
return recipeRepository.FindCuisinesNative();
|
|
}
|
|
|
|
public void save(Recipe recipe) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
public void delete(Recipe recipe) {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Inject
|
|
ShopcatRepository shopcatRepository;
|
|
|
|
public List<String> findShoppingCategories() {
|
|
return shopcatRepository.findDistinctCategoryNative();
|
|
}
|
|
|
|
@Inject
|
|
CategoryRepository categoryRepository;
|
|
|
|
/**
|
|
*
|
|
* @return All Category names that are not null/blank,
|
|
* sorted.
|
|
*/
|
|
public List<String> findCategories() {
|
|
return categoryRepository.findDistinctCategoryNative();
|
|
}
|
|
}
|
|
|