From b18be0a498e81db1359fd0826c6685f0e1619eca Mon Sep 17 00:00:00 2001 From: hajekad3 Date: Wed, 4 Jan 2023 23:44:04 +0100 Subject: [PATCH] front end is done --- frontEnd/trainee.html | 8 ++--- frontEnd/trainee.js | 31 +++++++++++++++++-- frontEnd/training.js | 23 ++++++++++++-- .../Api/Controllers/TraineeController.java | 2 +- 4 files changed, 54 insertions(+), 10 deletions(-) diff --git a/frontEnd/trainee.html b/frontEnd/trainee.html index 050ed0f..24428e3 100644 --- a/frontEnd/trainee.html +++ b/frontEnd/trainee.html @@ -24,7 +24,7 @@

Find Match





-
+



@@ -46,7 +46,7 @@

Assign training




-
+



@@ -58,9 +58,9 @@

Assign training



-
+

-
+

diff --git a/frontEnd/trainee.js b/frontEnd/trainee.js index 66371fa..a04edb3 100644 --- a/frontEnd/trainee.js +++ b/frontEnd/trainee.js @@ -23,7 +23,7 @@ async function findMatch() { try { const response = await fetch(`http://localhost:6060/trainee/bussiness?range=${range}`, { - method: 'GET', + method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(traineeDto) }); @@ -52,9 +52,14 @@ async function assignTraining() { 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 fromDL = document.getElementById('from-assign-training').value; + const toDL = document.getElementById('to-assign-training').value; + + const from = convertDatetimeLocal(fromDL); + const to = convertDatetimeLocal(toDL); + console.log(`${fromDL} -> ${from}\n${toDL} -> ${to}`); + const traineeDto = { id: id, username: username, @@ -141,6 +146,26 @@ async function updateTrainee() { update(traineeDto, '/trainee'); } +function convertDatetimeLocal(input) { + const timestamp = Date.parse(input); + + if (isNaN(timestamp)) { + return 'Invalid Date'; + } + + const date = new Date(timestamp); + + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + + const hour = String(date.getHours()).padStart(2, '0'); + const minute = String(date.getMinutes()).padStart(2, '0'); + + return `${year}-${month}-${day} ${hour}:${minute}:00`; +} + + function addInput() { const inputContainer = document.getElementById('input-container'); const input = document.createElement('input'); diff --git a/frontEnd/training.js b/frontEnd/training.js index dc04463..b5444cc 100644 --- a/frontEnd/training.js +++ b/frontEnd/training.js @@ -6,7 +6,7 @@ async function trainingGet() { async function createTraining() { const idCoach = document.getElementById('id-coach-post').value; const idPlace = document.getElementById('id-place-post').value; - const dateOfTraining = document.getElementById('date-of-training-post').value; + const dateOfTraining = convertDatetimeLocal(document.getElementById('date-of-training-post').value); const description = document.getElementById('description-post').value; const createTrainingDto = { @@ -28,7 +28,7 @@ async function updateTraining() { const id = document.getElementById('id-update').value; const idCoach = document.getElementById('id-coach-update').value; const idPlace = document.getElementById('id-place-update').value; - const dateOfTraining = document.getElementById('date-of-training-update').value; + const dateOfTraining = convertDatetimeLocal(document.getElementById('date-of-training-update').value); const description = document.getElementById('description-update').value; const inputs = document.querySelectorAll('.traineesInput'); const participatingTraineesIds = Array.from(inputs).map(input => Number(input.value)); @@ -130,4 +130,23 @@ async function update(dto, at) { console.error("Error: one of the ids does not exist."); document.getElementById('responseUpdate').value = "Error: one of the ids does not exist."; } +} + +function convertDatetimeLocal(input) { + const timestamp = Date.parse(input); + + if (isNaN(timestamp)) { + return 'Invalid Date'; + } + + const date = new Date(timestamp); + + const year = date.getFullYear(); + const month = String(date.getMonth() + 1).padStart(2, '0'); + const day = String(date.getDate()).padStart(2, '0'); + + const hour = String(date.getHours()).padStart(2, '0'); + const minute = String(date.getMinutes()).padStart(2, '0'); + + return `${year}-${month}-${day} ${hour}:${minute}:00`; } \ No newline at end of file diff --git a/reservantor/src/main/java/cz/cvut/fit/hajekad3/reservantor/Api/Controllers/TraineeController.java b/reservantor/src/main/java/cz/cvut/fit/hajekad3/reservantor/Api/Controllers/TraineeController.java index ab7f9ac..c3555df 100644 --- a/reservantor/src/main/java/cz/cvut/fit/hajekad3/reservantor/Api/Controllers/TraineeController.java +++ b/reservantor/src/main/java/cz/cvut/fit/hajekad3/reservantor/Api/Controllers/TraineeController.java @@ -38,7 +38,7 @@ public ResponseEntity getTrainingInTimeFrame(@RequestParam String from, @Request return ResponseEntity.ok().body(ret); } - @GetMapping("/bussiness") + @PostMapping("/bussiness") public ResponseEntity findMatch(@RequestParam int range, @RequestBody TraineeDto challenger) { TraineeDto ret;