Skip to content

Commit

Permalink
added servlet propeties
Browse files Browse the repository at this point in the history
  • Loading branch information
DDDrag0 committed Jan 1, 2024
1 parent 8d0fdbd commit 8574580
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 7 deletions.
62 changes: 59 additions & 3 deletions src/main/java/controller/ScheduleServlet.java
Original file line number Diff line number Diff line change
@@ -1,19 +1,75 @@
package controller;

import model.entity.Schedule;
import model.service.schedule.ScheduleManager;

import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

@WebServlet("/ScheduleServlet")
public class ScheduleServlet extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
HttpSession session = request.getSession();
int userId = 44;//(Integer) request.getSession().getAttribute("id");
response.getWriter().append("Served at: ").append(request.getContextPath());
String action = request.getParameter("action");
ScheduleManager scheduleManager = new ScheduleManager();

try {

//azioni fatte dal logopedista

RequestDispatcher dispatcher = request.getRequestDispatcher("JSP/schedule.jsp");
if (action.equalsIgnoreCase("createNewSchedule")) {
System.out.println("entrato createNewSchedule");
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));
scheduleManager.createNewSchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")));
System.out.println(idTherapist +" == "+ (request.getParameter("date")) +" == "+ (request.getParameter("timeslot")));
//scheduleManager.createNewSchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")));
dispatcher = request.getRequestDispatcher("JSP/schedule.jsp");
}
else if (action.equalsIgnoreCase("deleteSchedule")) {
System.out.println("entrato deleteSchedule");
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));
scheduleManager.deleteSchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")));
//scheduleManager.deleteSchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")));
dispatcher = request.getRequestDispatcher("JSP/schedule.jsp");
}
else if (action.equalsIgnoreCase("modifySchedule")) {
int idReserved = Integer.parseInt(request.getParameter("idReserved"));
scheduleManager.modifySchedule(userId,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("ndate")),(request.getParameter("ntimeslot")),idReserved);
dispatcher = request.getRequestDispatcher("JSP/schedule.jsp");
}

//azioni fatte dal paziente

else if (action.equalsIgnoreCase("prenoteSchedule")) {
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));
scheduleManager.modifySchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("date")),(request.getParameter("timeslot")),userId);
dispatcher = request.getRequestDispatcher("JSP/schedule.jsp");
}else if (action.equalsIgnoreCase("unprenoteSchedule")) {
int idTherapist = Integer.parseInt(request.getParameter("idTherapist"));
scheduleManager.modifySchedule(idTherapist,(request.getParameter("date")),(request.getParameter("timeslot")),(request.getParameter("date")),(request.getParameter("timeslot")),0);
dispatcher = request.getRequestDispatcher("JSP/schedule.jsp");
}


else {
// Gestisci il caso in cui "action" non sia presente nella richiesta
response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid action parameter");
}

dispatcher.forward(request, response);
} catch (ServletException e) {
throw new RuntimeException(e);
}
}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {

doGet(request, response);
}
}
10 changes: 6 additions & 4 deletions src/main/webapp/JSP/schedule.jsp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@
<button id="prevMonth">Previous Month</button>
<table id="calendarTable"></table>
<table id="timeTable"></table>
<form id="dateForm">
<input type="hidden" id="selectedDate" name="selectedDate">
<input type="hidden" id="selectedTime" name="selectedTime">
<input type="submit" value="Submit">
<form action="<%=request.getContextPath()%>/ScheduleServlet" id="dateForm">
<input type="hidden" name="idTherapist" value="0">
<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>
</div>
<script src="../JS/schedule.js"></script>
Expand Down

0 comments on commit 8574580

Please sign in to comment.