Skip to content

Commit

Permalink
better comunication with db and major fix for user division
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDrag0 committed Jan 2, 2024
1 parent d927581 commit 455cfa5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 29 deletions.
18 changes: 5 additions & 13 deletions src/main/java/controller/ScheduleServlet.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ protected void doGet(HttpServletRequest request, HttpServletResponse response) t
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
int userId = 44;//(Integer) request.getSession().getAttribute("id");
int userId = (Integer) request.getSession().getAttribute("id");
response.getWriter().append("Served at: ").append(request.getContextPath());
String action = request.getParameter("action");
ScheduleManager scheduleManager = new ScheduleManager();
Expand All @@ -25,32 +25,24 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
//azioni fatte dal logopedista

if (action.equalsIgnoreCase("createNewSchedule")) {
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));//cancellare
scheduleManager.createNewSchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")));//cancellare
//scheduleManager.createNewSchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")));
scheduleManager.createNewSchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")));
response.sendRedirect("JSP/schedule.jsp");
}
else if (action.equalsIgnoreCase("deleteSchedule")) {
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));//cancellare
scheduleManager.deleteSchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")));//cancellare
//scheduleManager.deleteSchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")));
scheduleManager.deleteSchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")));
response.sendRedirect("JSP/schedule.jsp");
}
else if (action.equalsIgnoreCase("modifySchedule")) {
int idReserved = Integer.parseInt(request.getParameter("idReserved"));
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));//cancellare
scheduleManager.modifySchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("ndate")),(request.getParameter("ntimeslot")),idReserved);//cancellare
//scheduleManager.modifySchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("ndate")),(request.getParameter("ntimeslot")),idReserved);
scheduleManager.modifySchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("ndate")),(request.getParameter("ntimeslot")),idReserved);
response.sendRedirect("JSP/schedule.jsp");
}

//azioni fatte dal paziente

