mirror of
https://github.com/hyperledger/fabric-samples.git
synced 2026-06-17 15:35:09 +00:00
se eliminaron prints y comentarios innecesarios en los controllers
This commit is contained in:
parent
07204e131e
commit
f2493b14ab
2 changed files with 18 additions and 79 deletions
|
|
@ -35,24 +35,10 @@ public class RecetaController {
|
|||
|
||||
@PostMapping("/crear")
|
||||
public ResponseEntity<AssetIdDto> crear(@RequestBody Receta receta) {
|
||||
System.out.println("\n--> Submit Transaction: CrearReceta");
|
||||
|
||||
// Log para verificar los valores iniciales
|
||||
System.out.println("Receta recibida: " + receta);
|
||||
|
||||
String now = LocalDateTime.now().toString();
|
||||
String dni = receta.getPatientDocumentNumber();
|
||||
|
||||
// Log para ver el DNI y el timestamp
|
||||
System.out.println("DNI del paciente: " + dni);
|
||||
System.out.println("Timestamp actual: " + now);
|
||||
|
||||
String id = dni + now;
|
||||
String assetId = Hashing.sha256(id);
|
||||
|
||||
// Log para ver el ID generado
|
||||
System.out.println("ID generado para el asset: " + assetId);
|
||||
|
||||
receta.setId(assetId);
|
||||
|
||||
AssetIdDto assetIdDto = new AssetIdDto();
|
||||
|
|
@ -60,17 +46,9 @@ public class RecetaController {
|
|||
assetIdDto.setTimeStamp(now);
|
||||
|
||||
try {
|
||||
// Log antes de intentar cargar la receta
|
||||
System.out.println("Intentando cargar la receta...");
|
||||
|
||||
recetaService.cargarReceta(receta);
|
||||
|
||||
// Log después de que la receta fue cargada
|
||||
System.out.println("Receta cargada correctamente.");
|
||||
|
||||
return new ResponseEntity<>(assetIdDto, HttpStatus.OK);
|
||||
} catch (CommitStatusException | EndorseException | CommitException | SubmitException e) {
|
||||
// Log de error
|
||||
System.err.println("Error al cargar la receta: " + e.getMessage());
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
|
|
@ -79,35 +57,27 @@ public class RecetaController {
|
|||
|
||||
@PostMapping("/obtener")
|
||||
public ResponseEntity<RecetaDto> find(@RequestBody RecetaRequestDto requestBody) {
|
||||
logger.info("Received request to obtain receta with ID: {}", requestBody.getId()); // Log de entrada
|
||||
logger.info("Received request to obtain receta with ID: {}", requestBody.getId());
|
||||
|
||||
try {
|
||||
String id = requestBody.getId();
|
||||
logger.debug("Searching for receta with ID: {}", id); // Log de búsqueda
|
||||
logger.debug("Searching for receta with ID: {}", id);
|
||||
|
||||
Receta receta = recetaService.obtenerReceta(id);
|
||||
logger.debug("Receta found: {}", receta); // Log cuando se encuentra la receta
|
||||
logger.debug("Receta found: {}", receta);
|
||||
|
||||
RecetaDto recetaDto = mapToDto(receta);
|
||||
logger.info("Receta DTO created successfully for ID: {}", id); // Log de éxito
|
||||
logger.info("Receta DTO created successfully for ID: {}", id);
|
||||
|
||||
return new ResponseEntity<>(recetaDto, HttpStatus.OK);
|
||||
} catch (IOException e) {
|
||||
logger.error("IOException occurred while obtaining receta with ID: {}", requestBody.getId(), e); // Log de
|
||||
// excepción
|
||||
// específica
|
||||
logger.error("IOException occurred while obtaining receta with ID: {}", requestBody.getId(), e);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
} catch (GatewayException e) {
|
||||
logger.error("GatewayException occurred while obtaining receta with ID: {}", requestBody.getId(), e); // Log
|
||||
// de
|
||||
// excepción
|
||||
// Gateway
|
||||
logger.error("GatewayException occurred while obtaining receta with ID: {}", requestBody.getId(), e);
|
||||
return new ResponseEntity<>(HttpStatus.NOT_ACCEPTABLE);
|
||||
} catch (Exception e) {
|
||||
logger.error("Unexpected error occurred while obtaining receta with ID: {}", requestBody.getId(), e); // Log
|
||||
// de
|
||||
// error
|
||||
// inesperado
|
||||
logger.error("Unexpected error occurred while obtaining receta with ID: {}", requestBody.getId(), e);
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -121,10 +91,6 @@ public class RecetaController {
|
|||
}
|
||||
|
||||
List<Receta> recetas = recetaService.obtenerRecetasPorIds(ids);
|
||||
for (Receta receta : recetas) {
|
||||
System.out.println(" - " + receta.getId());
|
||||
}
|
||||
|
||||
List<RecetaDto> recetasDto = new ArrayList<>();
|
||||
for (Receta receta : recetas) {
|
||||
recetasDto.add(mapToDto(receta));
|
||||
|
|
@ -134,8 +100,6 @@ public class RecetaController {
|
|||
|
||||
return new ResponseEntity<>(recetasDto, HttpStatus.OK);
|
||||
|
||||
// 🔍 Log de los IDs obtenidos desde el service
|
||||
|
||||
} catch (IOException | GatewayException e) {
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
|
|
@ -154,19 +118,16 @@ public class RecetaController {
|
|||
if (id == null || id.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
System.out.println("\n--> Submit Transaction: EntregarReceta");
|
||||
|
||||
recetaService.entregarReceta(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
} catch (EndorseException | SubmitException | CommitStatusException | CommitException e) {
|
||||
e.printStackTrace(); // o algún log específico
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} catch (GatewayException e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -186,13 +147,13 @@ public class RecetaController {
|
|||
recetaService.firmarReceta(id, signature);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
} catch (EndorseException | SubmitException | CommitStatusException | CommitException e) {
|
||||
e.printStackTrace(); // o algún log específico
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} catch (GatewayException e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -210,19 +171,16 @@ public class RecetaController {
|
|||
if (id == null || id.isEmpty()) {
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
}
|
||||
|
||||
System.out.println("\n--> Submit Transaction: BorrarReceta");
|
||||
|
||||
recetaService.borrarReceta(id);
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
} catch (EndorseException | SubmitException | CommitStatusException | CommitException e) {
|
||||
e.printStackTrace(); // o algún log específico
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} catch (GatewayException e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(); // este bloque rara vez se ejecutaría si ya atrapás las anteriores
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
|
@ -233,7 +191,6 @@ public class RecetaController {
|
|||
@RequestParam List<String> estados,
|
||||
@RequestParam(defaultValue = "10") int pageSize,
|
||||
@RequestParam(defaultValue = "") String bookmark) {
|
||||
System.out.println("Entro ");
|
||||
try {
|
||||
ResultadoPaginado<RecetaDto> recetas = recetaService
|
||||
.obtenerRecetasPorDniYEstadoPaginado(dni, estados, pageSize, bookmark);
|
||||
|
|
|
|||
|
|
@ -29,12 +29,7 @@ public class VacunaController {
|
|||
|
||||
@PostMapping("/crear")
|
||||
public ResponseEntity<AssetIdDto> crearVacuna(@RequestBody Vacuna vacuna) {
|
||||
System.out.println("\n--> Submit Transaction: CrearVacuna");
|
||||
|
||||
// Log para verificar los valores iniciales
|
||||
System.out.println("Vacuna recibida: " + vacuna);
|
||||
|
||||
// Validación básica
|
||||
|
||||
if (vacuna == null || vacuna.getPatientDocumentNumber() == null || vacuna.getPatientDocumentNumber().isEmpty()) {
|
||||
System.err.println("Datos de vacuna inválidos: faltan campos requeridos.");
|
||||
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
|
||||
|
|
@ -43,16 +38,9 @@ public class VacunaController {
|
|||
String now = LocalDateTime.now().toString();
|
||||
String dni = vacuna.getPatientDocumentNumber();
|
||||
|
||||
// Log para ver el DNI y el timestamp
|
||||
System.out.println("DNI del paciente: " + dni);
|
||||
System.out.println("Timestamp actual: " + now);
|
||||
|
||||
String id = dni + now;
|
||||
String assetId = Hashing.sha256(id);
|
||||
|
||||
// Log para ver el ID generado
|
||||
System.out.println("ID generado para el asset: " + assetId);
|
||||
|
||||
vacuna.setId(assetId);
|
||||
|
||||
AssetIdDto assetIdDto = new AssetIdDto();
|
||||
|
|
@ -60,18 +48,12 @@ public class VacunaController {
|
|||
assetIdDto.setTimeStamp(now);
|
||||
|
||||
try {
|
||||
// Log antes de intentar registrar la vacuna
|
||||
System.out.println("Intentando registrar la vacuna..." + vacuna);
|
||||
|
||||
vacunaService.cargarVacuna(vacuna);
|
||||
|
||||
// Log después de que la vacuna fue registrada
|
||||
System.out.println("Vacuna registrada correctamente.");
|
||||
|
||||
return new ResponseEntity<>(assetIdDto, HttpStatus.OK);
|
||||
} catch (CommitStatusException | EndorseException | CommitException | SubmitException e) {
|
||||
// Log de error
|
||||
System.err.println("Error al registrar la vacuna: " + e.getMessage());
|
||||
|
||||
e.printStackTrace();
|
||||
return new ResponseEntity<>(HttpStatus.UNAUTHORIZED);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue