сохранение перед исправлениями

This commit is contained in:
dasha 2023-04-17 14:12:12 +04:00
parent 7a95e50ac3
commit 1544973e7b
4 changed files with 4 additions and 7 deletions

View File

@ -2,7 +2,7 @@ import React, { useEffect, useState } from "react"
import MyButton from './MyButton' import MyButton from './MyButton'
export default function SessionItem(props) { export default function SessionItem(props) {
const date = new Date(props.item.timestamp).toLocaleString('RU-ru') const date = new Date(props.item.timestamp).toLocaleDateString('ru-RU')
return ( return (
<tr> <tr>

View File

@ -3,14 +3,10 @@ package com.labwork1.app.student.repository;
import com.labwork1.app.student.model.Order; import com.labwork1.app.student.model.Order;
import com.labwork1.app.student.model.OrderSession; import com.labwork1.app.student.model.OrderSession;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param; import org.springframework.data.repository.query.Param;
public interface OrderRepository extends JpaRepository<Order, Long> { public interface OrderRepository extends JpaRepository<Order, Long> {
@Query("Select os from OrderSession os where os.order.id = :orderId and os.session.id = :sessionId") @Query("Select os from OrderSession os where os.order.id = :orderId and os.session.id = :sessionId")
OrderSession getOrderSession(@Param("orderId") Long orderId, @Param("sessionId") Long sessionId); OrderSession getOrderSession(@Param("orderId") Long orderId, @Param("sessionId") Long sessionId);
@Modifying
@Query("delete from OrderSession os where os.order.id = :orderId and os.session.id = :sessionId")
void deleteSessionInOrder(@Param("orderId") Long orderId, @Param("sessionId") Long sessionId);
} }

View File

@ -3,10 +3,13 @@ package com.labwork1.app.student.repository;
import com.labwork1.app.student.model.Session; import com.labwork1.app.student.model.Session;
import org.springframework.data.jpa.repository.JpaRepository; import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query; import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.util.List; import java.util.List;
public interface SessionRepository extends JpaRepository<Session, Long> { public interface SessionRepository extends JpaRepository<Session, Long> {
@Query("Select s from Session s where s.capacity > 0") @Query("Select s from Session s where s.capacity > 0")
List<Session> findAllSessionsWithCapacity(); List<Session> findAllSessionsWithCapacity();
@Query("Select sum(os.count) from OrderSession os where os.session.id = :sessionId")
Integer getCapacity(@Param("sessionId") Long sessionId);
} }

View File

@ -46,8 +46,6 @@ public class OrderService {
currentSession.getCapacity(), count)); currentSession.getCapacity(), count));
} }
currentSession.setCapacity(currentSession.getCapacity() - count); currentSession.setCapacity(currentSession.getCapacity() - count);
/*final Session updatedSession = sessionService.updateSession(currentSession.getId(),
currentSession.getPrice(), currentSession.getCapacity() - count);*/
if (currentOrderSession == null) { if (currentOrderSession == null) {
currentOrder.addSession(new OrderSession(currentOrder, currentSession, count)); currentOrder.addSession(new OrderSession(currentOrder, currentSession, count));
} }