From 095e59810744742c60989834de1ce5ea3af04005 Mon Sep 17 00:00:00 2001 From: s3190285 <m.ruginosu@student.utwente.nl> Date: Tue, 7 May 2024 16:41:23 +0200 Subject: [PATCH] issue 2 --- src/main/webapp/js/requests.js | 16 ++++++++++++++++ src/main/webapp/trainers.html | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/src/main/webapp/js/requests.js b/src/main/webapp/js/requests.js index 9f11ad9..2e21776 100644 --- a/src/main/webapp/js/requests.js +++ b/src/main/webapp/js/requests.js @@ -60,4 +60,20 @@ function createPokemonTypesTable() { </tbody> </table> ` +} + +function createTrainer() { + const name = document.getElementById('trainerName').value; + const profileurl = document.getElementById('profileUrl').value; + const data = { + profileUrl: profileurl, + name: name + } + fetch('/pokemon/api/trainers', { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify(data) + }).then(response => updateTrainerTable()) } \ No newline at end of file diff --git a/src/main/webapp/trainers.html b/src/main/webapp/trainers.html index c806ed2..764dc87 100644 --- a/src/main/webapp/trainers.html +++ b/src/main/webapp/trainers.html @@ -40,5 +40,17 @@ </div> </div> +<form id="createTrainerForm" onsubmit = "createTrainer();"> + <div class = "form-group"> + <label for = "trainerName">Name</label> + <input type = "text" class = "form-control" id = "trainerName" required> + </div> + <div class = "form-group"> + <label for = "profileUrl">Profile Url</label> + <input type = "text" class = "form-control" id = "profileUrl" required> + </div> + <button type = "submit" class = "btn btn-primary">Create Trainer</button> +</form> + </body> </html> \ No newline at end of file -- GitLab