Gitlab - Argos ALM by PALO IT

Commit c79acb03 authored by Andres Isaac Garcia's avatar Andres Isaac Garcia

Improve upgrading and homologate BD

parent e017f1e1
...@@ -8,6 +8,7 @@ import lombok.NoArgsConstructor; ...@@ -8,6 +8,7 @@ import lombok.NoArgsConstructor;
@Data @Data
@NoArgsConstructor @NoArgsConstructor
public class MeasureDTO { public class MeasureDTO {
private String id;
private String deviceId; private String deviceId;
private String value; private String value;
private Instant date; private Instant date;
......
...@@ -2,6 +2,6 @@ package com.br.cardif.pocmeasureinternalrest.in.controller.model; ...@@ -2,6 +2,6 @@ package com.br.cardif.pocmeasureinternalrest.in.controller.model;
import java.time.Instant; import java.time.Instant;
public record MeasureRequest(String deviceId, String value, Instant date) { public record MeasureRequest(String id, String deviceId, String value, Instant date) {
} }
...@@ -3,6 +3,6 @@ package com.br.cardif.pocmeasureinternalrest.in.controller.model; ...@@ -3,6 +3,6 @@ package com.br.cardif.pocmeasureinternalrest.in.controller.model;
import java.io.Serializable; import java.io.Serializable;
import java.time.Instant; import java.time.Instant;
public record MeasureResponse(String deviceId, String value, Instant date) implements Serializable { public record MeasureResponse(String id, String deviceId, String value, Instant date) implements Serializable {
} }
...@@ -8,9 +8,11 @@ import com.br.cardif.pocmeasureinternalrest.out.mongo.MeasureDocument; ...@@ -8,9 +8,11 @@ import com.br.cardif.pocmeasureinternalrest.out.mongo.MeasureDocument;
import com.br.cardif.pocmeasureinternalrest.out.mongo.adapter.MeasureMongoAdapter; import com.br.cardif.pocmeasureinternalrest.out.mongo.adapter.MeasureMongoAdapter;
import lombok.RequiredArgsConstructor; import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Service @Service
@RequiredArgsConstructor @RequiredArgsConstructor
@Slf4j
public class MeasureService { public class MeasureService {
private final MeasureMongoAdapter measureMongoAdapter; private final MeasureMongoAdapter measureMongoAdapter;
...@@ -18,12 +20,13 @@ public class MeasureService { ...@@ -18,12 +20,13 @@ public class MeasureService {
public MeasureDTO updateMeasure(MeasureDTO measure){ public MeasureDTO updateMeasure(MeasureDTO measure){
MeasureDocument document = mapper.documentFromDto(measure); MeasureDocument document = mapper.documentFromDto(measure);
MeasureDocument documentResult =measureMongoAdapter.save(document); MeasureDocument documentResult = measureMongoAdapter.save(document);
return mapper.dtoFromDocument(documentResult); return mapper.dtoFromDocument(documentResult);
} }
public MeasureDTO getMeasure(String deviceId){ public MeasureDTO getMeasure(String deviceId){
MeasureDocument document = measureMongoAdapter.findById(deviceId); MeasureDocument document = measureMongoAdapter.findByDeviceId(deviceId);
log.info("Measure Id recovered from BD {}", document.getId());
return mapper.dtoFromDocument(document); return mapper.dtoFromDocument(document);
} }
} }
...@@ -10,13 +10,14 @@ import lombok.Getter; ...@@ -10,13 +10,14 @@ import lombok.Getter;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
import lombok.Setter; import lombok.Setter;
@Document @Document(collection = "measure")
@Setter @Setter
@Getter @Getter
@NoArgsConstructor @NoArgsConstructor
public class MeasureDocument public class MeasureDocument
{ {
@Id @Id
private String id;
private String deviceId; private String deviceId;
private String value; private String value;
private Instant date; private Instant date;
......
...@@ -23,5 +23,9 @@ public class MeasureMongoAdapter { ...@@ -23,5 +23,9 @@ public class MeasureMongoAdapter {
return repository.findById(deviceId).orElseThrow(() -> new HttpClientErrorException(HttpStatus.NOT_FOUND)); return repository.findById(deviceId).orElseThrow(() -> new HttpClientErrorException(HttpStatus.NOT_FOUND));
} }
public MeasureDocument findByDeviceId(String deviceId) {
return repository.findByDeviceId(deviceId).orElseThrow(() -> new HttpClientErrorException(HttpStatus.NOT_FOUND));
}
} }
package com.br.cardif.pocmeasureinternalrest.out.mongo.repo; package com.br.cardif.pocmeasureinternalrest.out.mongo.repo;
import java.util.Optional;
import org.springframework.data.mongodb.repository.MongoRepository; import org.springframework.data.mongodb.repository.MongoRepository;
import com.br.cardif.pocmeasureinternalrest.out.mongo.MeasureDocument; import com.br.cardif.pocmeasureinternalrest.out.mongo.MeasureDocument;
public interface MeasureMongoRepository extends MongoRepository<MeasureDocument, String> { public interface MeasureMongoRepository extends MongoRepository<MeasureDocument, String> {
Optional<MeasureDocument> findByDeviceId(String deviceId);
} }
...@@ -5,10 +5,10 @@ management.endpoint.health.show-components=always ...@@ -5,10 +5,10 @@ management.endpoint.health.show-components=always
management.endpoint.health.show-details=always management.endpoint.health.show-details=always
# MongoDB # MongoDB
spring.data.mongodb.uri=mongodb://user:pa55word@localhost/petstore?authSource=admin spring.data.mongodb.uri=mongodb://user:myPasswordMongo21c@localhost:27017/carrefur-database?authSource=admin
#logs #logs
logging.pattern.level: "%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]" logging.pattern.level=%5p [${spring.application.name:},%X{traceId:-},%X{spanId:-}]
# Actuator # Actuator
......
...@@ -23,11 +23,3 @@ spring.jackson.visibility.field=any ...@@ -23,11 +23,3 @@ spring.jackson.visibility.field=any
spring.jackson.visibility.getter=none spring.jackson.visibility.getter=none
spring.jackson.visibility.setter=none spring.jackson.visibility.setter=none
spring.jackson.visibility.is-getter=none spring.jackson.visibility.is-getter=none
spring.cloud.function.definition=measureConsumer
#Producer
spring.cloud.stream.bindings.measureProducer.destination=measure
# MongoDB
spring.data.mongodb.uri=mongodb://user:pa55word@localhost/petstore?authSource=admin
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment