mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
algunos fixes, falta datetime
This commit is contained in:
parent
79da291bd1
commit
3f29718c54
4 changed files with 41 additions and 6 deletions
|
|
@ -76,6 +76,11 @@
|
|||
<version>1.5.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||
<version>2.15.2</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
|
|
|
|||
|
|
@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.time.Instant;
|
||||
import java.util.Map;
|
||||
|
||||
@RestController
|
||||
|
||||
|
|
@ -22,7 +24,7 @@ public class RecetaController {
|
|||
private RecetaService recetaService;
|
||||
|
||||
@PostMapping("/crear")
|
||||
public ResponseEntity<Receta> crear(Receta receta) {
|
||||
public ResponseEntity<Receta> crear(@RequestBody Receta receta) {
|
||||
System.out.println("\n--> Submit Transaction: CreateAsset, creates new asset with all arguments");
|
||||
|
||||
String assetId = "asset" + Instant.now().toEpochMilli();
|
||||
|
|
@ -38,12 +40,16 @@ public class RecetaController {
|
|||
}
|
||||
|
||||
@PostMapping("/obtener")
|
||||
public ResponseEntity<Receta> find(String id) {
|
||||
public ResponseEntity<Receta> find(@RequestBody Map<String, String> requestBody) {
|
||||
try {
|
||||
return new ResponseEntity<>(recetaService.obtenerReceta(id), HttpStatus.OK);
|
||||
System.out.println("requestbody: " + requestBody);
|
||||
String id = requestBody.get("id");
|
||||
System.out.println("id: " + id);
|
||||
Receta receta = recetaService.obtenerReceta(id);
|
||||
return new ResponseEntity<>(receta, HttpStatus.OK);
|
||||
} catch (IOException | GatewayException e) {
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.NOT_FOUND);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,24 +7,42 @@ import lombok.NoArgsConstructor;
|
|||
import java.time.LocalDate;
|
||||
import java.time.LocalDateTime;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class Receta {
|
||||
@JsonProperty("ID")
|
||||
private String id;
|
||||
@JsonProperty("Owner")
|
||||
private String owner;
|
||||
@JsonProperty("PrescripcionAnteriorId")
|
||||
private String prescripcionAnteriorId;
|
||||
@JsonProperty("Status")
|
||||
private String status;
|
||||
@JsonProperty("StatusChange")
|
||||
private LocalDateTime statusChange;
|
||||
@JsonProperty("Prioridad")
|
||||
private String prioridad;
|
||||
@JsonProperty("Medicacion")
|
||||
private String medicacion;
|
||||
@JsonProperty("Razon")
|
||||
private String razon;
|
||||
@JsonProperty("Notas")
|
||||
private String notas;
|
||||
@JsonProperty("PeriodoDeTratamiento")
|
||||
private String periodoDeTratamiento;
|
||||
@JsonProperty("InstruccionesTratamiento")
|
||||
private String instruccionesTratamiento;
|
||||
@JsonProperty("PeriodoDeValidez")
|
||||
private String periodoDeValidez;
|
||||
@JsonProperty("DniPaciente")
|
||||
private String dniPaciente;
|
||||
@JsonProperty("FechaDeAutorizacion")
|
||||
private LocalDate fechaDeAutorizacion;
|
||||
@JsonProperty("Cantidad")
|
||||
private int cantidad;
|
||||
@JsonProperty("ExpectedSupplyDuration")
|
||||
private LocalDate expectedSupplyDuration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,6 +13,8 @@ import org.hyperledger.fabric.client.identity.*;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
|
||||
import java.io.Console;
|
||||
import java.io.IOException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.nio.file.Files;
|
||||
|
|
@ -148,8 +150,12 @@ public class RecetaService {
|
|||
public Receta obtenerReceta(String assetId) throws GatewayException, IOException {
|
||||
System.out.println("\n--> Evaluate Transaction: ReadAsset, function returns asset attributes");
|
||||
|
||||
System.out.println("assetId: " + assetId);
|
||||
var evaluateResult = contract.evaluateTransaction("ReadAsset", assetId);
|
||||
System.out.println("evaluate");
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
return objectMapper.readValue(evaluateResult, Receta.class);
|
||||
var receta = objectMapper.readValue(evaluateResult, Receta.class);
|
||||
System.out.println("mapper:" + receta.getDniPaciente());
|
||||
return receta;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue