From b4c71af857545c31b3bbca94e78aafb78dddb745 Mon Sep 17 00:00:00 2001 From: brausjonas Date: Fri, 26 May 2023 02:10:15 +0200 Subject: [PATCH] Calender View Sync Prototype Working Correctly --- anwendung/src/components/CalenderView.jsx | 847 +++--- anwendung/src/components/DateElement.jsx | 14 +- anwendung/src/components/WeekSelector.jsx | 10 +- anwendung/src/pages/planning.js | 6 +- anwendung/src/styles/globals.css | 6 +- backend/database.mv.db | Bin 45056 -> 45056 bytes backend/database.trace.db | 2644 +++++++++++++++++ .../backend/anwprj/DataBaseHandler.java | 17 +- .../anwprj/controller/EntriesController.java | 56 +- 9 files changed, 3068 insertions(+), 532 deletions(-) diff --git a/anwendung/src/components/CalenderView.jsx b/anwendung/src/components/CalenderView.jsx index cb29989..26ce533 100644 --- a/anwendung/src/components/CalenderView.jsx +++ b/anwendung/src/components/CalenderView.jsx @@ -1,49 +1,32 @@ import {useEffect, useState} from "react"; import Button from "@/components/Button"; import {list} from "postcss"; +import Background from "@/components/Background"; +import WeekSelector from "@/components/WeekSelector"; -// //all entries of the current week -// let entries = {mo: [], tu: [], we: [], th: [], fr: [], sa: []} -// //a variable that saves the currently grabbed resize bar -// let grabbed = null; -// let grabbedUp = false; -// let grabbed_in_list = null; -// -// //a variable the saves if the mouse is pressed or not -// let mouseDown = false; -// -// //a variable that stores the currently grabbed element to move -// let selectedElement = null; -// //move offset from top row to cursor -// let selectedOffsetTop = 0; -// //move offset from bottom row to cursor -// let selectedOffsetBottom = 0; -// //the list, the grabbed element to move is currently in -// let selectedListID = ""; - -//variable for the hight of one cell / row. Important for resizing the calender view -let cellHeight = 25; +let cellHeight = 20; let colors = ["#f80000", "#414141"] let semesterStart; let currentWeekStartDay; let currentYear; +let selectedElement; export default function CalenderView(p) { const [entries, setEntries] = useState([[], [], [], [], [], []]) + const [update, setUpdate] = useState(false) function readEntries() { let url = "http://localhost:8080/entries?semesterid=" + localStorage.getItem("currentsid") + - "&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear; + "&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear + "&sessionid=" + localStorage.getItem("sessionid"); console.log(currentWeekStartDay) fetch(url).then(r => r.json()).then(en => setEntries(en)) } - function pushEntry(currentColumnID, row) - { - let url = "http://localhost:8080/entries" + function pushEntry(currentColumnID, row) { + let url = "http://localhost:8080/entries" + "?sessionid=" + localStorage.getItem("sessionid") let json = { "id": 0, "daynumber": currentWeekStartDay + currentColumnID, @@ -58,17 +41,89 @@ export default function CalenderView(p) { method: "POST", headers: {"Content-Type": "application/json"}, body: JSON.stringify(json) - }).then(r => {readEntries()}) + }).then(r => { + readEntries() + }) } - function deleteEntry(id) - { - let url = "http://localhost:8080/entries?id=" + id; + function deleteEntry(id) { + let url = "http://localhost:8080/entries?id=" + id + "&sessionid=" + localStorage.getItem("sessionid"); fetch(url, { method: "DELETE" }).then(r => readEntries()) } + function checkForElementAtRow(row, column) { + let currentList = entries[column]; + for (let i = 0; i < currentList.length; i++) { + if (currentList[i] != null) { + if (row >= currentList[i].timestart && row <= currentList[i].timeend) { + + + return true; + + } + } + } + + return false; + } + + function getElementInColumn(id, column) { + let currentList = entries[column]; + for (let i = 0; i < currentList.length; i++) { + if (currentList[i] != null) { + if (currentList[i].id === id) { + return currentList[i]; + } + } + } + + return null; + } + + function onMouseUp(e) { + if (selectedElement != null) { + let id = selectedElement.id; + + let url = "http://localhost:8080/entries?sessionid=" + localStorage.getItem("sessionid"); + let json = { + "id": id, + "daynumber": 0, + "yearnumber": 0, + "semesterid": 0, + "usercreatedbyid": 0, + "timestart": 0, + "timeend": selectedElement.timeend, + "info": "" + } + fetch(url, { + method: "PUT", + headers: {"Content-Type": "application/json"}, + body: JSON.stringify(json) + }).then(r => { + readEntries() + }) + + selectedElement = null; + } + } + + function onMouseMove(e) { + if (selectedElement != null) { + let y_window = e.clientY; + let y_target_offset = e.currentTarget.getBoundingClientRect().top; + let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1; + let currentColumnID = parseInt(e.currentTarget.id) + + if (selectedElement.timestart < row - 1) { + selectedElement.timeend = row + 1; + } + + setUpdate(!update); + } + } + function onMouseDown(e) { let y_window = e.clientY; let y_target_offset = e.currentTarget.getBoundingClientRect().top; @@ -76,24 +131,40 @@ export default function CalenderView(p) { let currentColumnID = parseInt(e.currentTarget.id) let currentId = e.target.id; - if(e.button === 0) - { - pushEntry(currentColumnID, row) - } - else if(e.button === 2) - { - if(currentId.includes("e")) - { + if (e.button === 0) { + if (!currentId.includes("e")) { + if (!currentId.includes("grab")) { + if (!checkForElementAtRow(row + 2, currentColumnID)) { + pushEntry(currentColumnID, row) + } + } else { + let parentID = parseInt(e.target.parentElement.id.replace("e", "")); + selectedElement = getElementInColumn(parentID, currentColumnID); + } + } + } else if (e.button === 2) { + if (currentId.includes("e")) { let id = parseInt(currentId.replace("e", "")) deleteEntry(id) } } } + function onWeekLeft() { + currentWeekStartDay -= 7; + readEntries() + } + + function onWeekRight() { + currentWeekStartDay += 7; + readEntries() + } + useEffect(() => { semesterStart = 0; currentWeekStartDay = 0; currentYear = 2000; + selectedElement = null; let url = "http://localhost:8080/semester/id?sessionid=" + localStorage.getItem("sessionid") + "&id=" + localStorage.getItem("currentsid"); @@ -107,266 +178,6 @@ export default function CalenderView(p) { window.addEventListener("contextmenu", (e) => (e.preventDefault())) }, []) - // function does_element_overlap(entry, start, end, search_list) - // { - // let current = null; - // for(let i = 0; i < search_list.length; i++) - // { - // current = search_list[i]; - // if(current !== entry) - // { - // if (start > current.timestart && start < current.timeend) - // { - // return true; - // } else if (end > current.timestart && end < current.timeend) - // { - // return true; - // } else if (start <= current.timestart && end >= current.timeend) - // { - // return true; - // } - // } - // } - // - // return false; - // } - - //function to delete an elemente and resize the corresponding list in the entries dictionary - // function delete_element(index, element) - // { - // let currentList = entries[index]; - // let temp = [] - // for (let i = 0; i < currentList.length; i++) - // { - // if (element !== currentList[i]) - // { - // temp.push(currentList[i]); - // } - // } - // entries[index] = temp; - // } - - //resize a grabbed element to the row paramter - // function size_grabbed(row, current_list) - // { - // if (row >= 0 && row <= 96) - // { - // if (grabbedUp) - // { - // console.log(grabbed.timestart) - // - // if (row < grabbed.timeend - 1) - // { - // if(!does_element_overlap(grabbed, row, grabbed.timeend, current_list)) - // { - // grabbed.timestart = row; - // } - // } - // } else - // { - // if (row > grabbed.timestart) - // { - // if(!does_element_overlap(grabbed, grabbed.timestart, row + 1, current_list)) - // { - // grabbed.timeend = row + 1; - // } - // } - // } - // } - // } - - - //moves the selected element to row and list with id - // function move_selected(row, id) - // { - // if (selectedListID !== id) - // { - // if(!does_element_overlap(selectedElement, row - selectedOffsetTop, row + selectedOffsetBottom, entries[id])) - // { - // delete_element(selectedListID, selectedElement); - // entries[id].push(selectedElement); - // selectedListID = id; - // } - // } - // - // if (row - selectedOffsetTop > 0 && row + selectedOffsetBottom <= 97) - // { - // if(!does_element_overlap(selectedElement, row - selectedOffsetTop, row + selectedOffsetBottom, entries[id])) - // { - // selectedElement.timestart = row - selectedOffsetTop; - // selectedElement.timeend = row + selectedOffsetBottom; - // } - // } - // } - - //routine, when mouse is moved - // function mouse_move(e) - // { - // //checks if mouse is still down - // if (mouseDown) - // { - // //get the y coordinate of the cursor - // let y_window = e.clientY; - // //get the offset to the calender view - // let y_target_offset = e.currentTarget.getBoundingClientRect().top; - // //get the id of the current column - // let id = e.currentTarget.id; - // //calcultes the current row the cursor hovers - // let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1 - // let current_list = entries[e.currentTarget.id]; - // - // //if a edge of an element was grabbed, resize it - // if (grabbed != null) - // { - // size_grabbed(row, grabbed_in_list); - // //if a whole element was grabbed, move it - // } else if (selectedElement != null) - // { - // move_selected(row, id); - // } - // } - // - // //update the calender view - // setT(!t); - // } - - //routine when mouse was released - // function mouse_up(e) - // { - // mouseDown = false; - // - // //remove all selected elements - // if (grabbed != null) - // { - // grabbed.colorID = 0; - // grabbed = null; - // } - // if (selectedElement != null) - // { - // selectedElement.colorID = 0; - // selectedElement = null; - // } - // - // setT(!t); - // } - - - //places a new entry to the calender - // function place_new_entry(row, list) - // { - // if (row < 96) - // { - // let free = true; - // for (let i = 0; i < list.length; i++) - // { - // let current = list[i]; - // - // for (let r = row; r < row + 3; r++) - // { - // for (let s = current.timestart; s < current.timeend; s++) - // { - // if (s === r) - // { - // free = false; - // break; - // } - // } - // } - // } - // - // if (free) - // { - // list.push(new CalenderEntry(row, row + 3)); - // setT(!t); - // } - // } - // } - - //routine when mouse was pressed - // function mouse_down(e) - // { - // - // //get the cursors y coordinate in the window - // let y_window = e.clientY; - // //get the offset of the calender view - // let y_target_offset = e.currentTarget.getBoundingClientRect().top; - // //calculate the row clicked on - // let row = Math.floor((y_window - y_target_offset) / cellHeight) + 1; - // //get the list of entries clicked on - // let current_list = entries[e.currentTarget.id]; - // - // //if right clicked - // if (e.button === 2) - // { - // //if right clicked on an element / entry delete it - // let current = find_current(row, current_list); - // - // if (current != null) - // { - // delete_element(e.currentTarget.id, current); - // } - // - // } - // else - // { - // mouseDown = true; - // - // //if a resize bar was grabbed - // if (e.target.id === "grab") - // { - // //get the entry the resize bar is child of - // let entry = e.target.parentElement; - // //get the startRow of the entry - // let rowStart = parseInt(window.getComputedStyle(entry).gridRowStart); - // - // grabbed_in_list = current_list; - // - // //check if the upper or lower resize bar was grabbed - // if (row === rowStart) - // { - // //+ / - 1 to avoid select the wrong element when overlapping - // grabbed = find_current(row + 1, current_list); - // grabbedUp = true; - // } else - // { - // grabbed = find_current(row - 1, current_list); - // grabbedUp = false; - // } - // - // grabbed.colorID = 1; - // - // setT(!t); - // } - // //if a whole element was clicked to move - // else if (e.target.id === "entry") - // { - // let rowStart = parseInt(window.getComputedStyle(e.target).gridRowStart); - // - // selectedListID = e.currentTarget.id; - // - // if(rowStart === row) - // { - // selectedElement = find_current(row + 1, current_list); - // } - // else - // { - // selectedElement = find_current(row, current_list); - // } - // - // selectedElement.colorID = 1; - // - // setT(!t); - // - // selectedOffsetTop = row - parseInt(window.getComputedStyle(e.target).gridRowStart); - // selectedOffsetBottom = parseInt(window.getComputedStyle(e.target).gridRowEnd) - row; - // } - // //single click places a new entry - // else - // { - // place_new_entry(row, current_list) - // } - // } - // } //returns internal format (0 - 96) to a string function internal_to_time(internal) { @@ -387,219 +198,247 @@ export default function CalenderView(p) { return ( -
+
+ onWeekLeft()} + onFunctionRight={() => onWeekRight()}/> +
- -
-
-
-
Montag
-
Dienstag
-
Mittwoch
-
Donnerstag
-
Freitag
-
Samstag
-
-
-
- -
- - -
onMouseDown(e)}> - - {entries[0].map(d => (d != null &&
-
-
-

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

-

Moduel etc.

-

Mehr Infos

-

Raum

-
-
-
))} -
- - -
onMouseDown(e)}> - - {entries[1].map(d => (d != null &&
- -
-
-

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

-

Moduel etc.

-

Mehr Infos

-

Raum

-
-
-
))} -
- - -
onMouseDown(e)}> - - - {entries[2].map(d => (d != null &&
- -
-
-

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

-

Moduel etc.

-

Mehr Infos

-

Raum

-
-
-
))} -
- - -
onMouseDown(e)}> - - {entries[3].map(d => (d != null &&
- -
-
-

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

-

Moduel etc.

-

Mehr Infos

-

Raum

-
-
-
))} -
- - -
onMouseDown(e)}> - - - {entries[4].map(d => (d != null &&
-
-
-

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

-

Moduel etc.

-

Mehr Infos

-

Raum

-
-
-
))} -
- - -
onMouseDown(e)}> - - - {entries[5].map(d => (d != null &&
-
-
-

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

-

Moduel etc.

-

Mehr Infos

-

Raum

-
-
-
))} +
+
+
+
Montag
+
Dienstag
+
Mittwoch
+
Donnerstag
+
Freitag
+
Samstag
+
+ +
-
- {/*maps a list of internal time stamps to lines and time stamps*/} - {temp.map(i => (
+
onMouseDown(e)} + onMouseMove={e => onMouseMove(e)} + onMouseUp={e => onMouseUp(e)}> -

{internal_to_time(i + 1)}

-

{internal_to_time(i + 1)}

-

{internal_to_time(i + 1)}

-

{internal_to_time(i + 1)}

-

{internal_to_time(i + 1)}

-

{internal_to_time(i + 1)}

-
))} + {entries[0].map(d => (d != null &&
+
+
+

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

+

Moduel etc.

+

Mehr Infos

+

Raum

+
+
+
))} +
+ + +
onMouseDown(e)} + onMouseMove={e => onMouseMove(e)} + onMouseUp={e => onMouseUp(e)}> + + {entries[1].map(d => (d != null &&
+ +
+
+

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

+

Moduel etc.

+

Mehr Infos

+

Raum

+
+
+
))} +
+ + +
onMouseDown(e)} + onMouseMove={e => onMouseMove(e)} + onMouseUp={e => onMouseUp(e)}> + + + {entries[2].map(d => (d != null &&
+ +
+
+

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

+

Moduel etc.

+

Mehr Infos

+

Raum

+
+
+
))} +
+ + +
onMouseDown(e)} + onMouseMove={e => onMouseMove(e)} + onMouseUp={e => onMouseUp(e)}> + + {entries[3].map(d => (d != null &&
+ +
+
+

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

+

Moduel etc.

+

Mehr Infos

+

Raum

+
+
+
))} +
+ + +
onMouseDown(e)} + onMouseMove={e => onMouseMove(e)} + onMouseUp={e => onMouseUp(e)}> + + + {entries[4].map(d => (d != null &&
+
+
+

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

+

Moduel etc.

+

Mehr Infos

+

Raum

+
+
+
))} +
+ + +
onMouseDown(e)} + onMouseMove={e => onMouseMove(e)} + onMouseUp={e => onMouseUp(e)}> + + + {entries[5].map(d => (d != null &&
+
+
+

{internal_to_time(d.timestart) + " - " + internal_to_time(d.timeend)}

+

Moduel etc.

+

Mehr Infos

+

Raum

+
+
+
))} +
+
+ + +
+ {/*maps a list of internal time stamps to lines and time stamps*/} + {temp.map(i => (
+ +

{internal_to_time(i + 1)}

+

{internal_to_time(i + 1)}

+

{internal_to_time(i + 1)}

+

{internal_to_time(i + 1)}

+

{internal_to_time(i + 1)}

+

{internal_to_time(i + 1)}

+
))} +
diff --git a/anwendung/src/components/DateElement.jsx b/anwendung/src/components/DateElement.jsx index 2db3508..6dce2d6 100644 --- a/anwendung/src/components/DateElement.jsx +++ b/anwendung/src/components/DateElement.jsx @@ -4,17 +4,13 @@ function addDays(date, days) { return result; } -export default function DateElement(props){ - let startDate; - let endDate; - const currDate = new Date(); +export default function DateElement(p){ - startDate = addDays(currDate, (currDate.getDay()-1)*-1); //berechnet den Montag der aktuellen Woche - startDate = addDays(startDate, props.week*7); //erhöht das Datum um 7 Tage für jede Woche, die weiter geklickt wurde. - endDate = addDays(startDate, 6); + let startDate = new Date(p.year, 0, p.startday); + let endDate = new Date(p.year, 0, p.startday + 5); - const startDateString = `${startDate.getDate()}.${startDate.getMonth()+1}.${startDate.getFullYear()}`; - const endDateString = `${endDate.getDate()}.${endDate.getMonth()+1}.${endDate.getFullYear()}`; + let startDateString = `${startDate.getDate()}.${startDate.getMonth()+1}.${startDate.getFullYear()}`; + let endDateString = `${endDate.getDate()}.${endDate.getMonth()+1}.${endDate.getFullYear()}`; return ( <>
diff --git a/anwendung/src/components/WeekSelector.jsx b/anwendung/src/components/WeekSelector.jsx index 64f3535..69acfad 100644 --- a/anwendung/src/components/WeekSelector.jsx +++ b/anwendung/src/components/WeekSelector.jsx @@ -6,14 +6,14 @@ import { useState } from 'react' -export default function WeekSelector(){ - const [weeks, setWeeks] = useState(0) +export default function WeekSelector(p){ + return ( <>
-
) diff --git a/anwendung/src/pages/planning.js b/anwendung/src/pages/planning.js index 06e170f..886a76c 100644 --- a/anwendung/src/pages/planning.js +++ b/anwendung/src/pages/planning.js @@ -1,9 +1,13 @@ import CalenderView from "@/components/CalenderView"; +import Background from "@/components/Background"; export default function planning(p) { return ( - + <> + + + ) } \ No newline at end of file diff --git a/anwendung/src/styles/globals.css b/anwendung/src/styles/globals.css index e8fd31c..84200a6 100644 --- a/anwendung/src/styles/globals.css +++ b/anwendung/src/styles/globals.css @@ -171,7 +171,9 @@ weekSelector width: 200px; align-items: center; justify-content: center; - background-color: #0d52ce; + background-color: #77932b; + font-weight: bold; + color: white; } .weekSelector { @@ -303,7 +305,7 @@ Calender View .wochen-tag-container .wochen-tag { text-align: center; - background-color: #f80000; + background-color: #346991; width: 400px; color: white; border-radius: 10px; diff --git a/backend/database.mv.db b/backend/database.mv.db index 45c46d041b166b5c058b8a9b64d79f0de299bef2..fb82867e74fde3e00666a229a069f284706bd831 100644 GIT binary patch literal 45056 zcmeHQUyK|_TA$e+dpgb^=OBQTi<0r$PVBH*byas)b&ojV+1*)tqV+nryS8J5w5sl^ zju)?Y&3f%5AfddRbUYy)FF`_p#36xD4(U$7BfKLaAq9vccs_Ip9^i?4;@5wwyXN2S ztk>(Gzoy3_Wv0u==+3RD!RC{R(LqCiD~iUJh{DhgB-s3`E2QQ%6Y|9@q)uYS0qKt+Ly0u==+ z3RD!RC{R(LqCiD~iUJh{DhfO)3gkw9ro8~@?3UWbn!sIguT2An<40}kz#Cv&eYDqh zXYYv*)cv-Y-QC&QYZK}F@D#9F><~J;w|Q5!J?Y?XPnGTfsCsWFY7-?$>#=+iUxHrq zk84xY^;-RlPinPay^$X4fAVR1oIdx9>9O%U|ML2oZ@y+Z(v_j|q~!&I37Zp(DJEU+ z+qK$>?@YZ~pL)G!5gIEJQ{N(<%_AprP;hNKj$;(Uz?Di_gc08h6hlD-Dx|7OxXXwP zndqY#I#wDC+clY7_y`5b(C&Rgw2U}Y= z#MT3~DE7qq$M>pxD*9Bsag6<9cAyXLeKdC?^R7}d?TASyJhvnww8F>d2X01(UETRm zcU67Y$)+Arp0*BNtDStQ`QKAhXKJOSb`t64`NVP*QIUX@bd<6~H|CZT6BP#%0xOn* z@+r4m64+tn3(KVt(+*{p>j=m;>7x)!;mg2sxwNSh;^r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gAnH`Sxy!y7vT5Ke`U8cHV@L$bXm*Z%v0^|ivZ&JS~wIbRi}C@%qTw+j?i zV_T(Z!B7@9cQk(PP};B`$u_r*<9yCSK+$7^X z4Ir&RnTOVwEPTP{sCepFi0K{*DO2~ugSTgjSxTn6RwaS2Z9Ls@C1tPBAt$E_U7nVgw; zC8I1h&Z6K@o@Oiq`w<$um*;z7k{LJMgDYKLoEx9p?0XPLFILyW7ED{>ZEV^SZ)4Mz zcnhX2mIcONvp@ZrWd)X1|HmcEdi postEntry(@RequestBody Entry entry) + public ResponseEntity postEntry(@RequestBody Entry entry, @RequestParam(name = "sessionid") String sessionid) { - db.addEntry(entry); - return new ResponseEntity<>(true, HttpStatus.OK); + User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid); + + if (sessionUser != null) + { + db.addEntry(entry); + return new ResponseEntity<>(true, HttpStatus.OK); + } + + return new ResponseEntity<>(false, HttpStatus.FORBIDDEN); } @CrossOrigin @GetMapping("/entries") - public ResponseEntity getEntries(@RequestParam(name="semesterid") int semesterid, - @RequestParam(name="daynumber") int daynumber, - @RequestParam(name="yearnumber") int yearnumber) + public ResponseEntity getEntries(@RequestParam(name = "semesterid") int semesterid, + @RequestParam(name = "daynumber") int daynumber, + @RequestParam(name = "yearnumber") int yearnumber, + @RequestParam(name = "sessionid") String sessionid) { + User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid); - return new ResponseEntity<>(db.getEntries(semesterid, daynumber, yearnumber), HttpStatus.OK); + if (sessionUser != null) + { + return new ResponseEntity<>(db.getEntries(semesterid, daynumber, yearnumber), HttpStatus.OK); + } + + return new ResponseEntity<>(null, HttpStatus.FORBIDDEN); } @CrossOrigin @DeleteMapping("/entries") - public ResponseEntity deleteEntry(@RequestParam(name="id") int id) + public ResponseEntity deleteEntry(@RequestParam(name = "id") int id, @RequestParam(name = "sessionid") String sessionid) { - db.deleteEntry(id); - return new ResponseEntity<>(true, HttpStatus.OK); + User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid); + + if (sessionUser != null) + { + db.deleteEntry(id); + return new ResponseEntity<>(true, HttpStatus.OK); + } + + return new ResponseEntity<>(false, HttpStatus.FORBIDDEN); + } + + @CrossOrigin + @PutMapping("/entries") + public ResponseEntity updateEntry(@RequestParam(name="sessionid") String sessionid, @RequestBody Entry entry) + { + User sessionUser = UserSessionIDHandler.getUserBySessionID(sessionid); + if (sessionUser != null) + { + db.updateEntry(entry); + return new ResponseEntity<>(true, HttpStatus.OK); + } + + return new ResponseEntity<>(false, HttpStatus.FORBIDDEN); } }