удалить
This commit is contained in:
parent
a794ee636f
commit
7a95e50ac3
@ -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<Customer> deleteCustomerOrders(Long id) {
|
||||
// final Optional<Customer> currentCustomer = customerRepository.findById(id);
|
||||
// if (currentCustomer.isPresent()) {
|
||||
// final List<Order> currentCustomerOrders = currentCustomer.get().getOrders();
|
||||
//
|
||||
// for (int i = 0; i < currentCustomerOrders.size(); i++) {
|
||||
// final Optional<Order> tempOrder = orderRepository.findById(currentCustomerOrders.get(i).getId());
|
||||
// if (tempOrder.isPresent()) {
|
||||
// final Order currentOrder = tempOrder.get();
|
||||
// List<OrderSession> 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<Customer> customers = em
|
||||
// .createQuery("select c from Customer c", Customer.class)
|
||||
// .getResultList();
|
||||
// for (var customer : customers) {
|
||||
// deleteCustomerOrders(customer.getId());
|
||||
// }
|
||||
// }
|
||||
//}
|
@ -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> 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<Order> addSession(Long id, Long session, Integer count) {
|
||||
// if (session <= 0 || count <= 0) {
|
||||
// throw new IllegalArgumentException("addOrder empty fields");
|
||||
// }
|
||||
// Optional<Order> optionalOrder = orderRepository.findById(id);
|
||||
// Optional<Session> 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<Order> deleteSessionInOrder(Long id, Long session, Integer count) {
|
||||
// final Optional<Order> optionalOrder = orderRepository.findById(id);
|
||||
// final Optional<Session> 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);
|
||||
// }
|
||||
//}
|
@ -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> 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<Session> 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<Session> sessions = em
|
||||
// .createQuery("select s from Session s", Session.class)
|
||||
// .getResultList();
|
||||
// for (var session : sessions) {
|
||||
// deleteSession(session.getId());
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public List<Session> findAllSessionsWithCapacity() {
|
||||
// return em.createQuery("select t from Session t where capacity > 0", Session.class)
|
||||
// .getResultList();
|
||||
// }
|
||||
//}
|
Loading…
Reference in New Issue
Block a user