From 1297d482021db866e29f93dd493b5fe8dbcb54c7 Mon Sep 17 00:00:00 2001 From: hajekad3 Date: Wed, 4 Jan 2023 07:27:32 +0100 Subject: [PATCH] all bussiness operations and complex querries are implemented on frontend --- frontEnd/coach.js | 9 ----- frontEnd/place.js | 24 +---------- frontEnd/trainee.html | 48 ++++++++++++++++++++++ frontEnd/trainee.js | 94 ++++++++++++++++++++++++++++++++++++++++--- frontEnd/training.js | 14 ------- 5 files changed, 137 insertions(+), 52 deletions(-) diff --git a/frontEnd/coach.js b/frontEnd/coach.js index 91d3628..29cc275 100644 --- a/frontEnd/coach.js +++ b/frontEnd/coach.js @@ -75,7 +75,6 @@ async function updateCoach() { update(coachDto, '/coach'); } - function addInput() { const inputContainer = document.getElementById('input-container'); const input = document.createElement('input'); @@ -84,14 +83,6 @@ function addInput() { inputContainer.appendChild(input); } - - - - - - - - async function get(id, at) { try { const response = await fetch(`http://localhost:6060` + at + `?id=${id}`); diff --git a/frontEnd/place.js b/frontEnd/place.js index 91ae6a3..8d5a45a 100644 --- a/frontEnd/place.js +++ b/frontEnd/place.js @@ -36,8 +36,7 @@ async function updatePlace() { update(placeDto, '/place'); } - - + function addInput() { const inputContainer = document.getElementById('input-container'); const input = document.createElement('input'); @@ -45,27 +44,6 @@ function addInput() { input.className = 'trainingInput'; inputContainer.appendChild(input); } - - - - - - - - - - - - - - - - - - - - - async function get(id, at) { try { diff --git a/frontEnd/trainee.html b/frontEnd/trainee.html index 17730c0..b897b0d 100644 --- a/frontEnd/trainee.html +++ b/frontEnd/trainee.html @@ -16,6 +16,54 @@

Trainee

+
+

Find Match

+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+ +
+ +
+ +
+

Assign training

+
+
+
+
+
+
+
+
+
+
+
+
+
+ +
+
+
+
+ + +
+ +
+

Get

diff --git a/frontEnd/trainee.js b/frontEnd/trainee.js index 185b051..66371fa 100644 --- a/frontEnd/trainee.js +++ b/frontEnd/trainee.js @@ -1,3 +1,91 @@ +async function findMatch() { + const range = document.getElementById('range-find-match').value; + const id = document.getElementById('id-find-match').value; + const username = document.getElementById('username-find-match').value; + const password = document.getElementById('password-find-match').value; + const email = document.getElementById('email-find-match').value; + const firstName = document.getElementById('first-name-find-match').value; + const secondName = document.getElementById('second-name-find-match').value; + const skillCap = document.getElementById('skill-cap-find-match').value; + const inputs = document.querySelectorAll('.trainingInputFindMatch'); + const trainings = Array.from(inputs).map(input => Number(input.value)); + + const traineeDto = { + id: id, + username: username, + password: password, + email: email, + firstName: firstName, + secondName: secondName, + skillCap: skillCap, + trainings: trainings + }; + + try { + const response = await fetch(`http://localhost:6060/trainee/bussiness?range=${range}`, { + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(traineeDto) + }); + if (response.ok) { + const responseJson = await response.json(); + console.log("JSON:\n" + JSON.stringify(responseJson, null, 2)); + document.getElementById('responseFindMatch').value = JSON.stringify(responseJson, null, 2); + } else { + console.error(`Error: ${response.status} ${response.statusText}`); + document.getElementById('responseFindMatch').value = `Error: ${response.status} ${response.statusText}`; + } + } catch (error) { + console.error(error); + document.getElementById('responseFindMatch').value = error.toString(); + } +} + +async function assignTraining() { + const id = document.getElementById('id-assign-training').value; + const username = document.getElementById('username-assign-training').value; + const password = document.getElementById('password-assign-training').value; + const email = document.getElementById('email-assign-training').value; + const firstName = document.getElementById('first-name-assign-training').value; + const secondName = document.getElementById('second-name-assign-training').value; + const skillCap = document.getElementById('skill-cap-assign-training').value; + const inputs = document.querySelectorAll('.trainingInputAssignTraining'); + const trainings = Array.from(inputs).map(input => Number(input.value)); + + const from = document.getElementById('from-assign-training').value; + const to = document.getElementById('to-assign-training').value; + + const traineeDto = { + id: id, + username: username, + password: password, + email: email, + firstName: firstName, + secondName: secondName, + skillCap: skillCap, + trainings: trainings + }; + + try { + const response = await fetch(`http://localhost:6060/trainee/bussiness?from=${from}&to=${to}`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify(traineeDto) + }); + if (response.ok) { + const responseJson = await response.json(); + console.log("JSON:\n" + JSON.stringify(responseJson, null, 2)); + document.getElementById('responseAssignTraining').value = JSON.stringify(responseJson, null, 2); + } else { + console.error(`Error: ${response.status} ${response.statusText}`); + document.getElementById('responseAssignTraining').value = `Error: ${response.status} ${response.statusText}`; + } + } catch (error) { + console.error("Error: one of the ids does not exist."); + document.getElementById('responseAssignTraining').value = "Error: one of the ids does not exist."; + } +} + async function traineeGet() { const id = document.getElementById('id-get').value; get(id, '/trainee'); @@ -53,7 +141,6 @@ async function updateTrainee() { update(traineeDto, '/trainee'); } - function addInput() { const inputContainer = document.getElementById('input-container'); const input = document.createElement('input'); @@ -62,11 +149,6 @@ function addInput() { inputContainer.appendChild(input); } - - - - - async function get(id, at) { try { const response = await fetch(`http://localhost:6060` + at + `?id=${id}`); diff --git a/frontEnd/training.js b/frontEnd/training.js index dcfea3f..dc04463 100644 --- a/frontEnd/training.js +++ b/frontEnd/training.js @@ -45,7 +45,6 @@ async function updateTraining() { update(trainingDto, '/training'); } - function addInput() { const inputContainer = document.getElementById('input-container'); const input = document.createElement('input'); @@ -54,19 +53,6 @@ function addInput() { inputContainer.appendChild(input); } - - - - - - - - - - - - - async function get(id, at) { try { const response = await fetch(`http://localhost:6060` + at + `?id=${id}`);