Skip to content
Snippets Groups Projects
Commit 2781809c authored by Keith Donald's avatar Keith Donald Committed by Mic
Browse files

appointments

parent 09013641
No related branches found
No related tags found
No related merge requests found
Showing
with 252 additions and 13 deletions
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;
}
}
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
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
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;
}
}
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";
}
}
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;
}
}
......@@ -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
......@@ -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;
}
......
<%@ 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
<%@ 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
......@@ -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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment