コード例 #1
0
ファイル: ItemController.java プロジェクト: lapula/MyPage
  @RequestMapping(
      value = "/deleteReservation/{itemId}/reservation/{reservationId}",
      method = RequestMethod.POST)
  public String deleteItemReservation(
      @PathVariable String id, @PathVariable Long itemId, @PathVariable Long reservationId) {

    Reservation reservation = reservationRepository.findOne(reservationId);
    Item item = itemRepository.findOne(itemId);
    int index = 0;
    int mem = -1;

    for (Reservation r : item.getReservedBy()) {
      if (r.getId().equals(reservationId)) {
        mem = index;
      }
      index++;
    }

    if (mem != -1) {
      item.getReservedBy().remove(mem);
    }
    item.setReserved(item.getReserved() - reservation.getAmount());
    itemRepository.save(item);
    reservationRepository.delete(reservation);

    return "redirect:/tapahtumat/" + id;
  }
コード例 #2
0
ファイル: ItemController.java プロジェクト: lapula/MyPage
  @RequestMapping(value = "/varaa/{itemId}", method = RequestMethod.POST)
  public String makeReservations(
      @PathVariable String id,
      @PathVariable Long itemId,
      @RequestParam("reserveAmount") Integer reserveAmount,
      @RequestParam("reserverName") String reserverName,
      RedirectAttributes redirectAttributes) {

    Item item = itemRepository.findOne(itemId);
    Reservation reservation = new Reservation();
    reservation.setAmount(reserveAmount);
    reservation.setName(reserverName);
    reservation.setItem(item);
    reservation = reservationRepository.save(reservation);

    item.getReservedBy().add(reservation);
    item.setReserved(item.getReserved() + reserveAmount);
    item = itemRepository.save(item);

    redirectAttributes.addFlashAttribute("lastReservation", reservation.getId());
    redirectAttributes.addFlashAttribute("lastReservationItem", item.getId());

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