Пример #1
0
  public void create(Category category) throws Exception {
    Category categoryDoc = categoryRepo.findByIdOrName(category.getId(), category.getName());

    if (categoryDoc != null) {
      throw new Exception("category exists");
    }

    categoryRepo.save(category);
  }
Пример #2
0
  public void update(Category category) throws Exception {
    Category categoryDoc = categoryRepo.findByIdOrName(category.getId(), category.getName());

    if (categoryDoc == null) {
      throw new Exception("can't found category");
    }

    category.setId(categoryDoc.getId());
    category.setRecipes(categoryDoc.getRecipes());

    categoryRepo.save(category);
  }
Пример #3
0
 public void deleteAll() {
   categoryRepo.deleteAll();
 }
Пример #4
0
 public void delete(Category category) {
   categoryRepo.delete(category);
 }
Пример #5
0
 public List<Category> readAll() {
   return categoryRepo.findAll();
 }
Пример #6
0
 public Category read(String id) {
   return categoryRepo.findOne(id);
 }