Skip to content

Commit

Permalink
all bussiness operations and complex querries are implemented on
Browse files Browse the repository at this point in the history
frontend
  • Loading branch information
hajekad3 committed Jan 4, 2023
1 parent 151705e commit 1297d48
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 52 deletions.
9 changes: 0 additions & 9 deletions frontEnd/coach.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ async function updateCoach() {
update(coachDto, '/coach');
}


function addInput() {
const inputContainer = document.getElementById('input-container');
const input = document.createElement('input');
Expand All @@ -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}`);
Expand Down
24 changes: 1 addition & 23 deletions frontEnd/place.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,36 +36,14 @@ async function updatePlace() {

update(placeDto, '/place');
}



function addInput() {
const inputContainer = document.getElementById('input-container');
const input = document.createElement('input');
input.type = 'number';
input.className = 'trainingInput';
inputContainer.appendChild(input);
}






















async function get(id, at) {
try {
Expand Down
48 changes: 48 additions & 0 deletions frontEnd/trainee.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,54 @@ <h1> Trainee </h1>
</header>
<main>

<section id="findMatch">
<h2>Find Match</h2>
<form>
<label for="range-find-match">Range:</label><br>
<input type="number" id="range-find-match"><br><br>
<label for="username-find-match">Username:</label><br>
<input type="number" id="username-find-match"><br>
<label for="password-find-match">Password:</label><br>
<input type="password" id="password-find-match"><br>
<label for="email-find-match">Email:</label><br>
<input type="email" id="email-find-match"><br>
<label for="first-name-find-match">First Name:</label><br>
<input type="text" id="first-name-find-match"><br>
<label for="second-name-find-match">Second Name:</label><br>
<input type="text" id="second-name-find-match"><br>
<label for="skill-cap-find-match">Skill Cap:</label><br>
<input type="number" id="skill-cap-find-match"><br>
<button type="button" onclick="findMatch()">Find Match</button>
</form>
<textarea id="responseFindMatch" rows="10" cols="50"></textarea>
</section>

<section id="assignTraining">
<h2>Assign training</h2>
<form>
<label for="username-assign-training">Username:</label><br>
<input type="number" id="username-assign-training"><br>
<label for="password-assign-training">Password:</label><br>
<input type="password" id="password-assign-training"><br>
<label for="email-assign-training">Email:</label><br>
<input type="email" id="email-assign-training"><br>
<label for="first-name-assign-training">First Name:</label><br>
<input type="text" id="first-name-assign-training"><br>
<label for="second-name-assign-training">Second Name:</label><br>
<input type="text" id="second-name-assign-training"><br>
<label for="skill-cap-assign-training">Skill Cap:</label><br>
<input type="number" id="skill-cap-assign-training"><br>

<label for="from-assign-training">Second Name:</label><br>
<input type="datetime-local" id="from-assign-training"><br>
<label for="to-assign-training">Skill Cap:</label><br>
<input type="datetime-local" id="to-assign-training"><br>

<button type="button" onclick="assignTraining()">Create Trainee</button>
</form>
<textarea id="responseAssignTraining" rows="10" cols="50"></textarea>
</section>

<section id="getRequest">
<h2>Get</h2>
<label for="id-get">ID:</label>
Expand Down
94 changes: 88 additions & 6 deletions frontEnd/trainee.js
Original file line number Diff line number Diff line change
@@ -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');
Expand Down Expand Up @@ -53,7 +141,6 @@ async function updateTrainee() {
update(traineeDto, '/trainee');
}


function addInput() {
const inputContainer = document.getElementById('input-container');
const input = document.createElement('input');
Expand All @@ -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}`);
Expand Down
14 changes: 0 additions & 14 deletions frontEnd/training.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ async function updateTraining() {
update(trainingDto, '/training');
}


function addInput() {
const inputContainer = document.getElementById('input-container');
const input = document.createElement('input');
Expand All @@ -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}`);
Expand Down

0 comments on commit 1297d48

Please sign in to comment.