From f52d4275ba3426f516f553d0c4ab6b62f58a4cf0 Mon Sep 17 00:00:00 2001 From: brausjonas Date: Fri, 26 May 2023 00:46:50 +0200 Subject: [PATCH] New Calender View Logic Concept --- anwendung/src/components/CalenderEntry.js | 9 - anwendung/src/components/CalenderView.jsx | 810 +++++++++--------- anwendung/src/components/Login.jsx | 4 + anwendung/src/pages/planning.js | 9 + anwendung/src/pages/semesteroverview.js | 2 + anwendung/src/styles/globals.css | 2 +- backend/database.mv.db | Bin 49152 -> 45056 bytes backend/database.trace.db | 30 + .../backend/anwprj/DataBaseHandler.java | 124 ++- .../example/backend/anwprj/Entries/Entry.java | 51 +- .../anwprj/controller/EntriesController.java | 36 +- 11 files changed, 587 insertions(+), 490 deletions(-) delete mode 100644 anwendung/src/components/CalenderEntry.js create mode 100644 anwendung/src/pages/planning.js diff --git a/anwendung/src/components/CalenderEntry.js b/anwendung/src/components/CalenderEntry.js deleted file mode 100644 index dc0013c..0000000 --- a/anwendung/src/components/CalenderEntry.js +++ /dev/null @@ -1,9 +0,0 @@ -export class CalenderEntry -{ - constructor(start_point, end_point) - { - this.start_point = start_point; - this.end_point = end_point; - this.colorID = 0; - } -} \ No newline at end of file diff --git a/anwendung/src/components/CalenderView.jsx b/anwendung/src/components/CalenderView.jsx index cd0c214..cb29989 100644 --- a/anwendung/src/components/CalenderView.jsx +++ b/anwendung/src/components/CalenderView.jsx @@ -1,323 +1,375 @@ import {useEffect, useState} from "react"; -import {CalenderEntry} from "@/components/CalenderEntry"; import Button from "@/components/Button"; import {list} from "postcss"; -//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 = ""; +// //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 colors = ["#f80000", "#414141"] -export default function CalenderView(p) -{ - //state to update the calender view - const [t, setT] = useState(false) +let semesterStart; +let currentWeekStartDay; +let currentYear; - //a blocker for the right click context menu - useEffect(() => - { - window.addEventListener("contextmenu", (e) => (e.preventDefault())) - }) +export default function CalenderView(p) { - function does_element_overlap(entry, start, end, search_list) + const [entries, setEntries] = useState([[], [], [], [], [], []]) + + function readEntries() { + let url = "http://localhost:8080/entries?semesterid=" + localStorage.getItem("currentsid") + + "&daynumber=" + currentWeekStartDay + "&yearnumber=" + currentYear; + console.log(currentWeekStartDay) + fetch(url).then(r => r.json()).then(en => setEntries(en)) + } + + function pushEntry(currentColumnID, row) { - let current = null; - for(let i = 0; i < search_list.length; i++) + let url = "http://localhost:8080/entries" + let json = { + "id": 0, + "daynumber": currentWeekStartDay + currentColumnID, + "yearnumber": currentYear, + "semesterid": localStorage.getItem("currentsid"), + "usercreatedbyid": localStorage.getItem("userid"), + "timestart": row, + "timeend": row + 3, + "info": "" + } + fetch(url, { + method: "POST", + headers: {"Content-Type": "application/json"}, + body: JSON.stringify(json) + }).then(r => {readEntries()}) + } + + function deleteEntry(id) + { + let url = "http://localhost:8080/entries?id=" + id; + fetch(url, { + method: "DELETE" + }).then(r => readEntries()) + } + + function onMouseDown(e) { + 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) + let currentId = e.target.id; + + if(e.button === 0) { - current = search_list[i]; - if(current !== entry) + pushEntry(currentColumnID, row) + } + else if(e.button === 2) + { + if(currentId.includes("e")) { - if (start > current.start_point && start < current.end_point) - { - return true; - } else if (end > current.start_point && end < current.end_point) - { - return true; - } else if (start <= current.start_point && end >= current.end_point) - { - return true; - } + let id = parseInt(currentId.replace("e", "")) + deleteEntry(id) } } - - return false; } + useEffect(() => { + semesterStart = 0; + currentWeekStartDay = 0; + currentYear = 2000; + + let url = "http://localhost:8080/semester/id?sessionid=" + localStorage.getItem("sessionid") + + "&id=" + localStorage.getItem("currentsid"); + + fetch(url).then(r => r.json()).then(s => { + currentWeekStartDay = s.startday - new Date(s.startyear, 0, s.startday).getUTCDay(); + currentYear = s.startyear; + semesterStart = s.startday; + }).then(readEntries) + + 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; - } + // 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.start_point) - - if (row < grabbed.end_point - 1) - { - if(!does_element_overlap(grabbed, row, grabbed.end_point, current_list)) - { - grabbed.start_point = row; - } - } - } else - { - if (row > grabbed.start_point) - { - if(!does_element_overlap(grabbed, grabbed.start_point, row + 1, current_list)) - { - grabbed.end_point = row + 1; - } - } - } - } - } + // 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.start_point = row - selectedOffsetTop; - selectedElement.end_point = row + selectedOffsetBottom; - } - } - } + // 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); - } + // 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; + // 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); + // } - //remove all selected elements - if (grabbed != null) - { - grabbed.colorID = 0; - grabbed = null; - } - if (selectedElement != null) - { - selectedElement.colorID = 0; - selectedElement = null; - } - - setT(!t); - } - - //find the current element on row in the selected list (search_list) - function find_current(row, search_list) - { - let current = null; - for (let i = 0; i < search_list.length; i++) - { - current = search_list[i]; - if (current.start_point <= row && current.end_point >= row) - { - break; - } - current = null; - } - - return current; - } //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.start_point; s < current.end_point; s++) - { - if (s === r) - { - free = false; - break; - } - } - } - } - - if (free) - { - list.push(new CalenderEntry(row, row + 3)); - setT(!t); - } - } - } + // 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) - } - } - } + // 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) - { + function internal_to_time(internal) { internal -= 1 internal /= 4 let integer = Math.floor(internal) @@ -328,23 +380,17 @@ export default function CalenderView(p) } let temp = [] - for (let i = 2; i <= 96; i += 2) - { + for (let i = 2; i <= 96; i += 2) { temp.push(i); } - //html of the calender view + return ( - // calender outer container, contains the calender view and resize buttons +
- {/* resize butto*/} -
) } \ No newline at end of file diff --git a/anwendung/src/components/Login.jsx b/anwendung/src/components/Login.jsx index 8a1fd98..df63faa 100644 --- a/anwendung/src/components/Login.jsx +++ b/anwendung/src/components/Login.jsx @@ -20,6 +20,9 @@ export default function Login() { if (value != "failed") { localStorage.setItem("sessionid", value); + url = "http://localhost:8080/users/check?sessionid=" + value; + fetch(url).then(r => r.json()).then(u => localStorage.setItem("userid", u.id)) + await router.push("/semesteroverview") } else { @@ -35,6 +38,7 @@ export default function Login() { const [backgroundColor, setBackgroundColor] = useState("rgb(255, 255, 255)") const router = useRouter() + return ( //
diff --git a/anwendung/src/pages/planning.js b/anwendung/src/pages/planning.js new file mode 100644 index 0000000..06e170f --- /dev/null +++ b/anwendung/src/pages/planning.js @@ -0,0 +1,9 @@ +import CalenderView from "@/components/CalenderView"; + +export default function planning(p) +{ + + return ( + + ) +} \ No newline at end of file diff --git a/anwendung/src/pages/semesteroverview.js b/anwendung/src/pages/semesteroverview.js index 334eb12..5d8a323 100644 --- a/anwendung/src/pages/semesteroverview.js +++ b/anwendung/src/pages/semesteroverview.js @@ -25,7 +25,9 @@ export default function SemesterOverview(p) if(m.target === m.currentTarget) { localStorage.setItem("currentsid", e.id) + router.push("/planning") } + } function onClickNewSemester() diff --git a/anwendung/src/styles/globals.css b/anwendung/src/styles/globals.css index 58bfc89..e8fd31c 100644 --- a/anwendung/src/styles/globals.css +++ b/anwendung/src/styles/globals.css @@ -322,7 +322,7 @@ Calender View justify-content: space-between; padding: 0 2px; align-items: center; - cursor: move; + /*cursor: move;*/ z-index: 10; overflow: hidden; margin-top: 1px; diff --git a/backend/database.mv.db b/backend/database.mv.db index 1bd03b7debf50b543e5c56fad11c826f868c59a4..45c46d041b166b5c058b8a9b64d79f0de299bef2 100644 GIT binary patch literal 45056 zcm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QPSR@(;qpef+ZC=0_>lWju$K&x6+$Q0W2mk2~6aW7QiT_`Jp7{SEg%wm*1=87H z{HHjr9)3E>`v3nh>;KLAe-mW&d7D7}D$_Fs-_rBE{(tUg^Zz|FV?bC2gk|Dio7mqb z?)gd3Ia3%arUAk_|ARO(KsL_~Xe7?JvRO(FSf)kHmjMGX4t7@2(6vRL}zgbSqC=iF2#^V zA(JJv_9VQ{x0x-mx)d+pdvT(1{z|$pdhf_0fYs8T*%O*Bm_f8JSrKZ2Vw6sCG#U5N)dpP^2tzWbiir@urJ1H1F$bj z0oZ3*m8;g=pZ_$*YS;endvN}$Wuq-fVRzt*Q91K7955U(955U(9C&^?km3Ie{C$D{ z=SBR#K!hHHeJh?0IX`;$x$OBO)inHcmzy&FKU&?muRlI&2I(pQoNadmSE8SzFenMh zN;?RW1R?E8s{lm23IO)a8-4oe&H(F*WjFv1PN) zm>Tg0XwS;j_+f4j6<^87@GLfIb39m~R9HlV8%CXM`O>H@#7iHuVo6ik7|M2vnua+9 zL)W`s|8npDXYl_f2$L)Mo{&GW9&05QCHOc?t+vga0={SfBJco<|3Q?UR4AKR~$&j0`b diff --git a/backend/database.trace.db b/backend/database.trace.db index 7f922d9..3f30e58 100644 --- a/backend/database.trace.db +++ b/backend/database.trace.db @@ -270985,3 +270985,33 @@ No data is available [2000-214] 2023-05-25 13:35:45 jdbc[3]: exception org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar No data is available [2000-214] +2023-05-26 00:45:38 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:38 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:39 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:39 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:42 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:43 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:46 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:47 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:49 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] +2023-05-26 00:45:49 jdbc[3]: exception +org.h2.jdbc.JdbcSQLNonTransientException: Keine Daten verfügbar +No data is available [2000-214] diff --git a/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java b/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java index 5b96ddd..f8a1641 100644 --- a/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java +++ b/backend/src/main/java/com/example/backend/anwprj/DataBaseHandler.java @@ -173,58 +173,92 @@ public class DataBaseHandler /** ENTRIES */ - //method that returns all entries of a day based on the given parameters - public Entry[] getEntries(int dayinweek, int weeknumber, int semesterid, User user) + public void addEntry(Entry entry) { try { - //search the correct data in the database - ResultSet rs = st.executeQuery("select distinct e.id, e.dayid, e.usercreatedbyid, e.timestart, e.timeend, e.info " + - "from entries e, days d, weeks w, semester s " + - "where e.dayid = d.id and " + - "d.weekid = w.id and " + - "w.semesterid = s.id and " + - "d.dayinweek = " + dayinweek + " and " + - "w.weeknumber = " + weeknumber + " and " + - "s.id = " + semesterid); - - - int editable = 0; - - //a temporary list to save entry objects in - List temp = new ArrayList<>(); - //while there a still entries for the day - while(rs.next()) - { - editable = 0; - //if entry has been created by the requesting user set the entry to editable (or the user is admin) - if(rs.getInt("usercreatedbyid") == user.getId() || user.getPermissions() == 1) - { - editable = 1; - } - - temp.add( - new Entry( - rs.getInt("id"), - rs.getInt("dayid"), - rs.getInt("usercreatedbyid"), - rs.getInt("timestart"), - rs.getInt("timeend"), - rs.getString("info"), - editable - ) - ); - } - - //return the temporary list as an array - return temp.toArray(new Entry[0]); - - } catch (SQLException e) + st.executeUpdate("insert into entries (daynumber, yearnumber, semesterid, usercreatedbyid, timestart, timeend, info) values (" + + entry.getDaynumber() + ", " + entry.getYearnumber() + ", " + entry.getSemesterid() + ", " + + entry.getUsercreatedbyid() + ", " + entry.getTimestart() + ", " + entry.getTimeend() + ", '" + entry.getInfo() + "')" + ); + } + catch(Exception e) { - throw new RuntimeException(e); + e.printStackTrace(); } } + public Entry[][] getEntries(int semesterid, int daynumber, int yearnumber) + { + try + { + ResultSet rs = st.executeQuery("select * from entries where " + + "semesterid=" + semesterid + + " and yearnumber=" + yearnumber + + " and daynumber between " + daynumber + " and " + daynumber + 6); + + List entryList = new ArrayList<>(); + Entry current = null; + while((current = resultSetToEntry(rs)) != null) + { + entryList.add(current); + } + + Entry[][] entries = new Entry[6][20]; + for(int i = 0; i < 6; i++) + { + for(int j = 0; j < entryList.size(); j++) + { + if(entryList.get(j).getDaynumber() == i + daynumber) + { + entries[i][j] = entryList.get(j); + } + } + } + + return entries; + } + catch(Exception e) + { + return null; + } + } + + public void deleteEntry(int id) + { + try + { + st.executeUpdate("delete from entries where id=" + id); + } + catch (Exception e) + { + + } + } + + public Entry resultSetToEntry(ResultSet rs) + { + try + { + rs.next(); + return new Entry( + rs.getInt("id"), + rs.getInt("daynumber"), + rs.getInt("yearnumber"), + rs.getInt("usercreatedbyid"), + rs.getInt("timestart"), + rs.getInt("timeend"), + rs.getInt("semesterid"), + rs.getString("info") + ); + } + catch(Exception e) + { + return null; + } + } + + /** SEMESTER */ diff --git a/backend/src/main/java/com/example/backend/anwprj/Entries/Entry.java b/backend/src/main/java/com/example/backend/anwprj/Entries/Entry.java index 0d6f568..43a62cd 100644 --- a/backend/src/main/java/com/example/backend/anwprj/Entries/Entry.java +++ b/backend/src/main/java/com/example/backend/anwprj/Entries/Entry.java @@ -4,22 +4,24 @@ package com.example.backend.anwprj.Entries; public class Entry { private int id; - private int dayid; + private int daynumber; + private int yearnumber; private int usercreatedbyid; private int timestart; private int timeend; + private int semesterid; private String info; - private int editable; - public Entry(int id, int dayid, int usercreatedbyid, int timestart, int timeend, String info, int editable) + public Entry(int id, int daynumber, int yearnumber, int usercreatedbyid, int timestart, int timeend, int semesterid, String info) { this.id = id; - this.dayid = dayid; + this.daynumber = daynumber; + this.yearnumber = yearnumber; this.usercreatedbyid = usercreatedbyid; this.timestart = timestart; this.timeend = timeend; + this.semesterid = semesterid; this.info = info; - this.editable = editable; } public int getId() @@ -27,9 +29,14 @@ public class Entry return id; } - public int getDayid() + public int getDaynumber() { - return dayid; + return daynumber; + } + + public int getYearnumber() + { + return yearnumber; } public int getUsercreatedbyid() @@ -47,33 +54,13 @@ public class Entry return timeend; } + public int getSemesterid() + { + return semesterid; + } + public String getInfo() { return info; } - - public void setDayid(int dayid) - { - this.dayid = dayid; - } - - public void setTimestart(int timestart) - { - this.timestart = timestart; - } - - public void setTimeend(int timeend) - { - this.timeend = timeend; - } - - public void setInfo(String info) - { - this.info = info; - } - - public int getEditable() - { - return editable; - } } diff --git a/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java b/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java index 533cd76..943f5d6 100644 --- a/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java +++ b/backend/src/main/java/com/example/backend/anwprj/controller/EntriesController.java @@ -18,28 +18,28 @@ public class EntriesController } @CrossOrigin - @GetMapping("/entries") - public ResponseEntity getEntries( - @RequestParam(name = "sessionid") String sessionID, - @RequestParam(name = "dayinweek") int dayinweek, - @RequestParam(name = "weeknumber") int weeknumber, - @RequestParam(name = "semesterid") int semesterid) + @PostMapping("/entries") + public ResponseEntity postEntry(@RequestBody Entry entry) { - User user = UserSessionIDHandler.getUserBySessionID(sessionID); - - if(user == null) - { - return new ResponseEntity<>(HttpStatus.NOT_FOUND); - } - - Entry[] entries = db.getEntries(dayinweek, weeknumber, semesterid, user); - return new ResponseEntity<>(entries, HttpStatus.OK); + db.addEntry(entry); + return new ResponseEntity<>(true, HttpStatus.OK); } @CrossOrigin - @PostMapping("/entries") - public ResponseEntity postEntries(@RequestBody Entry[] entries, @RequestParam(name="sessionid") String sessionID) + @GetMapping("/entries") + public ResponseEntity getEntries(@RequestParam(name="semesterid") int semesterid, + @RequestParam(name="daynumber") int daynumber, + @RequestParam(name="yearnumber") int yearnumber) { - return null; + + return new ResponseEntity<>(db.getEntries(semesterid, daynumber, yearnumber), HttpStatus.OK); + } + + @CrossOrigin + @DeleteMapping("/entries") + public ResponseEntity deleteEntry(@RequestParam(name="id") int id) + { + db.deleteEntry(id); + return new ResponseEntity<>(true, HttpStatus.OK); } }