Beispiel #1
0
  @RequestMapping(value = "lisaaKommentti", method = RequestMethod.POST)
  public String addCommentToItemList(@PathVariable String id, @RequestParam String comment) {

    ItemList itemList = itemListRepository.findById(id);
    itemList.getComments().add(comment);
    itemListRepository.save(itemList);

    return "redirect:/tapahtumat/" + id;
  }
Beispiel #2
0
  @RequestMapping(value = "/deleteComment", method = RequestMethod.POST)
  public String deleteComment(@PathVariable String id, @RequestParam String comment) {

    ItemList itemList = itemListRepository.findById(id);
    if (!itemList.getPerson().getId().equals(getPersonId())) {
      throw new IllegalAccessError();
    }
    int index = 0;
    int mem = -1;
    for (String c : itemList.getComments()) {
      if (c.equals(comment)) {
        mem = index;
      }
      index++;
    }

    if (mem != -1) {
      itemList.getComments().remove(mem);
    }

    itemListRepository.save(itemList);

    return "redirect:/tapahtumat/" + id;
  }