WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a9ed054
first commit
ThadeuFerreira May 14, 2019
4129579
ThadeuFerreira May 14, 2019
dfd3257
Add JWT
ThadeuFerreira May 14, 2019
3e659b9
Add User Authentitication
ThadeuFerreira May 14, 2019
6af5b2e
Using new archtecure.
ThadeuFerreira May 15, 2019
25887ef
Add credit card and spending details.
ThadeuFerreira May 15, 2019
60ef0f3
Add add new credit card to User
ThadeuFerreira May 15, 2019
d2059a1
Add spending controller, now users can add spendings associated to a …
ThadeuFerreira May 15, 2019
4bfc76f
Calculate the total amount from a credit card request.
ThadeuFerreira May 16, 2019
a48c041
Filter spending by date.
ThadeuFerreira May 16, 2019
eb18b04
Merge remote-tracking branch 'refs/remotes/origin/master'
ThadeuFerreira May 16, 2019
7e0ece5
Add feature to find spending without category and feature to edit a s…
ThadeuFerreira May 17, 2019
679b180
Add feature to automatic find spending category based on its descript…
ThadeuFerreira May 17, 2019
3413fa0
Add docker support
ThadeuFerreira May 17, 2019
4c87b28
Fix minor error
ThadeuFerreira May 17, 2019
d8fc74f
Update README.md
ThadeuFerreira May 17, 2019
a71dfd2
Add Swagger
ThadeuFerreira May 21, 2019
91e5922
Merge remote-tracking branch 'origin/master'
ThadeuFerreira May 21, 2019
f767639
Update README.md
ThadeuFerreira May 21, 2019
ab3e726
Add appengine
ThadeuFerreira May 21, 2019
4be31f8
Merge remote-tracking branch 'origin/master'
ThadeuFerreira May 21, 2019
d503a14
Add appengine
ThadeuFerreira May 21, 2019
677d41c
Add Hello world controller
ThadeuFerreira May 21, 2019
aa6afb6
Add Hello world controller
ThadeuFerreira May 21, 2019
26c69fa
Revert "Add Hello world controller"
ThadeuFerreira May 21, 2019
900b293
Revert "Add Hello world controller"
ThadeuFerreira May 21, 2019
9eef772
Revert "Add appengine"
ThadeuFerreira May 21, 2019
5728079
Revert "Merge remote-tracking branch 'origin/master'"
ThadeuFerreira May 21, 2019
6c4f186
Revert "Add appengine"
ThadeuFerreira May 21, 2019
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
29 changes: 29 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
HELP.md
/target/
!.mvn/wrapper/maven-wrapper.jar

### 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/

### VS Code ###
.vscode/
114 changes: 114 additions & 0 deletions .mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
/*
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.
*/

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.net.URL;
import java.nio.channels.Channels;
import java.nio.channels.ReadableByteChannel;
import java.util.Properties;

public class MavenWrapperDownloader {

/**
* Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided.
*/
private static final String DEFAULT_DOWNLOAD_URL =
"https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.2/maven-wrapper-0.4.2.jar";

/**
* Path to the maven-wrapper.properties file, which might contain a downloadUrl property to
* use instead of the default one.
*/
private static final String MAVEN_WRAPPER_PROPERTIES_PATH =
".mvn/wrapper/maven-wrapper.properties";

/**
* Path where the maven-wrapper.jar will be saved to.
*/
private static final String MAVEN_WRAPPER_JAR_PATH =
".mvn/wrapper/maven-wrapper.jar";

/**
* Name of the property which should be used to override the default download url for the wrapper.
*/
private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl";

public static void main(String args[]) {
System.out.println("- Downloader started");
File baseDirectory = new File(args[0]);
System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath());

// If the maven-wrapper.properties exists, read it and check if it contains a custom
// wrapperUrl parameter.
File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH);
String url = DEFAULT_DOWNLOAD_URL;
if(mavenWrapperPropertyFile.exists()) {
FileInputStream mavenWrapperPropertyFileInputStream = null;
try {
mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile);
Properties mavenWrapperProperties = new Properties();
mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream);
url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url);
} catch (IOException e) {
System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'");
} finally {
try {
if(mavenWrapperPropertyFileInputStream != null) {
mavenWrapperPropertyFileInputStream.close();
}
} catch (IOException e) {
// Ignore ...
}
}
}
System.out.println("- Downloading from: : " + url);

File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH);
if(!outputFile.getParentFile().exists()) {
if(!outputFile.getParentFile().mkdirs()) {
System.out.println(
"- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'");
}
}
System.out.println("- Downloading to: " + outputFile.getAbsolutePath());
try {
downloadFileFromURL(url, outputFile);
System.out.println("Done");
System.exit(0);
} catch (Throwable e) {
System.out.println("- Error downloading");
e.printStackTrace();
System.exit(1);
}
}

private static void downloadFileFromURL(String urlString, File destination) throws Exception {
URL website = new URL(urlString);
ReadableByteChannel rbc;
rbc = Channels.newChannel(website.openStream());
FileOutputStream fos = new FileOutputStream(destination);
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
fos.close();
rbc.close();
}

}
Binary file added .mvn/wrapper/maven-wrapper.jar
Binary file not shown.
1 change: 1 addition & 0 deletions .mvn/wrapper/maven-wrapper.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.6.0/apache-maven-3.6.0-bin.zip
20 changes: 20 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Start with a base image containing Java runtime
FROM openjdk:8-jdk-alpine

# Add Maintainer Info
LABEL maintainer="[email protected]"

# Add a volume pointing to /tmp
VOLUME /tmp

# Make port 8080 available to the world outside this container
EXPOSE 8080

# The application's jar file
ARG JAR_FILE=target/SantanderTechnologies-0.0.1-SNAPSHOT.jar

# Add the application's jar to the container
ADD ${JAR_FILE} app.jar

# Run the jar file
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
115 changes: 115 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,118 @@
# Como executar

# Docker-Compose

Execute as seguintes linhas de comando

git clone https://github.com/ThadeuFerreira/TestBackJava
cd TestBackJava
mvn package
java -jar target/SantanderTechnologies-0.0.1-SNAPSHOT.jar

docker-compose build
docker-compose up

ATENÇÃO!
É possivel que na primeira vez que seja executado a aplicação java tente se conectar com o banco de dados antes dele estar funcionando.
Nesse caso, tente novamente. Se o erro persistir, execute a aplicação e o banco de dados separadamente, proxima sessão.

# Executando o banco de dados se paradamente

Crie um servidor de banco de dados mysql no localhost e portas padão 3306 com senha de root "password" e nome test
Ou execute o comando a seguir para criar o servidor e banco pelo Docker

docker run --name mysql -e MYSQL_ROOT_PASSWORD=password -e MYSQL_DATABASE=test -p 3306:3306 -p 33060:33060 -d mysql:latest

Execute a aplicação

mvn spring-boot:run

# Como utilizar a API

A autenticação é feita utilizando Bearer Token. Criar usuário não requer autenticação, todas as outras requisicões precisam do Token obtido no login.

- Criar usuário


POST localhost:8080/api/auth/signup

Payload
{
"name": "Thadeu Costa",
"username": "ThadeuCosta",
"email":"[email protected]",
"password":"Secret"
}

- Login



Post http://localhost:8080/api/auth/signin
Payload
{
"usernameOrEmail":"ThadeuCosta" ,
"password":"Secret"
}

- Criar novo cartão de crédito


POST http://localhost:8080/api/user/newCreditCard
Payload
{
"number":"666 666 666 666",
"validationCode":"666",
"clientName":"Thadeu Antonio F Melo",
"duoDate":"2020-04-21T18:25:43-05:00"
}

- Adicionar gasto em um Cartão


POST http://localhost:8080/api/spending
Payload
{
"description":"Descrição",
"amount": 88.10,
"category": "Roupas",
"date": "2019-05-21T18:25:43-05:00",
"creditCardNumber":"666 666 666 666"
}


- Listar total de gastos do Cartão


GET http://localhost:8080/api/creditcard/details/<numero do cartão>

- Listar todos os gastos do usuário


GET http://localhost:8080/api/user/creditCards

- Listar gastos filtrados por dia


GET http://localhost:8080/api/spending/filterbydate/21052019

- Listar gastos sem category de um Cartão


GET http://localhost:8080/api/spending/nocategory/<numero do cartão>

- Editar a categoria de um gasto


POST http://localhost:8080/api/spending/edit
Payload
{
"spendingId":9,
"category":"Games"
}



# Show me the code

### # DESAFIO:
Expand Down
47 changes: 47 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Docker Compose file Reference (https://docs.docker.com/compose/compose-file/)

version: '3.3'

# Define services
services:
# App backend service
app-server:
# Configuration for building the docker image for the backend service
build:
context: . # Use an image built from the specified dockerfile in the `polling-app-server` directory.
dockerfile: Dockerfile
ports:
- "8080:8080" # Forward the exposed port 8080 on the container to port 8080 on the host machine
restart: always
depends_on:
- db # This service depends on mysql. Start that first.
environment: # Pass environment variables to the service
SPRING_DATASOURCE_URL: jdbc:mysql://db:3306/test?useSSL=false&serverTimezone=UTC&useLegacyDatetimeCode=false
SPRING_DATASOURCE_USERNAME: test
SPRING_DATASOURCE_PASSWORD: password
networks: # Networks to join (Services on the same network can communicate with each other using their name)
- backend

# Database Service (Mysql)
db:
image: mysql:5.7
ports:
- "3306:3306"
restart: always
environment:
MYSQL_DATABASE: test
MYSQL_USER: test
MYSQL_PASSWORD: password
MYSQL_ROOT_PASSWORD: root
volumes:
- db-data:/var/lib/mysql
networks:
- backend

# Volumes
volumes:
db-data:

# Networks to be created to facilitate communication between containers
networks:
backend:
Loading