Update Form HTML output and disable validation auto-configuration

The form-to-HTML output process has been switched from a `<div>` approach to using a `StringBuilder` with a table structure in `ContactFormData.java`. Also, the spring validation auto-configuration has been disabled by adding `exclude = ValidationAutoConfiguration.class` in the `@SpringBootApplication` annotation of `Main.java`. Some changes in `.idea/workspace.xml` and `VerifyController.java` were made as well.
This commit is contained in:
2024-04-28 17:58:43 +02:00
parent 4ec41d8a7e
commit 2f1d24598b
7 changed files with 220 additions and 88 deletions
@@ -37,7 +37,7 @@ public class FormQuery {
}
private Optional<Form> getFormForId(Connection connection, int formId) throws SQLException {
String sql = "SELECT form_json FROM form WHERE formId = ?";
String sql = "SELECT form_json, form_class FROM form WHERE formId = ?";
try (PreparedStatement stmt = connection.prepareStatement(sql)) {
stmt.setInt(1, formId);
@@ -10,6 +10,13 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CompletableFuture;
@RestController
@@ -23,6 +30,27 @@ public class VerifyController {
logger.debug(verificationData.toString());
return new FormQuery().getFormForCode(verificationData.code, verificationData.eMail).thenApply(result -> result.form()
.map(form -> {
try {
HttpRequest request = HttpRequest.newBuilder()
.uri(new URI("http://51.222.255.92:8001/api/contact/submitContactForm"))//TODO get uri from form
.header("Content-Type", "application/json;charset=UTF-8")
.POST(HttpRequest.BodyPublishers.ofString(form.toJsonString(), StandardCharsets.UTF_8))
.build();
HttpClient client = HttpClient.newHttpClient();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
if (response.statusCode() < 200 || response.statusCode() > 200) {
logger.error(String.format("Failed to send form to Discord. Got status code [%d], with body\n%s", response.statusCode(), response.body()));
//TODO handle failure
//TODO strings to config
return ResponseEntity.ok("Failed to send form to Discord, please contact us at [email protected]");
}
} catch (URISyntaxException e) {
logger.error("Unable to create URI for posting form", e); //TODO more clear
return ResponseEntity.ok("Unable to create URI for posting form, please contact us at [email protected]");
} catch (IOException | InterruptedException e) {
logger.error("Unable to send form to Discord", e); //TODO more clear
return ResponseEntity.ok("Unable to send form to Discord, please contact us at [email protected]");
}
MailForm.sendForm("[email protected]", form);
return ResponseEntity.ok(form.toJsonString());
})