diff --git a/src/main/java/com/labwork1/app/student/repository/impl/CustomerRepositoryImpl.java b/src/main/java/com/labwork1/app/student/repository/impl/CustomerRepositoryImpl.java deleted file mode 100644 index ff9bfcf..0000000 --- a/src/main/java/com/labwork1/app/student/repository/impl/CustomerRepositoryImpl.java +++ /dev/null @@ -1,63 +0,0 @@ -//package com.labwork1.app.student.repository.impl; -// -//import com.labwork1.app.student.model.Customer; -//import com.labwork1.app.student.model.Order; -//import com.labwork1.app.student.model.OrderSession; -//import com.labwork1.app.student.model.Session; -//import com.labwork1.app.student.repository.CustomerRepository; -//import com.labwork1.app.student.repository.OrderRepository; -//import jakarta.persistence.EntityManager; -//import jakarta.persistence.PersistenceContext; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.context.annotation.Lazy; -// -//import java.util.List; -//import java.util.Optional; -// -//public class CustomerRepositoryImpl { -// @Lazy -// private CustomerRepository customerRepository; -// @Lazy -// private OrderRepository orderRepository; -// -// @PersistenceContext -// private EntityManager em; -// -// public Optional deleteCustomerOrders(Long id) { -// final Optional currentCustomer = customerRepository.findById(id); -// if (currentCustomer.isPresent()) { -// final List currentCustomerOrders = currentCustomer.get().getOrders(); -// -// for (int i = 0; i < currentCustomerOrders.size(); i++) { -// final Optional tempOrder = orderRepository.findById(currentCustomerOrders.get(i).getId()); -// if (tempOrder.isPresent()) { -// final Order currentOrder = tempOrder.get(); -// List orderSessionList = em -// .createQuery("select p from OrderSession p where p.id.orderId = :id", OrderSession.class) -// .setParameter("id", id) -// .getResultList(); -// for (int j = 0; j < orderSessionList.size(); j++) { -// final Session currentSession = orderSessionList.get(j).getSession(); -// currentOrder.getSessions().remove(orderSessionList.get(j)); -// currentSession.getOrders().remove(orderSessionList.get(j)); -// em.remove(orderSessionList.get(j)); -// em.merge(currentSession); -// } -// em.merge(currentOrder); -// } -// } -// em.remove(currentCustomer.get()); -// } -// return currentCustomer; -// } -// -// -// public void deleteAllCustomers() { -// List customers = em -// .createQuery("select c from Customer c", Customer.class) -// .getResultList(); -// for (var customer : customers) { -// deleteCustomerOrders(customer.getId()); -// } -// } -//} diff --git a/src/main/java/com/labwork1/app/student/repository/impl/OrderRepositoryImpl.java b/src/main/java/com/labwork1/app/student/repository/impl/OrderRepositoryImpl.java deleted file mode 100644 index 5d008e5..0000000 --- a/src/main/java/com/labwork1/app/student/repository/impl/OrderRepositoryImpl.java +++ /dev/null @@ -1,104 +0,0 @@ -//package com.labwork1.app.student.repository.impl; -// -//import com.labwork1.app.student.model.*; -//import com.labwork1.app.student.repository.CustomerRepository; -//import com.labwork1.app.student.repository.OrderRepository; -//import com.labwork1.app.student.repository.SessionRepository; -//import com.labwork1.app.student.service.CustomerNotFoundException; -//import jakarta.persistence.EntityManager; -//import jakarta.persistence.PersistenceContext; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.context.annotation.Lazy; -//import org.springframework.transaction.annotation.Transactional; -// -//import java.util.Optional; -// -//public class OrderRepositoryImpl { -// -// @Lazy -// private CustomerRepository customerRepository; -// -// @Lazy -// private OrderRepository orderRepository; -// -// @Lazy -// private SessionRepository sessionRepository; -// @PersistenceContext -// private EntityManager em; -// -// public Order addOrder(Order order, Long customerId) { -// final Optional customer = customerRepository.findById(customerId); -// if (customer.isEmpty()) { -// throw new CustomerNotFoundException(customerId); -// } -// order.setCustomer(customer.get()); -// em.persist(order); -// em.merge(customer.get()); -// return order; -// } -// -// -// @Transactional -// public Optional addSession(Long id, Long session, Integer count) { -// if (session <= 0 || count <= 0) { -// throw new IllegalArgumentException("addOrder empty fields"); -// } -// Optional optionalOrder = orderRepository.findById(id); -// Optional optionalSession = sessionRepository.findById(session); -// if (optionalOrder.isEmpty() || optionalSession.isEmpty()) { -// return optionalOrder; -// } -// final Session currentSession = optionalSession.get(); -// final Order currentOrder = optionalOrder.get(); -// OrderSession orderSession = em.find(OrderSession.class, -// new OrderSessionKey(currentSession.getId(), currentOrder.getId())); -// -// if (currentSession.getCapacity() < count || -// (orderSession != null && orderSession.getCount() + count > currentSession.getMaxCount())) { -// throw new IllegalArgumentException(String.format("No more tickets in session. Capacity: %1$s. Count: %2$s", -// currentSession.getCapacity(), count)); -// } -// if (orderSession == null) -// orderSession = new OrderSession(currentOrder, currentSession, count); -// else if (orderSession.getCount() + count <= currentSession.getMaxCount()) { -// orderSession.setCount(orderSession.getCount() + count); -// } -// -// currentOrder.addSession(orderSession); -// currentSession.addOrder(orderSession); -// currentSession.setCapacity(currentSession.getCapacity() - count); -// em.merge(currentSession); -// em.merge(currentOrder); -// em.merge(orderSession); -// return orderRepository.findById(id); -// } -// -// @Override -// public Optional deleteSessionInOrder(Long id, Long session, Integer count) { -// final Optional optionalOrder = orderRepository.findById(id); -// final Optional optionalSession = sessionRepository.findById(session); -// if (optionalOrder.isEmpty() || optionalSession.isEmpty()) { -// return optionalOrder; -// } -// final Order currentOrder = optionalOrder.get(); -// final Session currentSession = optionalSession.get(); -// -// OrderSession orderSession = em.find(OrderSession.class, new OrderSessionKey(session, id)); -// if (orderSession == null) -// return optionalOrder; -// -// if (count >= orderSession.getCount()) { -// currentOrder.getSessions().remove(orderSession); -// currentSession.getOrders().remove(orderSession); -// currentSession.setCapacity(currentSession.getCapacity() + orderSession.getCount()); -// em.remove(orderSession); -// } else { -// orderSession.setCount(orderSession.getCount() - count); -// currentSession.setCapacity(currentSession.getMaxCount() - orderSession.getCount()); -// em.merge(orderSession); -// em.merge(currentSession); -// } -// -// return orderRepository.findById(id); -// } -//} diff --git a/src/main/java/com/labwork1/app/student/repository/impl/SessionRepositoryImpl.java b/src/main/java/com/labwork1/app/student/repository/impl/SessionRepositoryImpl.java deleted file mode 100644 index 8de629c..0000000 --- a/src/main/java/com/labwork1/app/student/repository/impl/SessionRepositoryImpl.java +++ /dev/null @@ -1,73 +0,0 @@ -//package com.labwork1.app.student.repository.impl; -// -//import com.labwork1.app.student.model.Cinema; -//import com.labwork1.app.student.model.OrderSession; -//import com.labwork1.app.student.model.Session; -//import com.labwork1.app.student.repository.CinemaRepository; -//import com.labwork1.app.student.repository.SessionRepository; -//import com.labwork1.app.student.service.CinemaNotFoundException; -//import com.labwork1.app.student.service.SessionNotFoundException; -//import jakarta.persistence.EntityManager; -//import jakarta.persistence.PersistenceContext; -//import org.springframework.beans.factory.annotation.Autowired; -//import org.springframework.context.annotation.Lazy; -// -//import java.util.List; -//import java.util.Optional; -// -//public class SessionRepositoryImpl implements SessionRepositoryExtension { -// @Autowired -// @Lazy -// private SessionRepository sessionRepository; -// @Autowired -// @Lazy -// private CinemaRepository cinemaRepository; -// @PersistenceContext -// private EntityManager em; -// @Override -// public Session addSession(Session session, Long cinemaId) { -// if (session == null) return null; -// final Optional cinema = cinemaRepository.findById(cinemaId); -// if (cinema.isEmpty()) { -// throw new CinemaNotFoundException(cinemaId); -// } -// session.setCinema(cinema.get()); -// em.persist(session); -// em.merge(cinema.get()); -// return session; -// } -// -// @Override -// public Session deleteSession(Long id) { -// final Optional optionalSession = sessionRepository.findById(id); -// if (optionalSession.isEmpty()) { -// throw new SessionNotFoundException(id); -// } -// final Session currentSession = optionalSession.get(); -// int size = currentSession.getOrders().size(); -// for (int i = 0; i < size; i++) { -// OrderSession temp = currentSession.getOrders().get(0); -// temp.getSession().removeOrder(temp); -// temp.getOrder().removeSession(temp); -// em.remove(temp); -// } -// em.remove(currentSession); -// return currentSession; -// } -// -// @Override -// public void deleteAllSessions() { -// List sessions = em -// .createQuery("select s from Session s", Session.class) -// .getResultList(); -// for (var session : sessions) { -// deleteSession(session.getId()); -// } -// } -// -// @Override -// public List findAllSessionsWithCapacity() { -// return em.createQuery("select t from Session t where capacity > 0", Session.class) -// .getResultList(); -// } -//}