Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Yape Code Challenge - José Portilla #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
83 changes: 6 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,84 +1,13 @@
# Yape Code Challenge :rocket:

Our code challenge will let you marvel us with your Jedi coding skills :smile:.
For the setup you only need to run 2 commands, that is if you already have docker installed. I assume you do :D

Don't forget that the proper way to submit your work is to fork the repo and create a PR :wink: ... have fun !!
Be sure you are positioned on the root folder that has the docker compose file and run these commands:

- [Yape Code Challenge :rocket:](#yape-code-challenge-rocket)
- [Problem](#problem)
- [Tech Stack](#tech-stack)
- [Optional](#optional)
- [Send us your challenge](#send-us-your-challenge)
docker-compose.exe -f .\yape-challenge-environment.yml build

# Problem
docker-compose.exe -f .\yape-challenge-environment.yml up -d

Every time a financial transaction is created it must be validated by our anti-fraud microservice and then the same service sends a message back to update the transaction status.
For now, we have only three transaction statuses:
To help you test my submission I prepared a Postman Collection you can import which can be found in the root folder too. Root folder also contains a Report I made that I invite you to read.

<ol>
<li>pending</li>
<li>approved</li>
<li>rejected</li>
</ol>

Every transaction with a value greater than 1000 should be rejected.

```mermaid
flowchart LR
Transaction -- Save Transaction with pending Status --> transactionDatabase[(Database)]
Transaction --Send transaction Created event--> Anti-Fraud
Anti-Fraud -- Send transaction Status Approved event--> Transaction
Anti-Fraud -- Send transaction Status Rejected event--> Transaction
Transaction -- Update transaction Status event--> transactionDatabase[(Database)]
```

# Tech Stack

<ol>
<li>Java. You can use any framework you want</li>
<li>Any database</li>
<li>Kafka</li>
</ol>

We do provide a `Dockerfile` to help you get started with a dev environment.

You must have two resources:

1. Resource to create a transaction that must containt:

```json
{
"accountExternalIdDebit": "Guid",
"accountExternalIdCredit": "Guid",
"tranferTypeId": 1,
"value": 120
}
```

2. Resource to retrieve a transaction

```json
{
"transactionExternalId": "Guid",
"transactionType": {
"name": ""
},
"transactionStatus": {
"name": ""
},
"value": 120,
"createdAt": "Date"
}
```

## Optional

You can use any approach to store transaction data but you should consider that we may deal with high volume scenarios where we have a huge amount of writes and reads for the same data at the same time. How would you tackle this requirement?

You can use Graphql;

# Send us your challenge

When you finish your challenge, after forking a repository, you **must** open a pull request to our repository. There are no limitations to the implementation, you can follow the programming paradigm, modularization, and style that you feel is the most appropriate solution.

If you have any questions, please let us know.
I am thrilled to hear back from you and receive the feedback about my hardwork.
Binary file not shown.
124 changes: 124 additions & 0 deletions YapeTestsPostmanCollection.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
{
"info": {
"_postman_id": "2ca7e9fd-341c-43ab-b788-b1dd53be86b5",
"name": "Transaction Service",
"description": "Collection for creating and retrieving transactions",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json",
"_exporter_id": "7764285"
},
"item": [
{
"name": "Create Transaction JSON",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"query\": \"mutation { createTransaction(accountExternalIdDebit: \\\"1234\\\", accountExternalIdCredit: \\\"5678\\\", transferTypeId: 1, value: 120) { transactionExternalId accountExternalIdDebit accountExternalIdCredit transferTypeId value transactionStatus createdAt } }\"\r\n}"
},
"url": {
"raw": "http://localhost:8080/graphql",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"graphql"
]
}
},
"response": []
},
{
"name": "Retrieve Transaction JSON",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "raw",
"raw": "{\r\n \"query\": \"mutation { createTransaction(accountExternalIdDebit: \\\"1234\\\", accountExternalIdCredit: \\\"5678\\\", transferTypeId: 1, value: 120) { transactionExternalId accountExternalIdDebit accountExternalIdCredit transferTypeId value transactionStatus createdAt } }\"\r\n}"
},
"url": {
"raw": "http://localhost:8080/graphql",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"graphql"
]
}
},
"response": []
},
{
"name": "Create Transaction GraphQL",
"request": {
"method": "POST",
"header": [
{
"key": "Content-Type",
"value": "application/json"
}
],
"body": {
"mode": "graphql",
"graphql": {
"query": "mutation {\r\n createTransaction(accountExternalIdDebit: \"123e4567-e89b-12d3-a456-426655440000\"\r\n, accountExternalIdCredit: \"123e4567-e89b-12d3-a456-426655440000\", transferTypeId: 1, value: 120) {\r\n transactionExternalId\r\n accountExternalIdDebit\r\n accountExternalIdCredit\r\n transferTypeId\r\n value\r\n transactionStatus\r\n createdAt\r\n }\r\n}",
"variables": ""
}
},
"url": {
"raw": "http://localhost:8080/graphql",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"graphql"
]
}
},
"response": []
},
{
"name": "GetTransaction GraphQL",
"request": {
"method": "POST",
"header": [],
"body": {
"mode": "graphql",
"graphql": {
"query": "{\r\n getTransaction(transactionExternalId: \"22c6d270-77ea-4afd-89e4-16a593df4af2\") {\r\n transactionExternalId\r\n accountExternalIdDebit\r\n accountExternalIdCredit\r\n transferTypeId\r\n value\r\n transactionStatus\r\n createdAt\r\n }\r\n}",
"variables": ""
}
},
"url": {
"raw": "http://localhost:8080/graphql",
"protocol": "http",
"host": [
"localhost"
],
"port": "8080",
"path": [
"graphql"
]
}
},
"response": []
}
]
}
33 changes: 33 additions & 0 deletions antifraud/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
HELP.md
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/

### STS ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache

### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/

### VS Code ###
.vscode/
18 changes: 18 additions & 0 deletions antifraud/.mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# https://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.1
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
26 changes: 26 additions & 0 deletions antifraud/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# Base image with JDK and Maven installed
FROM maven:3.8.4-openjdk-17 AS build

# Sets the working directory in the container
WORKDIR /app

# Copy the project files into the container
COPY . .

# Build the application
RUN mvn clean package -DskipTests

# Verify the build output
RUN ls -l /app/target

# Small base image for runtime
FROM openjdk:17-jdk-slim

# Sets the working directory in the container
WORKDIR /app

# Copy the JAR file from the build stage into the container
COPY --from=build /app/target/antifraud-0.0.1-SNAPSHOT.jar app.jar

# Specifies the command to run on container start
CMD ["java", "-jar", "app.jar"]
Loading