Я пытаюсь загрузить gzip-файл (хранящийся как тип bytea) из базы данных PostgreSQL с помощью контроллера начальной загрузки , но мне также нужно вернуть объект json для описания состояния, сообщения и некоторой информации о запросе кклиент
например:
{ "success" : true, "status" : "APPROVED" "message" : "Your request <id> has been successfully approved" }
это мой контроллер:
@GetMapping("/enroll/{id}")
@Timed
public ResponseEntity<?> getEnrollById(@PathVariable String id) {
if (condition1) {
Request request = requestRepository.findByrequestId(id);
ResponseDetails responseDetails = new ResponseDetails();
if (condition2) {
responseDetails.setSuccess(true);
if (request.getStatus().equals("status1")) {
responseDetails.setStatus("status1");
responseDetails.setMessage(
"Please wait, your the request " + id + " needs to be approved by an administrator");
} else if (request.getStatus().equals("status2")) {
responseDetails.setStatus("status2");
responseDetails.setMessage("Your request " + id + " has been status2");
} else {
responseDetails.setStatus(request.getStatus().toUpperCase());
responseDetails.setMessage("Your request" + id + "has been successfully approved");
}
String contentType = null ;
if(contentType == null) {
contentType = "application/octet-stream";
}
return ResponseEntity.ok()
.contentType(MediaType.parseMediaType(contentType))
.header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"enrollment_" + request.getRequestId() + "\".gz")
.body(request.getMsp()); // ==> msp type : byte[]
**//i want to return my json object + gz file here**
} else {
responseDetails.setSuccess(false);
responseDetails.setCode("ENROLLMENT_REQUEST_NOT_FOUND");
responseDetails.setMessage("The enrollment request " + id + " doesn't exist");
return new ResponseEntity<ResponseDetails>(responseDetails, HttpStatus.NOT_FOUND);
}
} else {
return new ResponseEntity<ResponseDetails>(new ResponseDetails(false, "USER_INVALID_PARAMS", null,
"Invalid enrollment request params request_id", null, null, null), HttpStatus.BAD_REQUEST);
}
}
Спасибо, что ответили мне :)