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
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,22 @@ docker volume create cotas-mysql
docker run -d --rm --name mysql-server -v cotas-mysql:/var/lib/mysql -p 3306:3306 -e MYSQL_ROOT_PASSWORD=123456 -e MYSQL_DATABASE=cotas mysql:8.0
```

```
# Start Zookeeper and expose port 2181 for use by the host machine
docker run -d --name zookeeper -p 2181:2181 confluent/zookeeper

# Start Kafka and expose port 9092 for use by the host machine
docker run -d --name kafka -p 9092:9092 --link zookeeper:zookeeper confluent/kafka

# Start Schema Registry and expose port 8081 for use by the host machine
docker run -d --name schema-registry -p 8081:8081 --link zookeeper:zookeeper \
--link kafka:kafka confluent/schema-registry

# Start REST Proxy and expose port 8082 for use by the host machine
docker run -d --name rest-proxy -p 8082:8082 --link zookeeper:zookeeper \
--link kafka:kafka --link schema-registry:schema-registry confluent/rest-proxy
```

## API Calls Examples

[Postman Documentation](https://documenter.getpostman.com/view/984544/SWTG6bCs)
Expand Down
7 changes: 5 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id 'org.springframework.boot' version '2.2.1.RELEASE'
id 'io.spring.dependency-management' version '1.0.8.RELEASE'
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.9.RELEASE'
id 'org.asciidoctor.convert' version '1.5.8'
id 'java'
id "org.flywaydb.flyway" version "6.1.0"
Expand Down Expand Up @@ -46,6 +46,9 @@ dependencies {
testCompile group: 'com.h2database', name: 'h2', version: '1.4.200'
compile group: 'org.springframework.boot', name: 'spring-boot-devtools'
compile group: 'com.zaxxer', name: 'HikariCP', version: '3.4.1'
compile group: 'org.springframework', name: 'spring-webflux', version: '5.2.4.RELEASE'
compile group: 'org.springframework.kafka', name: 'spring-kafka', version: '2.4.4.RELEASE'
compile group: 'org.springframework', name: 'spring-core', version: '5.2.5.RELEASE'
}

test {
Expand Down
5 changes: 3 additions & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#Sun Mar 29 19:53:19 BRT 2020
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-all.zip
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,12 @@
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.net.URI;
import java.util.Objects;

import static org.springframework.http.HttpStatus.CREATED;
import static org.springframework.http.HttpStatus.OK;

@RestController
@RequestMapping("/quotaHolder")
Expand All @@ -28,4 +30,14 @@ public QuotaHolder create(@RequestBody QuotaHolder quotaHolder) {
return quotaHolderRepository.save(quotaHolder);
}

@PutMapping("/{id}")
@ResponseStatus(OK)
public QuotaHolder atualizar(@PathVariable @NotNull Long id, @RequestBody QuotaHolder quotaHolder) {
if (Objects.isNull(quotaHolder.getName()))
throw new RequiredAttributeException("O nome do Investidor é obrigatório");

quotaHolder.setId(id);
return quotaHolderRepository.save(quotaHolder);
}

}
6 changes: 6 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,10 @@ spring.jpa.show-sql=true
spring.jpa.properties.hibernate.format_sql=true

#Logging
logging.level.root=ERROR
logging.level.com.javadevzone.cotas=INFO
logging.level.com.zaxxer.hikari=INFO

#Kafka
kafka.bootstrapAddress=localhost:9092
kafka.investmentTopic=investmentUpdated
9 changes: 9 additions & 0 deletions src/main/resources/db/migration/clear_database.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
drop table asset_history;
drop table wallet_investments;
drop table investment;
drop table asset;
drop table wallet_history;
drop table wallet_quota_holders;
drop table quota_holder;
drop table wallet;
drop table flyway_schema_history;
39 changes: 39 additions & 0 deletions src/test/java/com/javadevzone/cotas/TestWebflux.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.javadevzone.cotas;

import reactor.core.publisher.Mono;

public class TestWebflux {

public Mono<String> testandoUmaChamada() {
Mono<String> httpSource = Mono.just("");

return httpSource;
}

public Mono<Double> soma(Double x, Double y) {
Mono<Double> soma = Mono.just(x);
Mono<Double> valorSomado = soma.map(element -> {
System.out.println("Imprimindo");
if (true)
throw new NullPointerException("");

return element / y;
});
return valorSomado.doOnError(Throwable::printStackTrace);
}

public static void main(String[] args) {
TestWebflux webflux = new TestWebflux();
Mono<Double> soma = webflux.soma(10.0, Double.parseDouble("0"));
soma.subscribe(System.out::println);

// Double block = soma.block();
// System.out.println(block);

// LAZY
// Usuario u = findByIdUsuario(1L);

//u.getPermissoes();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.javadevzone.cotas.CotasApplication;
import com.javadevzone.cotas.entity.QuotaHolder;
import com.javadevzone.cotas.repository.QuotaHolderRepository;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -16,6 +17,7 @@
import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.test.web.servlet.ResultMatcher.matchAll;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@ExtendWith(SpringExtension.class)
Expand All @@ -29,6 +31,9 @@ public class QuotaHolderControllerTest {
@Autowired
private MockMvc mockMvc;

@Autowired
private QuotaHolderRepository quotaHolderRepository;

@Test
public void should_create_a_new_quota_holder() throws Exception {
QuotaHolder mrs_lovely = QuotaHolder.builder().name("Mrs Lovely").build();
Expand Down Expand Up @@ -58,4 +63,23 @@ public void should_throw_exception_when_creating_new_quota_holder_without_name()

}

@Test
public void should_update_quota_holder_name_then_return() throws Exception {
QuotaHolder savedQuotaHolder = quotaHolderRepository.save(QuotaHolder.builder().name("Mrs Lovely").build());

savedQuotaHolder.setName("Nequinho");
MvcResult mvcResult = mockMvc.perform(put("/quotaHolder/" + savedQuotaHolder.getId())
.contentType(APPLICATION_JSON)
.accept(APPLICATION_JSON)
.content(mapper.writeValueAsString(savedQuotaHolder)))
.andExpect(matchAll(status().isOk()))
.andReturn();

QuotaHolder investidor = mapper.readValue(mvcResult.getResponse().getContentAsString(), QuotaHolder.class);

assertThat(investidor.getName())
.isEqualTo(savedQuotaHolder.getName());

}

}