Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

96 changes: 96 additions & 0 deletions api-root.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
openapi: 3.0.0
info:
title: Combined SimilarProducts API
version: '1.0'
servers:
- url: 'http://localhost:5000'
- url: 'http://localhost:3001'

paths:
/product:
get:
operationId: getAllProducts
summary: Products
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ProductDetail'
'404':
description: Product Not found

/product/{productId}/similar:
get:
operationId: getSimilarProductDetails
summary: Similar products
parameters:
- name: productId
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ProductDetail'
'404':
description: Product Not found

/product/{productId}/similarids:
get:
operationId: getSimilarProductsIds
summary: Gets the ids of similar products
parameters:
- name: productId
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/SimilarProductIds'

/product/{productId}:
get:
operationId: getProductId
summary: Gets a product detail
parameters:
- name: productId
in: path
required: true
schema:
type: string
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/ProductDetail'
'404':
description: Product Not found

components:
schemas:
ProductDetail:
type: object
$ref: './similarProducts.yaml#/components/schemas/ProductDetail'
description: List of similar products with full details
SimilarProductIds:
type: array
items:
type: string
description: List of similar product IDs
9 changes: 9 additions & 0 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ services:
image: influxdb:1.8.2
ports:
- "8086:8086"
- "5005:5005"
environment:
- INFLUXDB_DB=k6
grafana:
Expand All @@ -23,6 +24,7 @@ services:
volumes:
- ./shared/simulado:/app
command: ./bin/simulado -f /app/mocks.json
platform: linux/amd64
k6:
image: loadimpact/k6:0.28.0
ports:
Expand All @@ -33,3 +35,10 @@ services:
- K6_OUT=influxdb=http://influxdb:8086/k6
extra_hosts:
- "host.docker.internal:host-gateway"
backend:
build: .
ports:
- "5000:5000"
depends_on:
- influxdb
- grafana
18 changes: 18 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
FROM maven:3.9.6-eclipse-temurin-17 AS build
WORKDIR /app

COPY pom.xml .
COPY *.yaml .
COPY src ./src
COPY shared/simulado/mocks.json shared/simulado/mocks.json

RUN mvn clean package spring-boot:repackage -DskipTests

FROM eclipse-temurin:17-jre
WORKDIR /app

COPY --from=build /app/target/*.jar backendDevTest.jar

EXPOSE 5000 5005

CMD ["java", "-jar", "backendDevTest.jar", "--server.port=5000", "--server.address=0.0.0.0"]
16 changes: 16 additions & 0 deletions existingApis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ info:
servers:
- url: 'http://localhost:3001'
paths:
'/product':
get:
operationId: getAllProducts
summary: Products
responses:
'200':
description: OK
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/ProductDetail'
'404':
description: Product Not found

'/product/{productId}/similarids':
parameters:
- schema:
Expand Down
109 changes: 109 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.backendDevTest</groupId>
<artifactId>backendDevTest</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>

<properties>
<java.version>17</java.version>
<spring.boot.version>3.3.0</spring.boot.version>
<openapi.generator.version>7.0.0</openapi.generator.version>
</properties>

<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<version>${spring.boot.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>${spring.boot.version}</version>
</dependency>

<dependency>
<groupId>org.openapitools</groupId>
<artifactId>jackson-databind-nullable</artifactId>
<version>0.2.6</version>
</dependency>

<dependency>
<groupId>io.swagger.core.v3</groupId>
<artifactId>swagger-core-jakarta</artifactId>
<version>2.2.25</version>
</dependency>

<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId>
<version>2.2.0</version>
</dependency>
</dependencies>

<build>
<sourceDirectory>src/main/java</sourceDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>shared/simulado</directory>
<targetPath>.</targetPath>
<includes>
<include>mocks.json</include>
</includes>
</resource>
</resources>

<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>

<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi.generator.version}</version>
<executions>
<execution>
<id>generate-api</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/api-root.yaml</inputSpec>
<generatorName>spring</generatorName>
<output>${project.build.directory}/generated-sources</output>
<apiPackage>org.backendDevTest.infra.api</apiPackage>
<modelPackage>org.backendDevTest.infra.model</modelPackage>
<configOptions>
<interfaceOnly>true</interfaceOnly>
<useSpringBoot3>true</useSpringBoot3>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<encoding>UTF-8</encoding>
<generatedSourcesDirectory>${project.build.directory}/generated-sources</generatedSourcesDirectory>
</configuration>
</plugin>
</plugins>
</build>
</project>
11 changes: 11 additions & 0 deletions shared/simulado/mocks.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,5 +73,16 @@
"body": "{\"id\":\"10000\",\"name\":\"Leather jacket\",\"price\":89.99,\"availability\":true}",
"delay": 50000,
"headers": {"Content-Type": "application/json"}
},
{
"path": "/product/4/similar",
"body": "[{\"message\":\"Product not found\"}]",
"status": 404,
"headers": {"Content-Type": "application/json"}
},
{
"path": "/product/10000/similar",
"body": "[{\"id\":\"100000\",\"name\":\"Wool jacket\",\"price\":69.99,\"availability\":true}]",
"headers": {"Content-Type": "application/json"}
}
]
12 changes: 12 additions & 0 deletions src/main/java/org/backendDevTest/BackendDevTestApplication.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.backendDevTest;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class BackendDevTestApplication {

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