Skip to content

Commit

Permalink
wip: Add all microservices
Browse files Browse the repository at this point in the history
  • Loading branch information
David Pequegnot authored and foxlegend committed Jun 10, 2024
1 parent 026e252 commit 5eb71b9
Show file tree
Hide file tree
Showing 75 changed files with 1,890 additions and 14 deletions.
10 changes: 10 additions & 0 deletions api-gateway/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,15 @@ spring:
- Path=/api/smartbank/**
filters:
- StripPrefix=2
- id: easypay-service
uri: lb://EASYPAY-SERVICE
predicates:
- Path=/api/easypay/**
filters:
- StripPrefix=2
- id: fraudetect-service
uri: lb://FRAUDETECT-SERVICE
predicates:
- Path=/api/fraudetect/**
# refresh:
# enabled: false # AOT / Native Image does not support Spring Cloud Refresh Scope
66 changes: 66 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
services:
postgres-easypay:
image: postgres:16
ports:
- "5432:5432"
environment:
POSTGRES_DB: easypay
POSTGRES_USER: easypay
POSTGRES_PASSWORD: easypay

postgres-smartbank:
image: postgres:16
ports:
- "5433:5432"
environment:
POSTGRES_DB: smartbank
POSTGRES_USER: smartbank
POSTGRES_PASSWORD: smartbank

postgres-fraudetect:
image: postgres:16
ports:
- "5434:5432"
environment:
POSTGRES_DB: fraudetect
POSTGRES_USER: fraudetect
POSTGRES_PASSWORD: fraudetect

postgres-merchantbo:
image: postgres:16
ports:
- "5435:5432"
environment:
POSTGRES_DB: merchantbo
POSTGRES_USER: merchantbo
POSTGRES_PASSWORD: merchantbo

kafka:
image: docker.redpanda.com/redpandadata/redpanda:v24.1.3
command:
- redpanda
- start
- --kafka-addr internal://0.0.0.0:9092,external://0.0.0.0:19092
# Address the broker advertises to clients that connect to the Kafka API.
# Use the internal addresses to connect to the Redpanda brokers'
# from inside the same Docker network.
# Use the external addresses to connect to the Redpanda brokers'
# from outside the Docker network.
- --advertise-kafka-addr internal://kafka:9092,external://localhost:19092
- --pandaproxy-addr internal://0.0.0.0:8082,external://0.0.0.0:18082
# Address the broker advertises to clients that connect to the HTTP Proxy.
- --advertise-pandaproxy-addr internal://kafka:8082,external://localhost:18082
- --schema-registry-addr internal://0.0.0.0:8081,external://0.0.0.0:18081
# Redpanda brokers use the RPC API to communicate with each other internally.
- --rpc-addr kafka:33145
- --advertise-rpc-addr kafka:33145
# Mode dev-container uses well-known configuration properties for development in containers.
- --mode dev-container
# Tells Seastar (the framework Redpanda uses under the hood) to use 1 core on the system.
- --smp 1
- --default-log-level=info
ports:
- 18081:18081
- 18082:18082
- 19092:19092
- 19644:9644
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
server.port=0
server.shutdown=graceful

server.tomcat.accesslog.enabled=true

spring.cloud.config.allow-override=true
spring.cloud.config.override-none=true

Expand All @@ -13,4 +15,6 @@ management.endpoint.web.exposure.include="*"
logging.level.org.springframework=INFO

# AOT / Native Image does not support Spring Cloud Refresh Scope
#spring.cloud.refresh.enabled=false
#spring.cloud.refresh.enabled=false

eureka.client.registryFetchIntervalSeconds=5
23 changes: 23 additions & 0 deletions config-server/src/main/resources/config-server/easypay-service.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spring:
config:
activate:
on-profile: default
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}

---
spring:
config:
activate:
on-profile: default
datasource:
url: jdbc:postgresql://localhost:5432/easypay
username: easypay
password: easypay
driverClassName: org.postgresql.Driver
sql:
init:
schema-locations: classpath*:db/postgresql/schema.sql
data-locations: classpath*:db/postgresql/data.sql
mode: ALWAYS
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spring:
config:
activate:
on-profile: default
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}

---
spring:
config:
activate:
on-profile: default
datasource:
url: jdbc:postgresql://localhost:5434/fraudetect
username: fraudetect
password: fraudetect
driverClassName: org.postgresql.Driver
sql:
init:
schema-locations: optional:classpath*:db/postgresql/schema.sql
data-locations: optional:classpath*:db/postgresql/data.sql
mode: ALWAYS
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
spring:
config:
activate:
on-profile: default
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}

---
spring:
config:
activate:
on-profile: default
datasource:
url: jdbc:postgresql://localhost:5435/merchantbo
username: merchantbo
password: merchantbo
driverClassName: org.postgresql.Driver
sql:
init:
schema-locations: optional:classpath*:db/postgresql/schema.sql
data-locations: optional:classpath*:db/postgresql/data.sql
mode: ALWAYS
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,21 @@ spring:
on-profile: default
eureka:
instance:
instance-id: ${spring.application.name}:${random.uuid}
instance-id: ${spring.application.name}:${random.uuid}

---

spring:
config:
activate:
on-profile: default
datasource:
url: jdbc:postgresql://localhost:5433/smartbank
username: smartbank
password: smartbank
driverClassName: org.postgresql.Driver
sql:
init:
schema-locations: optional:classpath*:db/postgresql/schema.sql
data-locations: optional:classpath*:db/postgresql/data.sql
mode: ALWAYS
37 changes: 37 additions & 0 deletions easypay-service/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
HELP.md
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/
53 changes: 53 additions & 0 deletions easypay-service/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
plugins {
java
id("org.springframework.boot") version "3.2.5"
id("io.spring.dependency-management") version "1.1.4"
// id("org.graalvm.buildtools.native") version "0.9.28"
}

group = "com.worldline.easypay"
version = "0.0.1-SNAPSHOT"

java {
sourceCompatibility = JavaVersion.VERSION_21
}

repositories {
mavenCentral()
}

extra["springCloudVersion"] = "2023.0.1"
extra["springDocVersion"] = "2.5.0"

dependencies {
implementation("org.springframework.boot:spring-boot-starter-actuator")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("org.springframework.boot:spring-boot-starter-validation")
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.cloud:spring-cloud-starter-config")
implementation("org.springframework.cloud:spring-cloud-starter-netflix-eureka-client")
implementation("org.springframework.cloud:spring-cloud-starter-loadbalancer")
implementation("org.springframework.cloud:spring-cloud-starter-openfeign")
// implementation("io.github.danielliu1123:httpexchange-spring-boot-starter:3.2.5")
implementation("org.springframework.cloud:spring-cloud-starter-circuitbreaker-resilience4j")

implementation("org.springframework.cloud:spring-cloud-stream")
implementation("org.springframework.cloud:spring-cloud-stream-binder-kafka")
implementation("org.springframework.kafka:spring-kafka")

implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:${property("springDocVersion")}")
developmentOnly("org.springframework.boot:spring-boot-devtools")
runtimeOnly("com.h2database:h2")
runtimeOnly("org.postgresql:postgresql")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}

dependencyManagement {
imports {
mavenBom("org.springframework.cloud:spring-cloud-dependencies:${property("springCloudVersion")}")
}
}

tasks.withType<Test> {
useJUnitPlatform()
}
9 changes: 9 additions & 0 deletions easypay-service/create.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
create table card_ref (blacklisted boolean, id bigserial not null, card_number varchar(255) unique, card_type varchar(255) check (card_type in ('UNKNOWN','VISA','MASTERCARD','AMERICAN_EXPRESS','DINERS_CLUB','DISCOVER','JCB','CHINA_UNION_PAY')), primary key (id));
create table payment (amount integer, authorized boolean, bank_called boolean, date_time timestamp(6), response_time bigint, authorization_id uuid, id uuid not null, card_number varchar(255), card_type varchar(255) check (card_type in ('UNKNOWN','VISA','MASTERCARD','AMERICAN_EXPRESS','DINERS_CLUB','DISCOVER','JCB','CHINA_UNION_PAY')), expiry_date varchar(255), pos_id varchar(255), processing_mode varchar(255) check (processing_mode in ('STANDARD','FALLBACK')), response_code varchar(255) check (response_code in ('ACCEPTED','INACTIVE_POS','INVALID_CARD_NUMBER','BLACK_LISTED_CARD_NUMBER','UNKNWON_CARD_TYPE','AUTHORIZATION_DENIED','AMOUNT_EXCEEDED')), primary key (id));
create table pos_ref (active boolean, id bigserial not null, location varchar(255), pos_id varchar(255) unique, primary key (id));
create table card_ref (blacklisted boolean, id bigserial not null, card_number varchar(255) unique, card_type varchar(255) check (card_type in ('UNKNOWN','VISA','MASTERCARD','AMERICAN_EXPRESS','DINERS_CLUB','DISCOVER','JCB','CHINA_UNION_PAY')), primary key (id));
create table payment (amount integer, authorized boolean, bank_called boolean, date_time timestamp(6), response_time bigint, authorization_id uuid, id uuid not null, card_number varchar(255), card_type varchar(255) check (card_type in ('UNKNOWN','VISA','MASTERCARD','AMERICAN_EXPRESS','DINERS_CLUB','DISCOVER','JCB','CHINA_UNION_PAY')), expiry_date varchar(255), pos_id varchar(255), processing_mode varchar(255) check (processing_mode in ('STANDARD','FALLBACK')), response_code varchar(255) check (response_code in ('ACCEPTED','INACTIVE_POS','INVALID_CARD_NUMBER','BLACK_LISTED_CARD_NUMBER','UNKNWON_CARD_TYPE','AUTHORIZATION_DENIED','AMOUNT_EXCEEDED')), primary key (id));
create table pos_ref (active boolean, id bigserial not null, location varchar(255), pos_id varchar(255) unique, primary key (id));
create table card_ref (blacklisted boolean, id bigserial not null, card_number varchar(255) unique, card_type varchar(255) check (card_type in ('UNKNOWN','VISA','MASTERCARD','AMERICAN_EXPRESS','DINERS_CLUB','DISCOVER','JCB','CHINA_UNION_PAY')), primary key (id));
create table payment (amount integer, authorized boolean, bank_called boolean, date_time timestamp(6), response_time bigint, authorization_id uuid, id uuid not null, card_number varchar(255), card_type varchar(255) check (card_type in ('UNKNOWN','VISA','MASTERCARD','AMERICAN_EXPRESS','DINERS_CLUB','DISCOVER','JCB','CHINA_UNION_PAY')), expiry_date varchar(255), pos_id varchar(255), processing_mode varchar(255) check (processing_mode in ('STANDARD','FALLBACK')), response_code varchar(255) check (response_code in ('ACCEPTED','INACTIVE_POS','INVALID_CARD_NUMBER','BLACK_LISTED_CARD_NUMBER','UNKNWON_CARD_TYPE','AUTHORIZATION_DENIED','AMOUNT_EXCEEDED')), primary key (id));
create table pos_ref (active boolean, id bigserial not null, location varchar(255), pos_id varchar(255) unique, primary key (id));
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.worldline.easypay;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.openfeign.EnableFeignClients;

import com.worldline.easypay.payment.control.bank.BankAuthorClient;


@SpringBootApplication
@EnableDiscoveryClient
@EnableFeignClients
public class EasypayServiceApplication {

public static void main(String[] args) {
SpringApplication.run(EasypayServiceApplication.class, args);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.worldline.easypay.cardref.boundary;

import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.worldline.easypay.cardref.control.CardService;

import io.swagger.v3.oas.annotations.Operation;

import java.util.List;

import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;

@RestController
@RequestMapping("/cards")
public class CardRefResource {

CardService cardService;

public CardRefResource(CardService cardService) {
this.cardService = cardService;
}

@GetMapping
@Operation(description = "List all cards declared as reference data in the system", summary = "List all cards")
public ResponseEntity<List<CardRefResponse>> findAll() {
return ResponseEntity.ok(cardService.listAll());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.worldline.easypay.cardref.boundary;

public record CardRefResponse(
String cardNumber,
String cardType,
Boolean blackListed) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.worldline.easypay.cardref.control;

import java.util.List;

import org.springframework.stereotype.Service;

import com.worldline.easypay.cardref.boundary.CardRefResponse;
import com.worldline.easypay.cardref.entity.CardRef;
import com.worldline.easypay.cardref.entity.CardRefRepository;

@Service
public class CardService {

CardRefRepository repository;

public CardService(CardRefRepository repository) {
this.repository = repository;
}

public List<CardRefResponse> listAll() {
return repository.findAll().stream().map(this::toResponse).toList();
}

private CardRefResponse toResponse(CardRef cardRef) {
return new CardRefResponse(cardRef.cardNumber, cardRef.cardType.toString(), cardRef.blackListed);
}
}
Loading

0 comments on commit 5eb71b9

Please sign in to comment.