Skip to content

Commit

Permalink
production creation end to end manual test ok
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Dec 24, 2023
1 parent 6e61b7b commit a42eabf
Show file tree
Hide file tree
Showing 18 changed files with 79 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public interface ProductionRepository extends CrudRepository<Production, Integer
@Query("SELECT p FROM Production p WHERE p.producer = :producer")
List<Production> findByProducer(@Param("producer") Producer producer);

@Query("select p from Production p inner join p.sales sales where sales.id = :saleId")
@Query("select p from Sale s inner join s.productions p where s.id = :saleId")
List<Production> findBySalesId(@Param("saleId") Integer saleId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import java.util.stream.StreamSupport;

import static java.util.Collections.emptySet;
import static java.util.stream.Collectors.toSet;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,24 +41,32 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.anonymous()
.and()
.authorizeHttpRequests()
.requestMatchers("/sales")
.anonymous()
.requestMatchers("/sales", "/sales/*")
.permitAll()
.and()
.authorizeHttpRequests()
.requestMatchers("/packageTemplates", "/packageTemplates/*")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/productions", "/productions/*")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/productions")
.hasRole("GROWER")
.requestMatchers("/beefProductions", "/beefProductions/*")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/beefProductions/*")
.hasRole("GROWER")
.requestMatchers("/honneyProductions", "/honneyProductions/*")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/honneyProductions/*")
.hasRole("GROWER")
.requestMatchers("/customers", "/customers/*")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/orders")
.authenticated()
.requestMatchers("/orders", "/orders/*")
.hasRole("PRODUCER")
.and()
.authorizeHttpRequests()
.requestMatchers("/error")
Expand All @@ -70,7 +78,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.logoutSuccessUrl("/");
http.oauth2ResourceServer()
.jwt()
.jwtAuthenticationConverter(new KeycloakJwtAuthenticationConverter("backend"));
.jwtAuthenticationConverter(new KeycloakJwtAuthenticationConverter("viandeendirect-frontend"));
return http.build();
}
}
3 changes: 2 additions & 1 deletion backend/app/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ spring.datasource.password=vndndrct-db-p4ssw0rd
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
#spring.jpa.hibernate.ddl-auto = create
spring.jpa.hibernate.ddl-auto = update
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

Expand Down
8 changes: 4 additions & 4 deletions backend/app/src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
# database / JPA config
spring.jpa.hibernate.ddl-auto = create

#spring.security.oauth2.client.registration.keycloak.client-id=viandeendirect-frontend
#spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
#spring.security.oauth2.client.registration.keycloak.scope=openid
#spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username
spring.security.oauth2.client.registration.keycloak.client-id=viandeendirect-frontend
spring.security.oauth2.client.registration.keycloak.authorization-grant-type=authorization_code
spring.security.oauth2.client.registration.keycloak.scope=openid
spring.security.oauth2.client.provider.keycloak.user-name-attribute=preferred_username
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@

import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonValue;

import com.fasterxml.jackson.annotation.*;
import eu.viandeendirect.model.BeefProduction;
import eu.viandeendirect.model.PackageLot;
import eu.viandeendirect.model.Producer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@
import java.net.URI;
import java.util.Objects;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.*;
import eu.viandeendirect.model.ProducerStatus;
import eu.viandeendirect.model.Production;
import eu.viandeendirect.model.Sale;
Expand Down Expand Up @@ -51,13 +49,13 @@ public class Producer {
private Integer salesCredits;

@JsonProperty("productions")
@JsonManagedReference
@JsonIgnore
@jakarta.persistence.OneToMany(mappedBy = "producer")
@Valid
private List<Production> productions = null;

@JsonProperty("sales")
@JsonManagedReference
@JsonManagedReference("salesSeller")
@jakarta.persistence.OneToMany(mappedBy = "seller")
@Valid
private List<Sale> sales = null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
package eu.viandeendirect.model;

import java.net.URI;
import java.util.Objects;

import com.fasterxml.jackson.annotation.*;
import eu.viandeendirect.model.BeefProduction;
import eu.viandeendirect.model.HonneyProduction;
import eu.viandeendirect.model.PackageLot;
import eu.viandeendirect.model.Producer;
import eu.viandeendirect.model.Sale;
import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;


import java.util.*;
import jakarta.annotation.Generated;
import jakarta.persistence.*;
import jakarta.validation.Valid;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

/**
*
Expand Down Expand Up @@ -90,13 +74,13 @@ public static ProductionTypeEnum fromValue(String value) {
private ProductionTypeEnum productionType;

@JsonProperty("sales")
@JsonIgnore
@jakarta.persistence.ManyToMany(mappedBy = "productions")
@Valid
private List<Sale> sales = null;

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

@JsonProperty("lots")
Expand Down
29 changes: 12 additions & 17 deletions backend/model/src/main/java/eu/viandeendirect/model/Sale.java
Original file line number Diff line number Diff line change
@@ -1,26 +1,20 @@
package eu.viandeendirect.model;

import java.net.URI;
import java.util.Objects;
import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonCreator;
import eu.viandeendirect.model.Order;
import eu.viandeendirect.model.Producer;
import eu.viandeendirect.model.Production;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.annotation.Generated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.SequenceGenerator;
import jakarta.validation.Valid;
import org.springframework.format.annotation.DateTimeFormat;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.List;
import org.springframework.format.annotation.DateTimeFormat;
import jakarta.persistence.*;
import org.openapitools.jackson.nullable.JsonNullable;
import java.time.OffsetDateTime;
import jakarta.validation.Valid;
import jakarta.validation.constraints.*;
import io.swagger.v3.oas.annotations.media.Schema;


import java.util.*;
import jakarta.annotation.Generated;
import java.util.Objects;

/**
*
Expand All @@ -39,6 +33,7 @@ public class Sale {

@JsonProperty("seller")
@ManyToOne
@JsonBackReference("salesSeller")
private Producer seller;

@JsonProperty("productions")
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/api/AuthenticatedApiBuilder.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export class AuthenticatedApiBuilder {
} else {
let apiClient = ApiClient.instance
apiClient.authentications['oAuth2ForViandeEnDirect'].accessToken = keycloak.token
apiClient.basePath = '.'
apiClient.basePath = 'http://localhost:8080'
var api = new DefaultApi(apiClient)
return api
}
Expand Down
16 changes: 8 additions & 8 deletions frontend/app/src/api/mock/MockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,24 @@ export class MockApi {
callback(undefined, this.mockApiProductions.getBeefProduction())
}

getPackageTemplates(options, callback) {
callback(undefined, this.mockApiProductions.getPackageTemplates())
getPackageTemplates(callback) {
callback(this.mockApiProductions.getPackageTemplates())
}

getAddresses(options, callback) {
callback(undefined, this.mockApiAddresses.getAddresses())
getAddresses(callback) {
callback(this.mockApiAddresses.getAddresses())
}

getCustomers(options, callback) {
callback(undefined, this.mockApiCustomers.getCustomers())
getCustomers(callback) {
callback(this.mockApiCustomers.getCustomers())
}

getCutomer(customer, callback){
callback(undefined, this.mockApiCustomers.createCustomer(customer))
}

getSales(options, callback) {
callback(undefined, this.mockApiSales.getSales())
getSales(callback) {
callback(this.mockApiSales.getSales())
}

getSaleOrders(options, callback) {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/customer/views/CustomersList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export default function CustomersList() {
function loadCustomers() {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak)
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getCustomers({}, (error, data, response) => {
api.getCustomers((error, data, response) => {
if (error) {
console.error(error)
} else {
Expand Down
20 changes: 11 additions & 9 deletions frontend/app/src/domains/production/views/BeefProductionForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default function BeefProductionForm({ callback }) {

const { keycloak, initialized } = useKeycloak()
const [ activeStep, setActiveStep ] = useState(SET_PRODUCTION_PROPERTIES_STEP)
const [ beefProduction, setBeefProduction] = useState(new BeefProduction())
const authenticayedApiBuilder = new AuthenticatedApiBuilder()

return <>
Expand Down Expand Up @@ -80,20 +81,21 @@ export default function BeefProductionForm({ callback }) {

function validateProductionProperties(productionFormData) {
console.log(productionFormData)
const production = new BeefProduction()
production.productionType = "BeefProduction"
production.animalIdentifier = productionFormData.animalIdentifier
production.animalLiveWeight = productionFormData.animalLiveWeight
production.birthDate = productionFormData.birthDate
production.slaughterDate = productionFormData.slaughterDate
production.birthPlace = productionFormData.birthPlace
setBeefProduction({...beefProduction,
productionType: "BeefProduction",
animalIdentifier: productionFormData.animalIdentifier,
animalLiveWeight: productionFormData.animalLiveWeight,
birthDate: productionFormData.birthDate,
slaughterDate: productionFormData.slaughterDate,
birthPlace: productionFormData.birthPlace,
})
setActiveStep(SET_PRODUCTS_STEP)
}

function validate(production) {
function validate() {
var api = authenticayedApiBuilder.getAuthenticatedApi(keycloak);
authenticayedApiBuilder.invokeAuthenticatedApi(() => {
api.createBeefProduction(production, (error, data, response) => {
api.createBeefProduction(beefProduction, (error, data, response) => {
if (error) {
console.error(error)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export default function PackageLotsCreator() {
useEffect(() => {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak);
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getPackageTemplates({}, (error, data, response) => {
api.getPackageTemplates((error, data, response) => {
if (error) {
console.error(error);
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/sale/views/OrderForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export default function OrderForm({ sale: sale, returnCallback: returnCallback }
function loadCustomers() {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak);
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getCustomers(undefined, (error, data, response) => {
api.getCustomers((error, data, response) => {
if (error) {
console.error(error)
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/sale/views/SaleForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export default function SaleForm({returnCallback: returnCallback}) {
useEffect(() => {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak);
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getAddresses({}, (error, data, response) => {
api.getAddresses((error, data, response) => {
if (error) {
console.error(error);
} else {
Expand Down
2 changes: 1 addition & 1 deletion frontend/app/src/domains/sale/views/SalesList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export default function SalesList({manageSaleOrdersCallback: manageSaleOrdersCal
function loadSales() {
let api = authenticatedApiBuilder.getAuthenticatedApi(keycloak)
authenticatedApiBuilder.invokeAuthenticatedApi(() => {
api.getSales({}, (error, data, response) => {
api.getSales((error, data, response) => {
if (error) {
console.error(error)
} else {
Expand Down
2 changes: 2 additions & 0 deletions openapi/openapi.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ info:
version: 0.0.1
description: This API allows selling and buying food through the shortest path between
farmers and customers.
servers:
- url: http://localhost:8080

security:
- oAuth2ForViandeEnDirect:
Expand Down

0 comments on commit a42eabf

Please sign in to comment.