Skip to content

Commit

Permalink
issue #7 : Pas d'infos sur la production dans la liste des ventes
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Mar 16, 2024
1 parent 769c5ff commit 20207ab
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public ResponseEntity<Order> createOrder(Order order) {
Order orderCreated = orderRepository.save(order);
List<PackageLot> lots = new ArrayList<>();
order.getItems().forEach(item -> {
PackageLot lot = item.getPackageLot();
PackageLot lot = packageLotRepository.findById(item.getPackageLot().getId()).get();
int updatedQuantySold = lot.getQuantitySold() + item.getQuantity();
if (updatedQuantySold > lot.getQuantity()) {
throw new ResponseStatusException(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ void createOrder_should_persist_order_in_database() {
assertThat(orderCreated.getId()).isNotNull();
List<OrderItem> itemsCreated = orderItemRepository.findByOrder(orderCreated);
assertThat(itemsCreated).hasSize(1);
assertThat(packageLot.getQuantitySold()).isEqualTo(quantitySoldBeforeOrderCreation + 1);
var packageLotReloaded = packageLotRepository.findById(packageLot.getId()).get();
assertThat(packageLotReloaded.getQuantitySold()).isEqualTo(quantitySoldBeforeOrderCreation + 1);
assertThat(packageLotReloaded.getProduction()).isNotNull();

}

@Test
Expand Down
6 changes: 3 additions & 3 deletions frontend/app/src/domains/sale/components/SaleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useEffect, useState } from 'react'

import { Button, ButtonGroup, Card, CardActions, CardContent, Typography } from "@mui/material"
import dayjs from 'dayjs'
import SaleCardBeefProduction from './SaleCardBeefProduction.js';
import SaleCardBeefProduction from './SaleCardBeefProduction.tsx';
import { ApiInvoker } from '../../../api/ApiInvoker.ts';
import { useKeycloak } from '@react-keycloak/web';
import Order from 'viandeendirect_eu/dist/model/Order'
Expand All @@ -18,11 +18,11 @@ export default function SaleCard({ sale: sale, manageOrdersCallback: manageOrder

useEffect(() => {
apiInvoker.callApiAuthenticatedly(keycloak, api => api.getSaleOrders, sale.id, setOrders, console.error)
}, [keycloak, sale])
}, [keycloak])

useEffect(() => {
apiInvoker.callApiAuthenticatedly(keycloak, api => api.getSaleProductions, sale.id, setProductions, console.error)
}, [keycloak, sale])
}, [keycloak])

return (
<Card>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import React from 'react'
import { useEffect, useState } from 'react';
import { useKeycloak } from '@react-keycloak/web'
import { Typography } from "@mui/material"
import { ApiInvoker } from '../../../api/ApiInvoker.ts'
import { AnimalTypeUtils } from '../../../enum/AnimalType.ts';
import PieChart from '../../commons/components/PieChart.tsx'
import styles from './SaleCard.css'
import Production from 'viandeendirect_eu/dist/model/BeefProduction'
import './SaleCard.css'

export default function SaleCardBeefProduction({production: production}) {

const [beefProduction, setBeefProduction] = useState<BeefProduction>()
const [productionPercentageSold, setProductionPercentageSold] = useState([])
const { keycloak } = useKeycloak()
const apiInvoker = new ApiInvoker()

useEffect(() => {
apiInvoker.callApiAuthenticatedly(
keycloak,
api => api.getBeefProduction,
production.id,
setBeefProduction,
console.error)
}, [keycloak])

useEffect(() => {
apiInvoker.callApiAuthenticatedly(
keycloak,
api => api.getProductionPercentageSold,
production.id,
setProductionPercentageSold,
console.error)
}, [keycloak, production])
}, [keycloak])

return <>
<div className='sale-card-production'>
Expand All @@ -29,12 +41,12 @@ export default function SaleCardBeefProduction({production: production}) {
</Typography>
<Typography>
<div>
{AnimalTypeUtils.getAnimalTypeLabel(production.animalType)}{production.animalIdentifier}
{AnimalTypeUtils.getAnimalTypeLabel(beefProduction?.animalType)}{beefProduction?.animalIdentifier}
</div>
</Typography>
<Typography>
<div>
Poids vif estimé : {production.animalLiveWeight} kg
Carcasse chaude estimée : {beefProduction?.warmCarcassWeight} kg
</div>
</Typography>
</div>
Expand Down

0 comments on commit 20207ab

Please sign in to comment.