mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
se descomento el resultado paginado y se agrego un endpoint de test
This commit is contained in:
parent
003a0ecd42
commit
bcd903c14a
3 changed files with 40 additions and 23 deletions
|
|
@ -5,6 +5,7 @@ import com.code.hyperledger.models.AssetIdDto;
|
|||
import com.code.hyperledger.models.Receta;
|
||||
import com.code.hyperledger.models.RecetaDto;
|
||||
import com.code.hyperledger.services.RecetaService;
|
||||
import main.java.com.code.hyperledger.models.ResultadoPaginado;
|
||||
|
||||
import main.java.com.code.hyperledger.models.RecetaRequestDto;
|
||||
|
||||
|
|
@ -164,8 +165,7 @@ public class RecetaController {
|
|||
} catch (GatewayException e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
|
@ -191,8 +191,7 @@ public class RecetaController {
|
|||
} catch (GatewayException e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
|
@ -217,13 +216,25 @@ public class RecetaController {
|
|||
} catch (GatewayException e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
@PostMapping("/obtener/paginado")
|
||||
private ResponseEntity<ResultadoPaginado> obtenerPaginadoTest() {
|
||||
|
||||
try {
|
||||
ResultadoPaginado recetas = recetaService.obtenerRecetasPorDniYEstadoPaginado("12345678", "active", 10, "");
|
||||
return new ResponseEntity<>(recetas, HttpStatus.OK);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private RecetaDto mapToDto(Receta receta) {
|
||||
RecetaDto dto = new RecetaDto();
|
||||
dto.setId(receta.getId());
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
/*package com.code.hyperledger.models;
|
||||
package main.java.com.code.hyperledger.models;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
|
|
@ -13,4 +13,3 @@ public class ResultadoPaginado<T> {
|
|||
private List<T> recetas;
|
||||
private String bookmark;
|
||||
}
|
||||
*/
|
||||
|
|
@ -11,6 +11,8 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
|||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import lombok.SneakyThrows;
|
||||
import main.java.com.code.hyperledger.models.ResultadoPaginado;
|
||||
|
||||
import org.hyperledger.fabric.client.*;
|
||||
import org.hyperledger.fabric.client.identity.*;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
|
@ -25,6 +27,7 @@ import java.security.cert.CertificateException;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import com.fasterxml.jackson.databind.JavaType;
|
||||
|
||||
@Service
|
||||
public class RecetaService {
|
||||
|
|
@ -98,6 +101,7 @@ public class RecetaService {
|
|||
var network = gateway.getNetwork(config.getChannelName());
|
||||
contract = network.getContract(config.getChaincodeName());
|
||||
}
|
||||
|
||||
// crea dos recetas default, borrar cuando no se necesite
|
||||
private void initLedger() throws EndorseException, SubmitException, CommitStatusException, CommitException {
|
||||
contract.submitTransaction("InitLedger");
|
||||
|
|
@ -145,19 +149,22 @@ public class RecetaService {
|
|||
contract.submitTransaction("DeleteReceta", recetaId);
|
||||
}
|
||||
|
||||
/*
|
||||
* public ResultadoPaginado<RecetaDto> obtenerRecetasPorDniYEstadoPaginado(
|
||||
* String dni, String estado, int pageSize, String bookmark) throws Exception {
|
||||
*
|
||||
* var result = contract.evaluateTransaction("GetRecetasPorDniYEstado", dni,
|
||||
* estado,
|
||||
* String.valueOf(pageSize), bookmark);
|
||||
*
|
||||
* var type = new ObjectMapper()
|
||||
* .getTypeFactory()
|
||||
* .constructParametricType(ResultadoPaginado.class, RecetaDto.class);
|
||||
*
|
||||
* return new ObjectMapper().readValue(result, type);
|
||||
* }
|
||||
*/
|
||||
public ResultadoPaginado<RecetaDto> obtenerRecetasPorDniYEstadoPaginado(
|
||||
String dni, String estado, int pageSize, String bookmark) throws Exception {
|
||||
|
||||
byte[] result = contract.evaluateTransaction(
|
||||
"GetRecetasPorDniYEstado",
|
||||
dni,
|
||||
estado,
|
||||
String.valueOf(pageSize),
|
||||
bookmark);
|
||||
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
JavaType tipo = mapper.getTypeFactory()
|
||||
.constructParametricType(ResultadoPaginado.class, RecetaDto.class);
|
||||
ResultadoPaginado<RecetaDto> resultado = mapper.readValue(json, tipo);
|
||||
|
||||
return mapper.readValue(result, type);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue