diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/Appointment.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/Appointment.java new file mode 100644 index 0000000000000000000000000000000000000000..d193117e05eda212a53006735b61d85e3d712c47 --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/Appointment.java @@ -0,0 +1,37 @@ +package org.springframework.samples.petclinic.appointments; + +import java.util.Date; + +public class Appointment { + + private String owner; + + private String ownerPhone; + + private String pet; + + private String notes; + + private Date dateTime; + + public String getOwner() { + return owner; + } + + public String getOwnerPhone() { + return ownerPhone; + } + + public String getPet() { + return pet; + } + + public Date getDateTime() { + return dateTime; + } + + public String getNotes() { + return notes; + } + +} diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentBook.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentBook.java new file mode 100644 index 0000000000000000000000000000000000000000..55ebd488b3189f725d66273487499908c48658d9 --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentBook.java @@ -0,0 +1,13 @@ +package org.springframework.samples.petclinic.appointments; + +import java.util.Date; + +public interface AppointmentBook { + + Appointments getAppointmentsForToday(); + + Appointments getAppointmentsForDay(Date day); + + Long createAppointment(AppointmentForm form); + +} \ No newline at end of file diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentForm.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentForm.java new file mode 100644 index 0000000000000000000000000000000000000000..d3d7abaaf5582682c7cd14c95cd70c497d11f3a2 --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentForm.java @@ -0,0 +1,67 @@ +package org.springframework.samples.petclinic.appointments; + +import java.util.Date; + +public class AppointmentForm { + + private Long doctor; + + private Long owner; + + private String pet; + + private Date date; + + private Date time; + + private String notes; + + public Long getDoctor() { + return doctor; + } + + public void setDoctor(Long doctor) { + this.doctor = doctor; + } + + public Long getOwner() { + return owner; + } + + public void setOwner(Long owner) { + this.owner = owner; + } + + public String getPet() { + return pet; + } + + public void setPet(String pet) { + this.pet = pet; + } + + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + + public Date getTime() { + return time; + } + + public void setTime(Date time) { + this.time = time; + } + + public String getNotes() { + return notes; + } + + public void setNotes(String notes) { + this.notes = notes; + } + +} \ No newline at end of file diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/Appointments.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/Appointments.java new file mode 100644 index 0000000000000000000000000000000000000000..f2aa85e682077c172fdd00c4936179b5f3610183 --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/Appointments.java @@ -0,0 +1,15 @@ +package org.springframework.samples.petclinic.appointments; + +import java.util.LinkedHashMap; +import java.util.List; +import java.util.Map; + +public class Appointments { + + private Map<String, List<Appointment>> vetAppointments = new LinkedHashMap<String, List<Appointment>>(); + + public Map<String, List<Appointment>> getAllByVet() { + return vetAppointments; + } + +} diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentsController.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentsController.java index c8abc0ab86b8ccf753414fa690a922813c0544f9..e3c786017f0a221dea7bb21434bfe8c5b7d1cb86 100644 --- a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentsController.java +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/AppointmentsController.java @@ -1,6 +1,10 @@ package org.springframework.samples.petclinic.appointments; +import java.util.Date; + +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; @@ -8,9 +12,31 @@ import org.springframework.web.bind.annotation.RequestMethod; @RequestMapping("/appointments") public class AppointmentsController { + private AppointmentBook appointmentBook; + + @Autowired + public AppointmentsController(AppointmentBook appointmentBook) { + this.appointmentBook = appointmentBook; + } + @RequestMapping(method = RequestMethod.GET) - public void get() { - + public Appointments get() { + return appointmentBook.getAppointmentsForToday(); + } + + @RequestMapping(value="/{day}", method = RequestMethod.GET) + public Appointments getForDay(@PathVariable Date day) { + return appointmentBook.getAppointmentsForDay(day); + } + + @RequestMapping(value="/new", method = RequestMethod.GET) + public AppointmentForm getNewForm() { + return new AppointmentForm(); } + @RequestMapping(method = RequestMethod.POST) + public String post(AppointmentForm form) { + appointmentBook.createAppointment(form); + return "redirect:/appointments"; + } } diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/StubAppointmentBook.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/StubAppointmentBook.java new file mode 100644 index 0000000000000000000000000000000000000000..92525a3655782b1773b2d64a83911da5bceac453 --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/appointments/StubAppointmentBook.java @@ -0,0 +1,23 @@ +package org.springframework.samples.petclinic.appointments; + +import java.util.Date; + +import org.springframework.stereotype.Repository; + +@Repository +public class StubAppointmentBook implements AppointmentBook { + + public Appointments getAppointmentsForDay(Date day) { + return new Appointments(); + } + + public Appointments getAppointmentsForToday() { + return new Appointments(); + } + + public Long createAppointment(AppointmentForm form) { + return 1L; + } + + +} diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/Owner.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/Owner.java index 934accd06c076b360269c4112aca62b06cab0e56..9841482b5bf6d542612b052537414c2f355073fa 100644 --- a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/Owner.java +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/Owner.java @@ -12,7 +12,7 @@ public class Owner { private String city; - private String telephone; + private String phone; public Owner() { @@ -58,13 +58,12 @@ public class Owner { this.city = city; } - public String getTelephone() { - return telephone; + public String getPhone() { + return phone; } - public void setTelephone(String telephone) { - this.telephone = telephone; + public void setPhone(String phone) { + this.phone = phone; } - -} +} \ No newline at end of file diff --git a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/OwnersController.java b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/OwnersController.java index f41e89571d151cfdbb7fc3bec728251aef827f0e..f24cd074590e1fdc95344d6ff87ea9b9f00465ba 100644 --- a/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/OwnersController.java +++ b/org.springframework.samples.petclinic/src/main/java/org/springframework/samples/petclinic/owners/OwnersController.java @@ -37,7 +37,6 @@ public class OwnersController { @RequestMapping(method = RequestMethod.POST) public String post(Owner owner) { Long ownerId = repository.saveOwner(owner); - // TODO simplify this since /owners is the current resource already? return "redirect:/owners/" + ownerId; } diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/appointments/addNewForm.jsp b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/appointments/addNewForm.jsp new file mode 100644 index 0000000000000000000000000000000000000000..997640df0bc2faf0f5622c0fad6e11d92c3d4764 --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/appointments/addNewForm.jsp @@ -0,0 +1,31 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %> +<h2>Add New Appointment</h2> + +<form:form id="addNewForm" action="${pageContext.request.contextPath}/appointments" modelAttribute="appointment" method="post"> + <form:label for="doctor" path="doctor"> + Doctor + <form:input path="doctor" /> + </form:label> + <form:label for="owner" path="owner"> + Owner + <form:input path="owner" /> + </form:label> + <form:label for="pet" path="pet"> + Pet + <form:input path="pet" /> + </form:label> + <form:label for="date" path="date"> + Date + <form:input path="date" /> + </form:label> + <form:label for="time" path="time"> + Time + <form:input path="time" /> + </form:label> + <form:label for="notes" path="notes"> + Notes + <form:input path="notes" /> + </form:label> + <input type="submit" value="Add" /> +</form:form> \ No newline at end of file diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/appointments/content.jsp b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/appointments/content.jsp new file mode 100644 index 0000000000000000000000000000000000000000..b171fb5ad907fa5cc10f8f891650e5e542126b5d --- /dev/null +++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/appointments/content.jsp @@ -0,0 +1,11 @@ +<%@ taglib prefix="tiles" uri="http://tiles.apache.org/tags-tiles" %> + +<div id="sidebar"> + <ul id="sub-nav"> + <li><a href="${pageContext.request.contextPath}/appointments">Calendar</a></li> + <li><a href="${pageContext.request.contextPath}/appointments/new">Add New</a></li> + </ul> +</div> +<div id="main"> + <tiles:insertAttribute name="main" /> +</div> \ No newline at end of file diff --git a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/tiles.xml b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/tiles.xml index 87229ac06d05f6811348e43f4ffe926e5e7b2297..e87543e730b80ea67995802a2c15c38fa02c10f5 100644 --- a/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/tiles.xml +++ b/org.springframework.samples.petclinic/src/main/webapp/WEB-INF/tiles.xml @@ -17,13 +17,30 @@ </definition> <!-- APPOINTMENTS PAGES --> + + <!-- CALENDAR PAGE --> <definition name="appointments" extends="page"> <put-attribute name="title" value="Appointments" type="string" /> - <put-attribute name="content" value="/WEB-INF/appointments/calendar.jsp" type="template" /> + <put-attribute name="content" value="appointments.content" type="definition" /> </definition> + <definition name="appointments.content" template="/WEB-INF/appointments/content.jsp"> + <put-attribute name="main" value="/WEB-INF/appointments/calendar.jsp" type="template" /> + </definition> + + <!-- ADD NEW PAGE --> + <definition name="appointments/new" extends="page"> + <put-attribute name="title" value="Add New Appointment" type="string" /> + <put-attribute name="content" value="appointments/new.content" type="definition" /> + </definition> + + <definition name="appointments/new.content" template="/WEB-INF/appointments/content.jsp"> + <put-attribute name="main" value="/WEB-INF/appointments/addNewForm.jsp" type="template" /> + </definition> + <!-- OWNERS PAGES --> + <!-- SEARCH PAGE --> <definition name="owners" extends="page"> <put-attribute name="title" value="Owners" type="string" /> @@ -36,7 +53,7 @@ <!-- ADD NEW PAGE --> <definition name="owners/new" extends="page"> - <put-attribute name="title" value="Owners" type="string" /> + <put-attribute name="title" value="Add New Owner" type="string" /> <put-attribute name="content" value="owners/new.content" type="definition" /> </definition> @@ -54,7 +71,7 @@ <put-attribute name="main" value="/WEB-INF/owners/searchResults.jsp" type="template" /> </definition> - <!-- OWNER DETAIL PAGE --> + <!-- DETAIL PAGE --> <definition name="owner" extends="page"> <put-attribute name="title" value="Owner" type="string" /> <put-attribute name="content" value="owner.content" type="definition" /> @@ -64,4 +81,5 @@ <put-attribute name="main" value="/WEB-INF/owners/owner.jsp" type="template" /> </definition> + </tiles-definitions> \ No newline at end of file