Example #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;
  }
Example #2
0
  @RequestMapping(value = "/lisaa", method = RequestMethod.POST)
  public String createNewItem(
      @Valid @ModelAttribute Item item, BindingResult bindingResult, @PathVariable String id) {

    if (bindingResult.hasFieldErrors("name") || bindingResult.hasFieldErrors("amount")) {
      return "tavarat";
    }
    ItemList itemList = itemListRepository.findById(id);
    if (!itemList.getPerson().getId().equals(getPersonId())) {
      throw new IllegalAccessError();
    }
    item.setItemList(itemList);
    item.setReserved(0);
    item.setReservedBy(new ArrayList<>());
    item.setId(null);
    item = itemRepository.save(item);

    itemList.getItems().add(item);
    itemListRepository.save(itemList);

    return "redirect:/tapahtumat/" + id;
  }
Example #3
0
  @RequestMapping(value = "/delete/{itemId}", method = RequestMethod.POST)
  public String deleteItemList(@PathVariable String id, @PathVariable Long itemId) {

    ItemList itemList = itemListRepository.findById(id);
    if (!itemList.getPerson().getId().equals(getPersonId())) {
      throw new IllegalAccessError();
    }

    Item item = itemRepository.findOne(itemId);
    reservationRepository.delete(item.getReservedBy());
    itemRepository.delete(item);

    return "redirect:/tapahtumat/" + id;
  }
Example #4
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;
  }