Skip to content

Commit

Permalink
créer vente : appel du service backend
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Jan 7, 2024
1 parent 9593102 commit 6edcb26
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,31 +41,31 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.anonymous()
.and()
.authorizeHttpRequests()
.requestMatchers("/sales", "/sales/*")
.requestMatchers("/sales", "/sales/**")
.permitAll()
.and()
.authorizeHttpRequests()
.requestMatchers("/packageTemplates", "/packageTemplates/*")
.requestMatchers("/packageTemplates", "/packageTemplates/**")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/productions", "/productions/*")
.requestMatchers("/productions", "/productions/**")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/beefProductions", "/beefProductions/*")
.requestMatchers("/beefProductions", "/beefProductions/**")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/honneyProductions", "/honneyProductions/*")
.requestMatchers("/honneyProductions", "/honneyProductions/**")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/customers", "/customers/*")
.requestMatchers("/customers", "/customers/**")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/orders", "/orders/*")
.requestMatchers("/orders", "/orders/**")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@ public ResponseEntity<Integer> getProductionPercentageSold(Integer productionId)
List<PackageLot> lots = packageLotRepository.findByProduction(production);
Float initialQuantityToSell = lots.stream()
.map(lot -> lot.getQuantity() * lot.getNetWeight())
.reduce((quantity1, quantity2) -> quantity1 + quantity2).get();
.reduce((quantity1, quantity2) -> quantity1 + quantity2).orElse(0f);
Float quantitySold = lots.stream()
.map(lot -> lot.getQuantitySold() * lot.getNetWeight())
.reduce((quantity1, quantity2) -> quantity1 + quantity2).get();
.reduce((quantity1, quantity2) -> quantity1 + quantity2).orElse(0f);
Float percentageSold = quantitySold / initialQuantityToSell * 100;
Integer roundedPercentageSold = Math.round(percentageSold);
return new ResponseEntity<>(roundedPercentageSold, OK);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
spring.datasource.driverClassName=org.postgresql.Driver
spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
spring.jpa.hibernate.ddl-auto = create
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ public static ProductionTypeEnum fromValue(String value) {

@ManyToOne
@JsonProperty("producer")
@JsonIgnore
private Producer producer;

@JsonProperty("lots")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package eu.viandeendirect.model;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Generated;
Expand Down
Empty file removed frontend/app/src/api/Api.js
Empty file.
4 changes: 2 additions & 2 deletions frontend/app/src/domains/sale/components/SaleCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -72,13 +72,13 @@ export default function SaleCard({ sale: sale, manageOrdersCallback: manageOrder
return sale.orders
.flatMap(order => order.items)
.map(item => item.packageLot.netWeight * item.quantity)
.reduce((totalQuantity, orderItemQuantity) => totalQuantity + orderItemQuantity)
.reduce((totalQuantity, orderItemQuantity) => totalQuantity + orderItemQuantity, 0)
}

function getAmountSold() {
return sale.orders
.flatMap(order => order.items)
.map(item => item.unitPrice * item.quantity)
.reduce((totalAmout, orderItemAmout) => totalAmout + orderItemAmout)
.reduce((totalAmout, orderItemAmout) => totalAmout + orderItemAmout, 0)
}
}
13 changes: 12 additions & 1 deletion frontend/app/src/domains/sale/views/SaleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,18 @@ export default function SaleForm({returnCallback: returnCallback}) {
}

function validate() {
returnCallback()
authenticatedApiBuilder.getAuthenticatedApi(keycloak).then(api => {
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.createSale(sale, (error, data, response) => {
if (error) {
console.error(error)
} else {
console.log('API called successfully. Returned data: ' + data)
returnCallback()
}
})
}, keycloak)
});
}

function cancel() {
Expand Down

0 comments on commit 6edcb26

Please sign in to comment.