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