Changed process time to backend.

This commit is contained in:
2023-03-08 12:03:46 +01:00
parent 61c4bb8e08
commit 7ee77cd126
2 changed files with 46 additions and 30 deletions

View File

@@ -24,35 +24,53 @@ public class JsonController implements RestController {
@ScopedControllerManifest(method = HandlerType.POST, path = "/formatting")
public void formatting(Request request, Response response) {
long startProcess = System.currentTimeMillis();
JsonObject responseJson = new JsonObject();
try {
JsonObject jsonObject = this.gson.fromJson(request.body(), JsonObject.class);
JsonObject requestJson = this.gson.fromJson(request.body(), JsonObject.class);
response.status(200);
response.body(this.prettyGson.toJson(jsonObject));
responseJson.addProperty("data", this.prettyGson.toJson(requestJson));
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.prettyGson.toJson(responseJson));
} catch (Exception e) {
response.status(500);
Throwable cause = e.getCause();
if (cause == null) {
response.body(e.getMessage());
} else {
response.body(cause.getMessage());
}
response.status(500);
responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage());
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.prettyGson.toJson(responseJson));
}
}
@ScopedControllerManifest(method = HandlerType.POST, path = "/minimize")
public void minimize(Request request, Response response) {
long startProcess = System.currentTimeMillis();
JsonObject responseJson = new JsonObject();
try {
JsonObject jsonObject = this.prettyGson.fromJson(request.body(), JsonObject.class);
JsonObject requestJson = this.prettyGson.fromJson(request.body(), JsonObject.class);
response.status(200);
response.body(this.gson.toJson(jsonObject));
responseJson.addProperty("data", this.gson.toJson(requestJson));
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.gson.toJson(responseJson));
} catch (Exception e) {
response.status(500);
Throwable cause = e.getCause();
if (cause == null) {
response.body(e.getMessage());
} else {
response.body(cause.getMessage());
}
response.status(500);
responseJson.addProperty("data", cause == null ? e.getMessage() : cause.getMessage());
responseJson.addProperty("time", System.currentTimeMillis() - startProcess);
response.body(this.prettyGson.toJson(responseJson));
}
}
}