@RequestMapping("/edit-appointment") public String editAppointment( int id, String dateMonth, String dateDay, String dateYear, String dateHour, String dateMinute, String purpose, String doctorName, String patientName, HttpSession session) throws Exception { if (session.getAttribute("username") == null) { throw new Exception("not logged in"); } Appointment appointment = appointments.findOne(id); appointment.patientName = patientName; appointment.doctorName = doctorName; appointment.purpose = purpose; appointment.dateMonth = dateMonth; appointment.dateDay = dateDay; appointment.dateYear = dateYear; appointment.dateHour = dateHour; appointment.dateMinute = dateMinute; appointments.save(appointment); return "redirect:/"; }
@RequestMapping("/add-appointment") public String addAppointment( String dateMonth, String dateDay, String dateYear, String dateHour, String dateMinute, String purpose, String doctorName, String patientName, HttpSession session) throws Exception { if (session.getAttribute("username") == null) { throw new Exception("not logged in"); } String username = (String) session.getAttribute("username"); User user = users.findOneByUsername(username); Appointment appointment = new Appointment(); appointment.patientName = patientName; appointment.doctorName = doctorName; appointment.purpose = purpose; appointment.dateMonth = dateMonth; appointment.dateDay = dateDay; appointment.dateYear = dateYear; appointment.dateHour = dateHour; appointment.dateMinute = dateMinute; if (purpose == null) { throw new Exception("Must submit purpose"); } else if (doctorName == null) { throw new Exception("Must submit doctor name"); } else if (patientName == null) { throw new Exception("Must submit patient name"); } else { appointments.save(appointment); } return "redirect:/"; }