mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-22 17:45:10 +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>
|
<version>1.5.1</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.datatype</groupId>
|
||||||
|
<artifactId>jackson-datatype-jsr310</artifactId>
|
||||||
|
<version>2.15.2</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -7,11 +7,13 @@ import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.http.HttpStatus;
|
import org.springframework.http.HttpStatus;
|
||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.PostMapping;
|
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.RequestMapping;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
|
|
||||||
|
|
@ -22,7 +24,7 @@ public class RecetaController {
|
||||||
private RecetaService recetaService;
|
private RecetaService recetaService;
|
||||||
|
|
||||||
@PostMapping("/crear")
|
@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");
|
System.out.println("\n--> Submit Transaction: CreateAsset, creates new asset with all arguments");
|
||||||
|
|
||||||
String assetId = "asset" + Instant.now().toEpochMilli();
|
String assetId = "asset" + Instant.now().toEpochMilli();
|
||||||
|
|
@ -38,12 +40,16 @@ public class RecetaController {
|
||||||
}
|
}
|
||||||
|
|
||||||
@PostMapping("/obtener")
|
@PostMapping("/obtener")
|
||||||
public ResponseEntity<Receta> find(String id) {
|
public ResponseEntity<Receta> find(@RequestBody Map<String, String> requestBody) {
|
||||||
try {
|
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) {
|
} catch (IOException | GatewayException e) {
|
||||||
e.printStackTrace();
|
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.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
public class Receta {
|
public class Receta {
|
||||||
|
@JsonProperty("ID")
|
||||||
private String id;
|
private String id;
|
||||||
|
@JsonProperty("Owner")
|
||||||
private String owner;
|
private String owner;
|
||||||
|
@JsonProperty("PrescripcionAnteriorId")
|
||||||
private String prescripcionAnteriorId;
|
private String prescripcionAnteriorId;
|
||||||
|
@JsonProperty("Status")
|
||||||
private String status;
|
private String status;
|
||||||
|
@JsonProperty("StatusChange")
|
||||||
private LocalDateTime statusChange;
|
private LocalDateTime statusChange;
|
||||||
|
@JsonProperty("Prioridad")
|
||||||
private String prioridad;
|
private String prioridad;
|
||||||
|
@JsonProperty("Medicacion")
|
||||||
private String medicacion;
|
private String medicacion;
|
||||||
|
@JsonProperty("Razon")
|
||||||
private String razon;
|
private String razon;
|
||||||
|
@JsonProperty("Notas")
|
||||||
private String notas;
|
private String notas;
|
||||||
|
@JsonProperty("PeriodoDeTratamiento")
|
||||||
private String periodoDeTratamiento;
|
private String periodoDeTratamiento;
|
||||||
|
@JsonProperty("InstruccionesTratamiento")
|
||||||
private String instruccionesTratamiento;
|
private String instruccionesTratamiento;
|
||||||
|
@JsonProperty("PeriodoDeValidez")
|
||||||
private String periodoDeValidez;
|
private String periodoDeValidez;
|
||||||
|
@JsonProperty("DniPaciente")
|
||||||
private String dniPaciente;
|
private String dniPaciente;
|
||||||
|
@JsonProperty("FechaDeAutorizacion")
|
||||||
private LocalDate fechaDeAutorizacion;
|
private LocalDate fechaDeAutorizacion;
|
||||||
|
@JsonProperty("Cantidad")
|
||||||
private int cantidad;
|
private int cantidad;
|
||||||
|
@JsonProperty("ExpectedSupplyDuration")
|
||||||
private LocalDate expectedSupplyDuration;
|
private LocalDate expectedSupplyDuration;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,8 @@ import org.hyperledger.fabric.client.identity.*;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import javax.annotation.PostConstruct;
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
|
import java.io.Console;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
|
@ -148,8 +150,12 @@ public class RecetaService {
|
||||||
public Receta obtenerReceta(String assetId) throws GatewayException, IOException {
|
public Receta obtenerReceta(String assetId) throws GatewayException, IOException {
|
||||||
System.out.println("\n--> Evaluate Transaction: ReadAsset, function returns asset attributes");
|
System.out.println("\n--> Evaluate Transaction: ReadAsset, function returns asset attributes");
|
||||||
|
|
||||||
|
System.out.println("assetId: " + assetId);
|
||||||
var evaluateResult = contract.evaluateTransaction("ReadAsset", assetId);
|
var evaluateResult = contract.evaluateTransaction("ReadAsset", assetId);
|
||||||
|
System.out.println("evaluate");
|
||||||
ObjectMapper objectMapper = new ObjectMapper();
|
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