Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
faermanj committed Sep 18, 2024
1 parent ae78787 commit c5ef2fe
Show file tree
Hide file tree
Showing 170 changed files with 13,540 additions and 0 deletions.
Binary file added img/gatling_perc.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions peecs
Empty file added peecs-1table/.dockerignore
Empty file.
3 changes: 3 additions & 0 deletions peecs-1table/.env.local
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
QUARKUS_DATASOURCE_JDBC_URL=jdbc:postgresql://localhost:5432/postgres
QUARKUS_DATASOURCE_USERNAME=gitpod
QUARKUS_DATASOURCE_PASSWORD=gitpod
43 changes: 43 additions & 0 deletions peecs-1table/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#Maven
target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
release.properties
.flattened-pom.xml

# Eclipse
.project
.classpath
.settings/
bin/

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

# NetBeans
nb-configuration.xml

# Visual Studio Code
.vscode
.factorypath

# OSX
.DS_Store

# Vim
*.swp
*.swo

# patch
*.orig
*.rej

# Local environment
.env

# Plugin directory
/.quarkus/cli/plugins/
1 change: 1 addition & 0 deletions peecs-1table/.mvn/wrapper/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
maven-wrapper.jar
98 changes: 98 additions & 0 deletions peecs-1table/.mvn/wrapper/MavenWrapperDownloader.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
/*
* 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
*
* http://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.IOException;
import java.io.InputStream;
import java.net.Authenticator;
import java.net.PasswordAuthentication;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;

public final class MavenWrapperDownloader
{
private static final String WRAPPER_VERSION = "3.2.0";

private static final boolean VERBOSE = Boolean.parseBoolean( System.getenv( "MVNW_VERBOSE" ) );

public static void main( String[] args )
{
log( "Apache Maven Wrapper Downloader " + WRAPPER_VERSION );

if ( args.length != 2 )
{
System.err.println( " - ERROR wrapperUrl or wrapperJarPath parameter missing" );
System.exit( 1 );
}

try
{
log( " - Downloader started" );
final URL wrapperUrl = new URL( args[0] );
final String jarPath = args[1].replace( "..", "" ); // Sanitize path
final Path wrapperJarPath = Paths.get( jarPath ).toAbsolutePath().normalize();
downloadFileFromURL( wrapperUrl, wrapperJarPath );
log( "Done" );
}
catch ( IOException e )
{
System.err.println( "- Error downloading: " + e.getMessage() );
if ( VERBOSE )
{
e.printStackTrace();
}
System.exit( 1 );
}
}

private static void downloadFileFromURL( URL wrapperUrl, Path wrapperJarPath )
throws IOException
{
log( " - Downloading to: " + wrapperJarPath );
if ( System.getenv( "MVNW_USERNAME" ) != null && System.getenv( "MVNW_PASSWORD" ) != null )
{
final String username = System.getenv( "MVNW_USERNAME" );
final char[] password = System.getenv( "MVNW_PASSWORD" ).toCharArray();
Authenticator.setDefault( new Authenticator()
{
@Override
protected PasswordAuthentication getPasswordAuthentication()
{
return new PasswordAuthentication( username, password );
}
} );
}
try ( InputStream inStream = wrapperUrl.openStream() )
{
Files.copy( inStream, wrapperJarPath, StandardCopyOption.REPLACE_EXISTING );
}
log( " - Downloader complete" );
}

private static void log( String msg )
{
if ( VERBOSE )
{
System.out.println( msg );
}
}

}
18 changes: 18 additions & 0 deletions peecs-1table/.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
#
# http://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.
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.6/apache-maven-3.9.6-bin.zip
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.2.0/maven-wrapper-3.2.0.jar
56 changes: 56 additions & 0 deletions peecs-1table/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# rinhadebackend

This project uses Quarkus, the Supersonic Subatomic Java Framework.

If you want to learn more about Quarkus, please visit its website: https://quarkus.io/ .

## Running the application in dev mode

You can run your application in dev mode that enables live coding using:
```shell script
./mvnw compile quarkus:dev
```

> **_NOTE:_** Quarkus now ships with a Dev UI, which is available in dev mode only at http://localhost:8080/q/dev/.
## Packaging and running the application

The application can be packaged using:
```shell script
./mvnw package
```
It produces the `quarkus-run.jar` file in the `target/quarkus-app/` directory.
Be aware that it’s not an _über-jar_ as the dependencies are copied into the `target/quarkus-app/lib/` directory.

The application is now runnable using `java -jar target/quarkus-app/quarkus-run.jar`.

If you want to build an _über-jar_, execute the following command:
```shell script
./mvnw package -Dquarkus.package.type=uber-jar
```

The application, packaged as an _über-jar_, is now runnable using `java -jar target/*-runner.jar`.

## Creating a native executable

You can create a native executable using:
```shell script
./mvnw package -Dnative
```

Or, if you don't have GraalVM installed, you can run the native executable build in a container using:
```shell script
./mvnw package -Dnative -Dquarkus.native.container-build=true
```

You can then execute your native executable with: `./target/rinhadebackend-1.0.0-SNAPSHOT-runner`

If you want to learn more about building native executables, please consult https://quarkus.io/guides/maven-tooling.

## Provided Code

### RESTEasy Reactive

Easily start your Reactive RESTful Web Services

[Related guide section...](https://quarkus.io/guides/getting-started-reactive#reactive-jax-rs-resources)
1 change: 1 addition & 0 deletions peecs-1table/default.iprof

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions peecs-1table/dev.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

quarkus dev -Djvm.args="-Djavaagent:dd-java-agent.jar -Ddd.profiling.enabled=true -XX:FlightRecorderOptions=stackdepth=256 -Ddd.logs.injection=true -Ddd.service=my-app -Ddd.env=staging -Ddd.version=1.0"
101 changes: 101 additions & 0 deletions peecs-1table/init.postgresql.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
CREATE UNLOGGED TABLE clientes (
id SERIAL PRIMARY KEY,
nome VARCHAR(255) NOT NULL,
limite INTEGER NOT NULL,
saldo INTEGER NOT NULL DEFAULT 0
);

CREATE UNLOGGED TABLE transacoes (
id SERIAL PRIMARY KEY,
cliente_id INTEGER NOT NULL,
valor INTEGER NOT NULL,
tipo CHAR(1) NOT NULL,
descricao VARCHAR(255) NOT NULL,
realizada_em TIMESTAMP NOT NULL DEFAULT NOW(),
CONSTRAINT fk_clientes_transacoes_id
FOREIGN KEY (cliente_id) REFERENCES clientes(id)
);

INSERT INTO clientes (nome, limite) VALUES
('o barato sai caro', 1000 * 100),
('zan corp ltda', 800 * 100),
('les cruders', 10000 * 100),
('padaria joia de cocaia', 100000 * 100),
('kid mais', 5000 * 100);
CREATE TYPE transacao_result AS (saldo INT, limite INT);

CREATE OR REPLACE FUNCTION proc_transacao(p_cliente_id INT, p_valor INT, p_tipo VARCHAR, p_descricao VARCHAR)
RETURNS transacao_result as $$
DECLARE
diff INT;
v_saldo INT;
v_limite INT;
result transacao_result;
BEGIN
IF p_tipo = 'd' THEN
diff := p_valor * -1;
ELSE
diff := p_valor;
END IF;

PERFORM * FROM clientes WHERE id = p_cliente_id FOR UPDATE;


UPDATE clientes
SET saldo = saldo + diff
WHERE id = p_cliente_id
RETURNING saldo, limite INTO v_saldo, v_limite;

IF (v_saldo + diff) < (-1 * v_limite) THEN
RAISE 'LIMITE_INDISPONIVEL [%, %, %]', v_saldo, diff, v_limite;
ELSE
result := (v_saldo, v_limite)::transacao_result;
INSERT INTO transacoes (cliente_id, valor, tipo, descricao)
VALUES (p_cliente_id, p_valor, p_tipo, p_descricao);
RETURN result;
END IF;
EXCEPTION
WHEN OTHERS THEN
RAISE 'Error processing transaction: %', SQLERRM;
ROLLBACK;
END;
$$ LANGUAGE plpgsql;CREATE OR REPLACE FUNCTION proc_extrato(p_id integer)
RETURNS json AS $$
DECLARE
result json;
row_count integer;
v_saldo numeric;
v_limite numeric;
BEGIN
SELECT saldo, limite
INTO v_saldo, v_limite
FROM clientes
WHERE id = p_id;

GET DIAGNOSTICS row_count = ROW_COUNT;

IF row_count = 0 THEN
RAISE EXCEPTION 'CLIENTE_NAO_ENCONTRADO %', p_id;
END IF;

SELECT json_build_object(
'saldo', json_build_object(
'total', v_saldo,
'data_extrato', TO_CHAR(NOW(), 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"'),
'limite', v_limite
),
'ultimas_transacoes', COALESCE((
SELECT json_agg(row_to_json(t)) FROM (
SELECT valor, tipo, descricao, TO_CHAR(realizada_em, 'YYYY-MM-DD"T"HH24:MI:SS.MS"Z"') as realizada_em
FROM transacoes
WHERE cliente_id = p_id
ORDER BY realizada_em DESC
LIMIT 10
) t
), '[]')
) INTO result;

RETURN result;
END;
$$ LANGUAGE plpgsql;
-- SQL init done
Loading

0 comments on commit c5ef2fe

Please sign in to comment.