mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 23:35:50 +00:00
refactor domain model to support vet available hours
This commit is contained in:
parent
2b5b1a5580
commit
0ecde8f3ea
7 changed files with 90 additions and 5 deletions
|
@ -0,0 +1,59 @@
|
||||||
|
/*
|
||||||
|
* Copyright 2002-2013 the original author or authors.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.springframework.samples.petclinic.vet;
|
||||||
|
|
||||||
|
import org.springframework.format.annotation.DateTimeFormat;
|
||||||
|
import org.springframework.samples.petclinic.model.BaseEntity;
|
||||||
|
|
||||||
|
import javax.persistence.*;
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Models a {@link AvailableHour AvailableHour} for each {@link Vet Vet}
|
||||||
|
*
|
||||||
|
* @author Diogo Santos
|
||||||
|
*/
|
||||||
|
@Entity
|
||||||
|
@Table(name = "available_hour")
|
||||||
|
public class AvailableHour extends BaseEntity implements Serializable {
|
||||||
|
|
||||||
|
@Column(name = "time_date")
|
||||||
|
@DateTimeFormat(pattern = "yyyy-MM-dd'T'HH:mm")
|
||||||
|
private LocalDateTime timeDate;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "vet_id")
|
||||||
|
private Vet vet;
|
||||||
|
|
||||||
|
public AvailableHour() {}
|
||||||
|
|
||||||
|
public Vet getVet() {
|
||||||
|
return vet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVet(Vet vet) {
|
||||||
|
this.vet = vet;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LocalDateTime getTimeDate() {
|
||||||
|
return timeDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTimeDate(LocalDateTime timeDate) {
|
||||||
|
this.timeDate = timeDate;
|
||||||
|
}
|
||||||
|
}
|
|
@ -19,6 +19,7 @@ import java.util.Collection;
|
||||||
|
|
||||||
import org.springframework.cache.annotation.Cacheable;
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.dao.DataAccessException;
|
import org.springframework.dao.DataAccessException;
|
||||||
|
import org.springframework.data.jpa.repository.Query;
|
||||||
import org.springframework.data.repository.Repository;
|
import org.springframework.data.repository.Repository;
|
||||||
import org.springframework.transaction.annotation.Transactional;
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
|
|
|
@ -5,6 +5,13 @@ INSERT INTO vets VALUES (4, 'Rafael', 'Ortega');
|
||||||
INSERT INTO vets VALUES (5, 'Henry', 'Stevens');
|
INSERT INTO vets VALUES (5, 'Henry', 'Stevens');
|
||||||
INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins');
|
INSERT INTO vets VALUES (6, 'Sharon', 'Jenkins');
|
||||||
|
|
||||||
|
INSERT INTO available_hour VALUES (1, 1, '2018-10-23 14:00:00');
|
||||||
|
INSERT INTO available_hour VALUES (2, 1, '2018-10-23 15:00:00');
|
||||||
|
INSERT INTO available_hour VALUES (3, 1, '2018-10-23 16:00:00');
|
||||||
|
INSERT INTO available_hour VALUES (4, 2, '2018-10-23 14:00:00');
|
||||||
|
INSERT INTO available_hour VALUES (5, 2, '2018-10-23 15:00:00');
|
||||||
|
INSERT INTO available_hour VALUES (6, 2, '2018-10-23 16:00:00');
|
||||||
|
|
||||||
INSERT INTO specialties VALUES (1, 'radiology');
|
INSERT INTO specialties VALUES (1, 'radiology');
|
||||||
INSERT INTO specialties VALUES (2, 'surgery');
|
INSERT INTO specialties VALUES (2, 'surgery');
|
||||||
INSERT INTO specialties VALUES (3, 'dentistry');
|
INSERT INTO specialties VALUES (3, 'dentistry');
|
||||||
|
@ -47,7 +54,7 @@ INSERT INTO pets VALUES (11, 'Freddy', '2010-03-09', 5, 9);
|
||||||
INSERT INTO pets VALUES (12, 'Lucky', '2010-06-24', 2, 10);
|
INSERT INTO pets VALUES (12, 'Lucky', '2010-06-24', 2, 10);
|
||||||
INSERT INTO pets VALUES (13, 'Sly', '2012-06-08', 1, 10);
|
INSERT INTO pets VALUES (13, 'Sly', '2012-06-08', 1, 10);
|
||||||
|
|
||||||
INSERT INTO visits VALUES (1, 7, '2013-01-01', 'rabies shot');
|
INSERT INTO visits VALUES (1, 1, 1, '2018-10-23 14:00:00', 'rabies shot');
|
||||||
INSERT INTO visits VALUES (2, 8, '2013-01-02', 'rabies shot');
|
INSERT INTO visits VALUES (2, 1, 1, '2018-10-23 15:00:00', 'rabies shot');
|
||||||
INSERT INTO visits VALUES (3, 8, '2013-01-03', 'neutered');
|
INSERT INTO visits VALUES (3, 2, 2, '2018-10-23 14:00:00', 'neutered');
|
||||||
INSERT INTO visits VALUES (4, 7, '2013-01-04', 'spayed');
|
INSERT INTO visits VALUES (4, 4, 2, '2018-10-23 16:00:00', 'spayed');
|
||||||
|
|
|
@ -57,8 +57,18 @@ CREATE INDEX pets_name ON pets (name);
|
||||||
CREATE TABLE visits (
|
CREATE TABLE visits (
|
||||||
id INTEGER IDENTITY PRIMARY KEY,
|
id INTEGER IDENTITY PRIMARY KEY,
|
||||||
pet_id INTEGER NOT NULL,
|
pet_id INTEGER NOT NULL,
|
||||||
visit_date DATE,
|
vet_id INTEGER NOT NULL,
|
||||||
|
visit_date TIMESTAMP,
|
||||||
description VARCHAR(255)
|
description VARCHAR(255)
|
||||||
);
|
);
|
||||||
ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
ALTER TABLE visits ADD CONSTRAINT fk_visits_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
||||||
|
ALTER TABLE visits ADD CONSTRAINT fk_vet_visits FOREIGN KEY (vet_id) REFERENCES vets (id);
|
||||||
CREATE INDEX visits_pet_id ON visits (pet_id);
|
CREATE INDEX visits_pet_id ON visits (pet_id);
|
||||||
|
|
||||||
|
CREATE TABLE available_hour (
|
||||||
|
id INTEGER IDENTITY PRIMARY KEY,
|
||||||
|
vet_id INTEGER NOT NULL,
|
||||||
|
time_date TIMESTAMP
|
||||||
|
);
|
||||||
|
ALTER TABLE available_hour ADD CONSTRAINT fk_vet_available_hour FOREIGN KEY (vet_id) REFERENCES vets (id);
|
||||||
|
CREATE INDEX available_hour_vet_id ON available_hour (vet_id);
|
||||||
|
|
|
@ -12,6 +12,9 @@
|
||||||
<input th:case="'date'" class="form-control" type="text" th:field="*{__${name}__}"
|
<input th:case="'date'" class="form-control" type="text" th:field="*{__${name}__}"
|
||||||
placeholder="YYYY-MM-DD" title="Enter a date in this format: YYYY-MM-DD"
|
placeholder="YYYY-MM-DD" title="Enter a date in this format: YYYY-MM-DD"
|
||||||
pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))"/>
|
pattern="(?:19|20)[0-9]{2}-(?:(?:0[1-9]|1[0-2])-(?:0[1-9]|1[0-9]|2[0-9])|(?:(?!02)(?:0[1-9]|1[0-2])-(?:30))|(?:(?:0[13578]|1[02])-31))"/>
|
||||||
|
<input th:case="'datetime'" class="form-control" type="text" th:field="*{__${name}__}"
|
||||||
|
placeholder="YYYY-MM-DD HH:MM" title="Enter a date in this format: YYYY-MM-DD HH:MM"
|
||||||
|
/>
|
||||||
</div>
|
</div>
|
||||||
<span th:if="${valid}"
|
<span th:if="${valid}"
|
||||||
class="glyphicon glyphicon-ok form-control-feedback"
|
class="glyphicon glyphicon-ok form-control-feedback"
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
<table id="owners" class="table table-striped">
|
<table id="owners" class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
|
<th>id</th>
|
||||||
<th style="width: 150px;">Name</th>
|
<th style="width: 150px;">Name</th>
|
||||||
<th style="width: 200px;">Address</th>
|
<th style="width: 200px;">Address</th>
|
||||||
<th>City</th>
|
<th>City</th>
|
||||||
|
@ -18,6 +19,7 @@
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr th:each="owner : ${selections}">
|
<tr th:each="owner : ${selections}">
|
||||||
|
<td th:text="${owner.id}"/>
|
||||||
<td>
|
<td>
|
||||||
<a th:href="@{/owners/__${owner.id}__}" th:text="${owner.firstName + ' ' + owner.lastName}"/></a>
|
<a th:href="@{/owners/__${owner.id}__}" th:text="${owner.firstName + ' ' + owner.lastName}"/></a>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -12,6 +12,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<th>Name</th>
|
<th>Name</th>
|
||||||
<th>Specialties</th>
|
<th>Specialties</th>
|
||||||
|
<th>Hours</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
@ -20,6 +21,8 @@
|
||||||
<td><span th:each="specialty : ${vet.specialties}"
|
<td><span th:each="specialty : ${vet.specialties}"
|
||||||
th:text="${specialty.name + ' '}" /> <span
|
th:text="${specialty.name + ' '}" /> <span
|
||||||
th:if="${vet.nrOfSpecialties == 0}">none</span></td>
|
th:if="${vet.nrOfSpecialties == 0}">none</span></td>
|
||||||
|
<td><span th:each="hour : ${vet.availableHours}"
|
||||||
|
th:text="${#temporals.format(hour.getTimeDate(), 'yyyy-MM-dd HH-mm') + ' | '}" /></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue