Exemplo n.º 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);
  }
Exemplo n.º 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);
  }