[rest] VoiceResource: Return answer from /interpreters endpoint & Add annotations for answer

Signed-off-by: Florian Hotze <dev@florianhotze.com>
This commit is contained in:
Florian Hotze 2024-10-30 18:21:46 +01:00 committed by Wouter Born
parent 728c7376b6
commit 9646607e47

View File

@ -139,8 +139,9 @@ public class VoiceResource implements RESTResource {
@POST
@Path("/interpreters/{ids: [a-zA-Z_0-9,]+}")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Operation(operationId = "interpretText", summary = "Sends a text to a given human language interpreter(s).", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "404", description = "No human language interpreter was found."),
@ApiResponse(responseCode = "400", description = "interpretation exception occurs") })
public Response interpret(
@ -175,8 +176,9 @@ public class VoiceResource implements RESTResource {
@POST
@Path("/interpreters")
@Consumes(MediaType.TEXT_PLAIN)
@Produces(MediaType.TEXT_PLAIN)
@Operation(operationId = "interpretTextByDefaultInterpreter", summary = "Sends a text to the default human language interpreter.", responses = {
@ApiResponse(responseCode = "200", description = "OK"),
@ApiResponse(responseCode = "200", description = "OK", content = @Content(schema = @Schema(implementation = String.class))),
@ApiResponse(responseCode = "404", description = "No human language interpreter was found."),
@ApiResponse(responseCode = "400", description = "interpretation exception occurs") })
public Response interpret(
@ -189,8 +191,8 @@ public class VoiceResource implements RESTResource {
}
try {
hli.interpret(locale, text);
return Response.ok(null, MediaType.TEXT_PLAIN).build();
String answer = hli.interpret(locale, text);
return Response.ok(answer, MediaType.TEXT_PLAIN).build();
} catch (InterpretationException e) {
return JSONResponse.createErrorResponse(Status.BAD_REQUEST, e.getMessage());
}