Skip to content

Commit

Permalink
payment feature - part 2 : runtime config in front end
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminpochat committed Jul 21, 2021
1 parent 1f37475 commit f2e7a17
Show file tree
Hide file tree
Showing 55 changed files with 352 additions and 161 deletions.
6 changes: 3 additions & 3 deletions core/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ WORKDIR /home/localeat

COPY ./core ./core


RUN mvn clean install -s /usr/share/maven/ref/settings-docker.xml -f ./core/pom.xml
RUN mvn exec:java -s /usr/share/maven/ref/settings-docker.xml -f ./core/pom.xml -Dexec.skip=true

Expand All @@ -21,7 +20,7 @@ USER localeat
# Wait for Postgre database (localhost:5432)
# and then start java core application
ENTRYPOINT ["wait-for-it", \
"localhost:5432", \
"database:5432", \
"--timeout=10", \
"--", \
"mvn", \
Expand All @@ -35,4 +34,5 @@ ENTRYPOINT ["wait-for-it", \
"-Ddatasource_username=${localeat_datasource_username}", \
"-Ddatasource_password=${localeat_datasource_password}", \
"-Dlocaleat_smtp_username=${localeat_smtp_username}", \
"-Dlocaleat_smtp_password=${localeat_smtp_password}"]
"-Dlocaleat_smtp_password=${localeat_smtp_password}", \
"-Dlocaleat_http_domainname=${localeat_http_domainname}"]
45 changes: 40 additions & 5 deletions core/src/main/java/com/localeat/core/config/http/HttpConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,48 @@
@Configuration
@ConfigurationProperties(prefix = "localeat.http")
public class HttpConfig {
private String userInterfaceUrl;
private String domainName;
private int backendPort = 8080;
private int frontendPort = 80;
private String protocol = "http";

public String getUserInterfaceUrl() {
return userInterfaceUrl;
public String getProtocol() {
return protocol;
}

public void setUserInterfaceUrl(String userInterfaceUrl) {
this.userInterfaceUrl = userInterfaceUrl;
public void setProtocol(String protocol) {
this.protocol = protocol;
}

public String getDomainName() {
return domainName;
}

public void setDomainName(String domainName) {
this.domainName = domainName;
}

public int getBackendPort() {
return backendPort;
}

public void setBackendPort(int backendPort) {
this.backendPort = backendPort;
}

public int getFrontendPort() {
return frontendPort;
}

public void setFrontendPort(int frontendPort) {
this.frontendPort = frontendPort;
}

public String getFrontendUrl() {
return String.format("%s://%s:%s", protocol, domainName, frontendPort);
}

public String getBackendUrl() {
return String.format("%s://%s:%s", protocol, domainName, backendPort);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public EmailService getEmailService() {
public Object[] getTemplateValues(Order order) {
Object[] templateValues = {
order.getId(),
httpConfig.getUserInterfaceUrl(),
httpConfig.getFrontendUrl(),
order.getCustomer().getFirstName(),
order.getCustomer().getName(),
order.getCustomer().getEmail(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public Object[] getTemplateValues(Order order) {
Delivery delivery = deliveryRepository.findById(slaughter.getDelivery().getId()).orElseThrow();
Object[] bodyTemplateValues = {
order.getId(),
httpConfig.getUserInterfaceUrl(),
httpConfig.getFrontendUrl(),
orderService.getTotalPrice(order),
orderService.getTotalWeight(order),
delivery.getDeliveryStart(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.localeat.core.domains.payment;

import com.localeat.core.commons.RestTemplateLoggingInterceptor;
import com.localeat.core.config.http.HttpConfig;
import com.localeat.core.domains.order.Order;
import com.localeat.core.domains.order.OrderService;
import com.localeat.core.domains.order.OrderStatus;
import com.localeat.core.domains.security.Account;
import com.localeat.core.domains.security.AccountRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.AutoConfigurationMetadata;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import org.springframework.web.util.UriComponentsBuilder;

import java.net.URI;
import java.util.List;

import static com.localeat.core.domains.order.OrderStatus.BOOKED;
import static com.localeat.core.domains.payment.MolliePaymentTransaction.Currency.EUR;
Expand All @@ -35,6 +31,9 @@ public class MolliePaymentTransactionService {
@Autowired
private AccountRepository accountRepository;

@Autowired
HttpConfig httpConfig;

public Payment createPayment(Account account, Order order) {
var payment = new Payment();
payment.setOrder(order);
Expand Down Expand Up @@ -67,11 +66,8 @@ private MolliePaymentTransaction getMolliePaymentTransaction(Payment payment, Ac
MolliePaymentTransaction transaction = new MolliePaymentTransaction();
transaction.setAmount(payment.getAmount(), EUR);
transaction.setDescription(String.format("payment for order %s", payment.getOrder().getId()));
//TODO : implémenter la route
//TODO : mettre la racine de l'url dans un paramètre externe
transaction.setRedirectUrl(String.format("http://viandeendirect.eu/customer-area/orders/%s", payment.getOrder().getId()));
//TODO : mettre la racine de l'url dans un paramètre externe
transaction.setWebhookUrl("http://viandeendirect.eu:8080/paymentTransactions/");
transaction.setRedirectUrl(String.format("%s/customer-area/orders/%s", httpConfig.getFrontendUrl(), payment.getOrder().getId()));
transaction.setWebhookUrl(String.format("%s/paymentTransactions/", httpConfig.getBackendUrl()));
return transaction;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ private String getPasswordRenewalUrl(Account account, String authenticationName,
account,
authenticationName,
Arrays.asList(account.getActor().getRole().name()), FIFTEEN_MINUTES);
return String.format("%s/password-renewal?token=%s&destinationRoute=%s", httpConfig.getUserInterfaceUrl(), jwt, destinationRoute);
return String.format("%s/password-renewal?token=%s&destinationRoute=%s", httpConfig.getFrontendUrl(), jwt, destinationRoute);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.localeat.core.domains.slaughter;

public enum AnimalBreed {
BEEF_LIMOUSINE,
BEEF_LIMOUSIN,
BEEF_CHAROLLAIS;
}
5 changes: 1 addition & 4 deletions core/src/main/resources/application-dev.properties
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialec
spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = update

logging.level.org.springframework.web = DEBUG
logging.level.com.localeat = DEBUG

localeat.http.userInterfaceUrl = http://localhost:4200
localeat.http.domainname = localhost
16 changes: 0 additions & 16 deletions core/src/main/resources/application-prod.properties

This file was deleted.

16 changes: 16 additions & 0 deletions core/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,7 +1,23 @@
# LOGGING
#--------
# Workaround to make the service "GET /product/{product}/photo" return a non nul photo content
# see https://github.com/benjaminpochat/localeat/issues/27
logging.level.org.springframework.web = WARN
logging.level.com.localeat = WARN

# SPRING
#-------
spring.jackson.serialization.FAIL_ON_EMPTY_BEANS=false
# /!\ Caution : The datasource is not set by SpringBoot default initialization
# The datasource is set in CommandLineDatabaseConfig
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect

# LOCALEAT
#---------
localeat.smtp.authentication = true
localeat.smtp.startTls = true
localeat.smtp.host = smtp.gmail.com
localeat.smtp.port = 587
localeat.smtp.sslTrust = smtp.gmail.com

Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,6 @@ public void should_format_a_mail_correctly() {
"<li>Montant de la commande : 1350.0 €TTC</li>" +
"<li>Quantité commandée : 100.0 kg</li>" +
"</ul>" +
"</div>", httpConfig.getUserInterfaceUrl()));
"</div>", httpConfig.getFrontendUrl()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,6 @@ public void should_format_a_mail_correctly() {
"Atlantic<br>" +
"</li>" +
"</ul>" +
"</div>", httpConfig.getUserInterfaceUrl()));
"</div>", httpConfig.getFrontendUrl()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void getAllSlaughters() throws Exception {
.build();
var animal2 = GenericBuilder.of(Animal::new)
.with(Animal::setAnimalType, AnimalType.BEEF_COW)
.with(Animal::setBreed, AnimalBreed.BEEF_LIMOUSINE)
.with(Animal::setBreed, AnimalBreed.BEEF_LIMOUSIN)
.with(Animal::setFinalFarm, farm2)
.with(Animal::setIdentificationNumber, "EFGH")
.build();
Expand All @@ -87,7 +87,7 @@ public void getAllSlaughters() throws Exception {
.build();
var animal3 = GenericBuilder.of(Animal::new)
.with(Animal::setAnimalType, AnimalType.BEEF_BULL)
.with(Animal::setBreed, AnimalBreed.BEEF_LIMOUSINE)
.with(Animal::setBreed, AnimalBreed.BEEF_LIMOUSIN)
.with(Animal::setFinalFarm, farm1)
.with(Animal::setIdentificationNumber, "IJKL")
.build();
Expand Down Expand Up @@ -125,7 +125,7 @@ public void getAllSlaughters() throws Exception {
" \"id\" : 3,\n" +
" \"animal\" : {\n" +
" \"id\" : 3,\n" +
" \"breed\" : \"BEEF_LIMOUSINE\",\n" +
" \"breed\" : \"BEEF_LIMOUSIN\",\n" +
" \"animalType\" : \"BEEF_BULL\",\n" +
" \"liveWeight\" : 0.0,\n" +
" \"meatWeight\" : 0.0,\n" +
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
-- order domain
delete from order_items;
delete from payments;
delete from orders;
alter sequence order_item_id_seq restart with 1;
alter sequence order_id_seq restart with 1;
Expand Down
17 changes: 12 additions & 5 deletions docker-compose.yml → docker-compose-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ services:
image: postgres:12.2-alpine
networks:
- hostnet
volumes:
- /var/lib/postgresql/data/pgdata:/var/lib/postgresql/data/pgdata
environment:
- POSTGRES_USER=localeat
- POSTGRES_PASSWORD=localeat
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- /var/lib/postgresql/data/pgdata:/var/lib/postgresql/data/pgdata
ports:
- 5432:5432

core:
build:
Expand All @@ -27,6 +29,9 @@ services:
- localeat_datasource_password=localeat
- [email protected]
- localeat_smtp_password=localeat
- localeat_http_domainname=http://localhost:4200
ports:
- 8080:8080

ui:
build:
Expand All @@ -39,10 +44,12 @@ services:
- hostnet
depends_on:
- core
volumes:
- /home/benjamin/Documents/workspace/localeat/test/localeat-ui-config:/usr/local/apache2/htdocs/assets/config
ports:
- 80:80

networks:
hostnet:
external: true
name: host


name: host
36 changes: 36 additions & 0 deletions docker-compose-run.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: '3.7'
services:

database:
image: postgres:12.2-alpine
volumes:
- <path_to_postgres_datafile_folder_on_real_server>:/var/lib/postgresql/data/pgdata
environment:
- POSTGRES_USER=localeat
- POSTGRES_PASSWORD=<password>
- PGDATA=/var/lib/postgresql/data/pgdata
ports:
- <published_postgres_port>:5432

core:
image: benjaminpochat/localeat-core:${DOCKER_IMAGE_TAG:-latest}
depends_on:
- database
environment:
- localeat_datasource_url=jdbc:postgresql://database:5432/localeat
- localeat_datasource_username=localeat
- localeat_datasource_password=<password>
- [email protected]
- localeat_smtp_password=localeat
- localeat_http_domainname=<domain_name_for_localeat_server>
ports:
- <published_backend_port>:8080

ui:
image: benjaminpochat/localeat-ui:${DOCKER_IMAGE_TAG:-latest}
depends_on:
- core
volumes:
- <path_to_folder_containing_localeat_ui_config_file_on_real_server>:/usr/local/apache2/htdocs/assets/config
ports:
- <published_frontend_port>:80
47 changes: 0 additions & 47 deletions docker-compose-staging.yml

This file was deleted.

Loading

0 comments on commit f2e7a17

Please sign in to comment.