diff --git a/src/main/webapp/js/requests.js b/src/main/webapp/js/requests.js index 9f11ad9018d236b068862c4a5a9f46ee1ddd377b..2e2177632e292c5668a4cc339ba56b843f1d1c3e 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 c806ed21708f81f783de699ad7b8f0957c45c93b..764dc874a3c981ee40e5b6a8fb5cc3f77e64fbdb 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