else if (action.equalsIgnoreCase("prenoteSchedule")) {
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));
int idReserved = Integer.parseInt(request.getParameter("idReserved"));//cancellare
scheduleManager.modifySchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("date")),(request.getParameter("timeslot")),idReserved);//cancellare
//scheduleManager.modifySchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("date")),(request.getParameter("timeslot")),userId);
scheduleManager.modifySchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("date")),(request.getParameter("timeslot")),userId);
response.sendRedirect("JSP/schedule.jsp");
}else if (action.equalsIgnoreCase("unprenoteSchedule")) {
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));
Expand Down
36 changes: 20 additions & 16 deletions src/main/webapp/JSP/schedule.jsp
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<%@ page import="java.util.*" %>
<%@ page import="model.service.user.UserData" %>
<%@ page import="model.entity.User" %>
<%@ page import="model.service.user.UserRegistry" %>
<%@ page import="model.entity.PersonalInfo" %>
<%@ page import="model.entity.Schedule" %>
<%@ page import="model.service.schedule.ScheduleManager" %>
<%
/*if(session.getAttribute("id") == "null") {
Integer userIdp = (Integer) session.getAttribute("id");
if(userIdp == null) {
response.sendRedirect("../errorPage/403.html");
}
else {
int userId = (Integer) session.getAttribute("id");*/
int userId = (Integer) session.getAttribute("id");
%>
<!DOCTYPE html>
<html lang="it">
Expand All @@ -22,18 +22,20 @@
</head>
<body>
<div id="calendar">
<%
if (session.getAttribute("type") == "therapist"){
%>
<h1>aggiunta calendario prenotazione</h1>
<h2 id="calendarTitle"></h2>
<button id="prevMonth">Previous Month</button>
<button id="nextMonth">Next Month</button>
<table id="calendarTable"></table>
<table id="timeTable"></table>
<form action="<%=request.getContextPath()%>/ScheduleServlet" id="dateForm" method="post">
<input type="hidden" name="idTherapist" value="9">
<input type="hidden" name="idTherapist" value="<%=userId%>">
<input type="hidden" id="selectedDate" name="date">
<input type="hidden" id="selectedTime" name="timeslot">
<input type="submit" name="action" value="createNewSchedule">
<input type="submit" name="action" value="deleteSchedule">
</form>


Expand All @@ -56,7 +58,7 @@
</thead>
<%
ScheduleManager scheduleManager = new ScheduleManager();
List<Schedule> list = scheduleManager.retrieveAllPrenotedSchedules(9);
List<Schedule> list = scheduleManager.retrieveAllPrenotedSchedules(userId);
if(list!=null){
for(Schedule schedule : list) {
UserRegistry ur = new UserRegistry();
Expand All @@ -79,7 +81,6 @@
<%
}
%>
<input type="hidden" name="idTherapist" value="<%=schedule.getIdTherapist()/*qua va messo idUser*/%>">
<input type="hidden" name="date" value="<%=schedule.getDate()%>">
<input type="hidden" name="timeslot" value="<%=schedule.getTimeSlot()%>">
<input type="hidden" name="idReserved" value="<%=schedule.getReserved()%>">
Expand Down Expand Up @@ -115,7 +116,7 @@
</thead>
<%
ScheduleManager scheduleManager2 = new ScheduleManager();
List<Schedule> list2 = scheduleManager2.retrieveAllTherapistSchedules(9);
List<Schedule> list2 = scheduleManager2.retrieveAllTherapistSchedules(userId);
if(list2!=null){
for(Schedule schedule : list2) {
UserRegistry ur = new UserRegistry();
Expand All @@ -138,7 +139,6 @@
<%
}
%>
<input type="hidden" name="idTherapist" value="<%=schedule.getIdTherapist()/*qua va messo idUser*/%>">
<input type="hidden" name="date" value="<%=schedule.getDate()%>">
<input type="hidden" name="timeslot" value="<%=schedule.getTimeSlot()%>">
<input type="hidden" name="idReserved" value="<%=schedule.getReserved()%>">
Expand All @@ -160,14 +160,17 @@
}
%>
</table>
<%
}else{
%>







<h1>paziente</h1>
<h1>paziente <%=userId%></h1>
<h2>prenotazioni disponibili</h2>
<table class="modTable">
<thead>
Expand All @@ -180,7 +183,7 @@
</thead>
<%
ScheduleManager scheduleManager3 = new ScheduleManager();
List<Schedule> list3 = scheduleManager3.retrieveAllNotPrenotedSchedules(9);
List<Schedule> list3 = scheduleManager3.retrieveAllNotPrenotedSchedules((Integer) session.getAttribute("therapist"));
if(list3!=null){
for(Schedule schedule : list3) {
UserRegistry ur = new UserRegistry();
Expand All @@ -206,7 +209,6 @@
<input type="hidden" name="idTherapist" value="<%=schedule.getIdTherapist()%>">
<input type="hidden" name="date" value="<%=schedule.getDate()%>">
<input type="hidden" name="timeslot" value="<%=schedule.getTimeSlot()%>">
<input type="hidden" name="idReserved" value="15<%/*qua va messo idUser*/%>">
<th>
<input type="submit" name="action" value="prenoteSchedule">
</th>
Expand Down Expand Up @@ -239,7 +241,7 @@
</thead>
<%
ScheduleManager scheduleManager4 = new ScheduleManager();
List<Schedule> list4 = scheduleManager4.retrieveAllPatientSchedules(15);
List<Schedule> list4 = scheduleManager4.retrieveAllPatientSchedules(userId);
if(list4!=null){
for(Schedule schedule : list4) {
UserRegistry ur = new UserRegistry();
Expand All @@ -265,7 +267,6 @@
<input type="hidden" name="idTherapist" value="<%=schedule.getIdTherapist()%>">
<input type="hidden" name="date" value="<%=schedule.getDate()%>">
<input type="hidden" name="timeslot" value="<%=schedule.getTimeSlot()%>">
<input type="hidden" name="idReserved" value="15<%/*qua va messo idUser*/%>">
<th>
<input type="submit" name="action" value="unprenoteSchedule">
</th>
Expand All @@ -283,6 +284,9 @@
%>
</table>

<%
}
%>



Expand All @@ -292,5 +296,5 @@
</html>

<%
//}
}
%>

0 comments on commit 455cfa5

Please sign in to comment.