bugfix
This commit is contained in:
parent
cf01392e65
commit
5d8837809a
@ -7,7 +7,6 @@ import jakarta.persistence.*;
|
||||
@Table(name = "order_session")
|
||||
public class OrderSession {
|
||||
@EmbeddedId
|
||||
@JsonIgnore
|
||||
private OrderSessionKey id;
|
||||
@ManyToOne
|
||||
@MapsId("sessionId")
|
||||
|
@ -10,6 +10,7 @@ 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;
|
||||
|
||||
@ -38,6 +39,7 @@ public class OrderRepositoryImpl implements OrderRepositoryExtension {
|
||||
}
|
||||
|
||||
@Override
|
||||
@Transactional
|
||||
public Optional<Order> addSession(Long id, Long session, Integer count) {
|
||||
if (session <= 0 || count <= 0) {
|
||||
throw new IllegalArgumentException("addOrder empty fields");
|
||||
@ -54,19 +56,21 @@ public class OrderRepositoryImpl implements OrderRepositoryExtension {
|
||||
|
||||
if (currentSession.getCapacity() < count ||
|
||||
(orderSession != null && orderSession.getCount() + count > currentSession.getMaxCount())) {
|
||||
throw new IllegalArgumentException("No more tickets in session. Capacity - "+currentSession.getCapacity()+". Count - "+count);
|
||||
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.getCapacity())
|
||||
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(orderSession);
|
||||
em.merge(currentSession);
|
||||
em.merge(currentOrder);
|
||||
em.merge(orderSession);
|
||||
return orderRepository.findById(id);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user