@Test public void testDDeleteEvent() { try { _eventService.delete(1L); } catch (IpatException e) { fail(String.format("Error in deleting event\nerrorCode: %s", e.getErrorInfos().get(0).getErrorCode())); } assertNull(_eventRepository.findById(1L)); assertEquals(0, _cartRepository.count()); assertEquals(0, _codeRepository.count()); }
@Transactional public void delete(Long eventId) throws IpatException { Event event = getEvent(eventId); List<Cart> cartsForEvent = cartRepository.findByEvent(event); List<Code> codesForEvent = codeRepository.findByEvent(event); for (Cart cart : cartsForEvent) { if (cart.getCartState().equals(CartState.VERIFIED)) { throw new IpatException(ErrorCodes.CART_ALREADY_REDEEMED); } } for (Cart cart : cartsForEvent) { cartRepository.delete(cart); } for (Code code : codesForEvent) { codeRepository.delete(code); } eventRepository.delete(event); }
EventService { @Transactional public void delete(Long eventId) throws IpatException { Event event = getEvent(eventId); List<Cart> cartsForEvent = cartRepository.findByEvent(event); List<Code> codesForEvent = codeRepository.findByEvent(event); for (Cart cart : cartsForEvent) { if (cart.getCartState().equals(CartState.VERIFIED)) { throw new IpatException(ErrorCodes.CART_ALREADY_REDEEMED); } } for (Cart cart : cartsForEvent) { cartRepository.delete(cart); } for (Code code : codesForEvent) { codeRepository.delete(code); } eventRepository.delete(event); } }
EventService { @Transactional public void delete(Long eventId) throws IpatException { Event event = getEvent(eventId); List<Cart> cartsForEvent = cartRepository.findByEvent(event); List<Code> codesForEvent = codeRepository.findByEvent(event); for (Cart cart : cartsForEvent) { if (cart.getCartState().equals(CartState.VERIFIED)) { throw new IpatException(ErrorCodes.CART_ALREADY_REDEEMED); } } for (Cart cart : cartsForEvent) { cartRepository.delete(cart); } for (Code code : codesForEvent) { codeRepository.delete(code); } eventRepository.delete(event); }  }
EventService { @Transactional public void delete(Long eventId) throws IpatException { Event event = getEvent(eventId); List<Cart> cartsForEvent = cartRepository.findByEvent(event); List<Code> codesForEvent = codeRepository.findByEvent(event); for (Cart cart : cartsForEvent) { if (cart.getCartState().equals(CartState.VERIFIED)) { throw new IpatException(ErrorCodes.CART_ALREADY_REDEEMED); } } for (Cart cart : cartsForEvent) { cartRepository.delete(cart); } for (Code code : codesForEvent) { codeRepository.delete(code); } eventRepository.delete(event); }  Event create(Event event); Event getEvent(Long eventId); @Transactional void delete(Long eventId); Event update(Event event); @Transactional void generateCodes(Long eventId, List<Long> cartIds); }
EventService { @Transactional public void delete(Long eventId) throws IpatException { Event event = getEvent(eventId); List<Cart> cartsForEvent = cartRepository.findByEvent(event); List<Code> codesForEvent = codeRepository.findByEvent(event); for (Cart cart : cartsForEvent) { if (cart.getCartState().equals(CartState.VERIFIED)) { throw new IpatException(ErrorCodes.CART_ALREADY_REDEEMED); } } for (Cart cart : cartsForEvent) { cartRepository.delete(cart); } for (Code code : codesForEvent) { codeRepository.delete(code); } eventRepository.delete(event); }  Event create(Event event); Event getEvent(Long eventId); @Transactional void delete(Long eventId); Event update(Event event); @Transactional void generateCodes(Long eventId, List<Long> cartIds);  }