Skip to content

Commit

Permalink
Added validation to receive api
Browse files Browse the repository at this point in the history
  • Loading branch information
vsadokhin committed Sep 29, 2018
1 parent 5679e50 commit 5d1e08e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions data/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def mockito_version = "1.10.19"

dependencies {
compile 'com.datastax.cassandra:cassandra-driver-core:3.6.0'
compile 'org.hibernate:hibernate-validator:6.0.13.Final'

testCompile 'junit:junit:4.12'
testCompile("org.powermock:powermock-module-junit4:${powermock_version}") {
Expand Down
10 changes: 8 additions & 2 deletions data/src/main/java/me/vsadokhin/iot/data/domain/Metric.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
package me.vsadokhin.iot.data.domain;

import javax.validation.constraints.NotNull;

public class Metric {

@NotNull
private String sensorId;

@NotNull
private String type;

private long when;
@NotNull
private Long when;

private float value;
@NotNull
private Float value;

public String getSensorId() {
return sensorId;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.vsadokhin.iot.receive.api;

import javax.validation.Valid;

import me.vsadokhin.iot.data.domain.Metric;
import me.vsadokhin.iot.stream.producer.KafkaProducer;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -20,8 +22,7 @@ public MetricResource(KafkaProducer kafkaProducer) {
}

@PostMapping("/metric")
ResponseEntity create(@RequestBody Metric metric) {
// TODO Vasiliy validate
ResponseEntity create(@Valid @RequestBody Metric metric) {
kafkaProducer.sendAsync("metric", metric);
return new ResponseEntity<>(HttpStatus.ACCEPTED);
}
Expand Down

0 comments on commit 5d1e08e

Please sign in to comment.