diff --git a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java index 3038bce3a90..82d3bb37413 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java +++ b/src/main/java/org/springframework/samples/petclinic/model/BaseEntity.java @@ -22,6 +22,8 @@ import jakarta.persistence.Id; import jakarta.persistence.MappedSuperclass; +import static java.util.UUID.randomUUID; + /** * Simple JavaBean domain object with an id property. Used as a base class for objects * needing this property. @@ -36,6 +38,8 @@ public class BaseEntity implements Serializable { @GeneratedValue(strategy = GenerationType.IDENTITY) private Integer id; + private final String uuid = randomUUID().toString(); + public Integer getId() { return id; } @@ -48,4 +52,8 @@ public boolean isNew() { return this.id == null; } + public String getUuid() { + return uuid; + } + } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 3240814a6f1..1eb77c3c4dc 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -23,6 +23,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestParam; import org.springframework.web.bind.annotation.ResponseBody; @@ -75,4 +76,10 @@ private Page findPaginated(int page) { return vets; } + @GetMapping({ "/vets/{uuid}" }) + public String getVetById(@PathVariable("uuid") String uuid, Model model) { + model.addAttribute("vet", this.vetRepository.findByUuid(uuid)); + return "vets/vetDetails"; + } + } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java index 8b9e0823c86..76d1f7ec0a0 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java @@ -55,4 +55,13 @@ public interface VetRepository extends Repository { @Cacheable("vets") Page findAll(Pageable pageable) throws DataAccessException; + /** + * Get Vet by uuid + * @param uuid this is the UUID generated for the Vet in persisted storage + * @return found Vet + * @throws DataAccessException + */ + @Transactional(readOnly = true) + Vet findByUuid(String uuid) throws DataAccessException; + } diff --git a/src/main/resources/db/h2/data.sql b/src/main/resources/db/h2/data.sql index f232b1361f4..0bae9bbec8c 100644 --- a/src/main/resources/db/h2/data.sql +++ b/src/main/resources/db/h2/data.sql @@ -1,53 +1,53 @@ -INSERT INTO vets VALUES (default, 'James', 'Carter'); -INSERT INTO vets VALUES (default, 'Helen', 'Leary'); -INSERT INTO vets VALUES (default, 'Linda', 'Douglas'); -INSERT INTO vets VALUES (default, 'Rafael', 'Ortega'); -INSERT INTO vets VALUES (default, 'Henry', 'Stevens'); -INSERT INTO vets VALUES (default, 'Sharon', 'Jenkins'); +INSERT INTO vets (id, first_name, last_name) VALUES (default, 'James', 'Carter'); +INSERT INTO vets (id, first_name, last_name) VALUES (default, 'Helen', 'Leary'); +INSERT INTO vets (id, first_name, last_name) VALUES (default, 'Linda', 'Douglas'); +INSERT INTO vets (id, first_name, last_name) VALUES (default, 'Rafael', 'Ortega'); +INSERT INTO vets (id, first_name, last_name) VALUES (default, 'Henry', 'Stevens'); +INSERT INTO vets (id, first_name, last_name) VALUES (default, 'Sharon', 'Jenkins'); -INSERT INTO specialties VALUES (default, 'radiology'); -INSERT INTO specialties VALUES (default, 'surgery'); -INSERT INTO specialties VALUES (default, 'dentistry'); +INSERT INTO specialties (id, name) VALUES (default, 'radiology'); +INSERT INTO specialties (id, name) VALUES (default, 'surgery'); +INSERT INTO specialties (id, name) VALUES (default, 'dentistry'); -INSERT INTO vet_specialties VALUES (2, 1); -INSERT INTO vet_specialties VALUES (3, 2); -INSERT INTO vet_specialties VALUES (3, 3); -INSERT INTO vet_specialties VALUES (4, 2); -INSERT INTO vet_specialties VALUES (5, 1); +INSERT INTO vet_specialties (vet_id, specialty_id) VALUES (2, 1); +INSERT INTO vet_specialties (vet_id, specialty_id) VALUES (3, 2); +INSERT INTO vet_specialties (vet_id, specialty_id) VALUES (3, 3); +INSERT INTO vet_specialties (vet_id, specialty_id) VALUES (4, 2); +INSERT INTO vet_specialties (vet_id, specialty_id) VALUES (5, 1); -INSERT INTO types VALUES (default, 'cat'); -INSERT INTO types VALUES (default, 'dog'); -INSERT INTO types VALUES (default, 'lizard'); -INSERT INTO types VALUES (default, 'snake'); -INSERT INTO types VALUES (default, 'bird'); -INSERT INTO types VALUES (default, 'hamster'); +INSERT INTO types (id, name) VALUES (default, 'cat'); +INSERT INTO types (id, name) VALUES (default, 'dog'); +INSERT INTO types (id, name) VALUES (default, 'lizard'); +INSERT INTO types (id, name) VALUES (default, 'snake'); +INSERT INTO types (id, name) VALUES (default, 'bird'); +INSERT INTO types (id, name) VALUES (default, 'hamster'); -INSERT INTO owners VALUES (default, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); -INSERT INTO owners VALUES (default, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); -INSERT INTO owners VALUES (default, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); -INSERT INTO owners VALUES (default, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); -INSERT INTO owners VALUES (default, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); -INSERT INTO owners VALUES (default, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); -INSERT INTO owners VALUES (default, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); -INSERT INTO owners VALUES (default, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); -INSERT INTO owners VALUES (default, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); -INSERT INTO owners VALUES (default, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); +INSERT INTO owners (id, first_name, last_name, address, city, telephone) VALUES (default, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); -INSERT INTO pets VALUES (default, 'Leo', '2010-09-07', 1, 1); -INSERT INTO pets VALUES (default, 'Basil', '2012-08-06', 6, 2); -INSERT INTO pets VALUES (default, 'Rosy', '2011-04-17', 2, 3); -INSERT INTO pets VALUES (default, 'Jewel', '2010-03-07', 2, 3); -INSERT INTO pets VALUES (default, 'Iggy', '2010-11-30', 3, 4); -INSERT INTO pets VALUES (default, 'George', '2010-01-20', 4, 5); -INSERT INTO pets VALUES (default, 'Samantha', '2012-09-04', 1, 6); -INSERT INTO pets VALUES (default, 'Max', '2012-09-04', 1, 6); -INSERT INTO pets VALUES (default, 'Lucky', '2011-08-06', 5, 7); -INSERT INTO pets VALUES (default, 'Mulligan', '2007-02-24', 2, 8); -INSERT INTO pets VALUES (default, 'Freddy', '2010-03-09', 5, 9); -INSERT INTO pets VALUES (default, 'Lucky', '2010-06-24', 2, 10); -INSERT INTO pets VALUES (default, 'Sly', '2012-06-08', 1, 10); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Leo', '2010-09-07', 1, 1); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Basil', '2012-08-06', 6, 2); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Rosy', '2011-04-17', 2, 3); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Jewel', '2010-03-07', 2, 3); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Iggy', '2010-11-30', 3, 4); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'George', '2010-01-20', 4, 5); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Samantha', '2012-09-04', 1, 6); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Max', '2012-09-04', 1, 6); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Lucky', '2011-08-06', 5, 7); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Mulligan', '2007-02-24', 2, 8); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Freddy', '2010-03-09', 5, 9); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Lucky', '2010-06-24', 2, 10); +INSERT INTO pets (id, name, birth_date, type_id, owner_id) VALUES (default, 'Sly', '2012-06-08', 1, 10); -INSERT INTO visits VALUES (default, 7, '2013-01-01', 'rabies shot'); -INSERT INTO visits VALUES (default, 8, '2013-01-02', 'rabies shot'); -INSERT INTO visits VALUES (default, 8, '2013-01-03', 'neutered'); -INSERT INTO visits VALUES (default, 7, '2013-01-04', 'spayed'); +INSERT INTO visits (id, pet_id, visit_date, description) VALUES (default, 7, '2013-01-01', 'rabies shot'); +INSERT INTO visits (id, pet_id, visit_date, description) VALUES (default, 8, '2013-01-02', 'rabies shot'); +INSERT INTO visits (id, pet_id, visit_date, description) VALUES (default, 8, '2013-01-03', 'neutered'); +INSERT INTO visits (id, pet_id, visit_date, description) VALUES (default, 7, '2013-01-04', 'spayed'); diff --git a/src/main/resources/db/h2/schema.sql b/src/main/resources/db/h2/schema.sql index 4a6c322cbcc..100ee2e1cbd 100644 --- a/src/main/resources/db/h2/schema.sql +++ b/src/main/resources/db/h2/schema.sql @@ -9,6 +9,7 @@ DROP TABLE owners IF EXISTS; CREATE TABLE vets ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID first_name VARCHAR(30), last_name VARCHAR(30) ); @@ -16,6 +17,7 @@ CREATE INDEX vets_last_name ON vets (last_name); CREATE TABLE specialties ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID name VARCHAR(80) ); CREATE INDEX specialties_name ON specialties (name); @@ -29,12 +31,14 @@ ALTER TABLE vet_specialties ADD CONSTRAINT fk_vet_specialties_specialties FOREIG CREATE TABLE types ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID name VARCHAR(80) ); CREATE INDEX types_name ON types (name); CREATE TABLE owners ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID first_name VARCHAR(30), last_name VARCHAR_IGNORECASE(30), address VARCHAR(255), @@ -45,6 +49,7 @@ CREATE INDEX owners_last_name ON owners (last_name); CREATE TABLE pets ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID name VARCHAR(30), birth_date DATE, type_id INTEGER NOT NULL, @@ -56,6 +61,7 @@ CREATE INDEX pets_name ON pets (name); CREATE TABLE visits ( id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, + uuid UUID DEFAULT RANDOM_UUID() NOT NULL UNIQUE, -- Added UUID pet_id INTEGER, visit_date DATE, description VARCHAR(255) diff --git a/src/main/resources/db/mysql/data.sql b/src/main/resources/db/mysql/data.sql index 3f1dcf8ea16..e0dc5be7911 100644 --- a/src/main/resources/db/mysql/data.sql +++ b/src/main/resources/db/mysql/data.sql @@ -1,53 +1,46 @@ -INSERT IGNORE INTO vets VALUES (1, 'James', 'Carter'); -INSERT IGNORE INTO vets VALUES (2, 'Helen', 'Leary'); -INSERT IGNORE INTO vets VALUES (3, 'Linda', 'Douglas'); -INSERT IGNORE INTO vets VALUES (4, 'Rafael', 'Ortega'); -INSERT IGNORE INTO vets VALUES (5, 'Henry', 'Stevens'); -INSERT IGNORE INTO vets VALUES (6, 'Sharon', 'Jenkins'); +INSERT IGNORE INTO specialties (id, name, uuid) VALUES (1, 'radiology', '0a6d7430-1234-4c3a-bc34-65b0ef2f7d48'); +INSERT IGNORE INTO specialties (id, name, uuid) VALUES (2, 'surgery', 'e3a10a00-4567-4c98-89ba-d7bb3e9a999a'); +INSERT IGNORE INTO specialties (id, name, uuid) VALUES (3, 'dentistry', '1a78df21-5678-4b5a-ae13-88f72065b4b1'); -INSERT IGNORE INTO specialties VALUES (1, 'radiology'); -INSERT IGNORE INTO specialties VALUES (2, 'surgery'); -INSERT IGNORE INTO specialties VALUES (3, 'dentistry'); +INSERT IGNORE INTO vet_specialties (vet_id, specialty_id) VALUES (2, 1); +INSERT IGNORE INTO vet_specialties (vet_id, specialty_id) VALUES (3, 2); +INSERT IGNORE INTO vet_specialties (vet_id, specialty_id) VALUES (3, 3); +INSERT IGNORE INTO vet_specialties (vet_id, specialty_id) VALUES (4, 2); +INSERT IGNORE INTO vet_specialties (vet_id, specialty_id) VALUES (5, 1); -INSERT IGNORE INTO vet_specialties VALUES (2, 1); -INSERT IGNORE INTO vet_specialties VALUES (3, 2); -INSERT IGNORE INTO vet_specialties VALUES (3, 3); -INSERT IGNORE INTO vet_specialties VALUES (4, 2); -INSERT IGNORE INTO vet_specialties VALUES (5, 1); +INSERT IGNORE INTO types (id, name, uuid) VALUES (1, 'cat', '9a7b1789-5678-4c23-b90c-ef3f82c3bcde'); +INSERT IGNORE INTO types (id, name, uuid) VALUES (2, 'dog', '3b8a2a12-4567-4c56-bb12-d3b50efc23b2'); +INSERT IGNORE INTO types (id, name, uuid) VALUES (3, 'lizard', '5d04f9ac-3456-4c68-8f10-0c5d8e91f6b3'); +INSERT IGNORE INTO types (id, name, uuid) VALUES (4, 'snake', 'fa0d4bce-6789-4c9a-b12f-df2b34d5e678'); +INSERT IGNORE INTO types (id, name, uuid) VALUES (5, 'bird', '7c4e2a79-1234-4a23-bc12-f7e8a6e2c9a1'); +INSERT IGNORE INTO types (id, name, uuid) VALUES (6, 'hamster', 'b0f9a8a7-6789-4e6f-9c10-c45d1c8d567a'); -INSERT IGNORE INTO types VALUES (1, 'cat'); -INSERT IGNORE INTO types VALUES (2, 'dog'); -INSERT IGNORE INTO types VALUES (3, 'lizard'); -INSERT IGNORE INTO types VALUES (4, 'snake'); -INSERT IGNORE INTO types VALUES (5, 'bird'); -INSERT IGNORE INTO types VALUES (6, 'hamster'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023', '0bc6a123-8c4e-4e2b-bc45-7a3e1d5e0236'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749', 'abc4e572-8a4d-41d1-bc67-d7c4e2c3b123'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763', 'de5f4b78-7a9b-4c12-8a3f-8e2c34d6c4b5'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198', '2a4d9b89-1234-4a56-8c4f-7a5d2b3d6c2e'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765', 'bc7f9a9a-5678-4e3d-8c5a-3b9e7a5f1234'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654', '567f1234-1234-4b6a-8d5e-3a5f9e8b6a2b'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387', '3b5a9f34-3456-4567-8a23-d5e7a12c3f67'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683', 'a2d3c456-4b56-4567-8a34-d4e7f23b6a7e'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435', 'de34a124-4e3f-4c2d-b123-8a4d1c7e8a7b'); +INSERT IGNORE INTO owners (id, first_name, last_name, address, city, telephone, uuid) VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487', '5f6b7a5c-8b9e-4f23-8d67-d5e7c2c3a5d9'); -INSERT IGNORE INTO owners VALUES (1, 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023'); -INSERT IGNORE INTO owners VALUES (2, 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749'); -INSERT IGNORE INTO owners VALUES (3, 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763'); -INSERT IGNORE INTO owners VALUES (4, 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198'); -INSERT IGNORE INTO owners VALUES (5, 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765'); -INSERT IGNORE INTO owners VALUES (6, 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654'); -INSERT IGNORE INTO owners VALUES (7, 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387'); -INSERT IGNORE INTO owners VALUES (8, 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683'); -INSERT IGNORE INTO owners VALUES (9, 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435'); -INSERT IGNORE INTO owners VALUES (10, 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (1, 'Leo', '2000-09-07', 1, 1, '67a5d89a-9b12-4a23-9f23-d7e8c6a5b12f'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (2, 'Basil', '2002-08-06', 6, 2, '1b7a5d9a-4e7f-4a23-8b9f-7a3e6b2d8e7f'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (3, 'Rosy', '2001-04-17', 2, 3, '5b7a4f9a-5678-4c2d-9f45-7e5d1f23b12f'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (4, 'Jewel', '2000-03-07', 2, 3, '6b7a4c9d-8b9e-4c12-9d34-e7a5f9b12c34'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (5, 'Iggy', '2000-11-30', 3, 4, 'de34b2f9-4567-4a23-9f6e-d3e7a5d6c7a9'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (6, 'George', '2000-01-20', 4, 5, '67a7d3f9-4c6e-4d12-8f9b-9c3d8e5f7a2d'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (7, 'Samantha', '1995-09-04', 1, 6, '9a5b7e34-4d67-4a12-bc23-8e5f4d7b3c2d'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (8, 'Max', '1995-09-04', 1, 6, '1a9d3e5b-1234-4d23-8b7e-c5d3a8e2b5d7'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (9, 'Lucky', '1999-08-06', 5, 7, '5a7d9e2f-9c8e-4f23-9b67-c7a3e5d9b123'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (10, 'Mulligan', '1997-02-24', 2, 8, '123b4e67-6789-4f12-9c5e-9d3b7a5e2c8d'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (11, 'Freddy', '2000-03-09', 5, 9, '7c5d1234-4a67-4f12-8c67-8e3f5a6b9d2e'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (12, 'Lucky', '2000-06-24', 2, 10, '67c5a12e-4a9e-4b6f-8d23-9e5f7b3c5d8e'); +INSERT IGNORE INTO pets (id, name, birth_date, type_id, owner_id, uuid) VALUES (13, 'Sly', '2002-06-08', 1, 10, '9a6b7f34-5678-4c2d-9f3e-5a7d1b6c4e23'); -INSERT IGNORE INTO pets VALUES (1, 'Leo', '2000-09-07', 1, 1); -INSERT IGNORE INTO pets VALUES (2, 'Basil', '2002-08-06', 6, 2); -INSERT IGNORE INTO pets VALUES (3, 'Rosy', '2001-04-17', 2, 3); -INSERT IGNORE INTO pets VALUES (4, 'Jewel', '2000-03-07', 2, 3); -INSERT IGNORE INTO pets VALUES (5, 'Iggy', '2000-11-30', 3, 4); -INSERT IGNORE INTO pets VALUES (6, 'George', '2000-01-20', 4, 5); -INSERT IGNORE INTO pets VALUES (7, 'Samantha', '1995-09-04', 1, 6); -INSERT IGNORE INTO pets VALUES (8, 'Max', '1995-09-04', 1, 6); -INSERT IGNORE INTO pets VALUES (9, 'Lucky', '1999-08-06', 5, 7); -INSERT IGNORE INTO pets VALUES (10, 'Mulligan', '1997-02-24', 2, 8); -INSERT IGNORE INTO pets VALUES (11, 'Freddy', '2000-03-09', 5, 9); -INSERT IGNORE INTO pets VALUES (12, 'Lucky', '2000-06-24', 2, 10); -INSERT IGNORE INTO pets VALUES (13, 'Sly', '2002-06-08', 1, 10); - -INSERT IGNORE INTO visits VALUES (1, 7, '2010-03-04', 'rabies shot'); -INSERT IGNORE INTO visits VALUES (2, 8, '2011-03-04', 'rabies shot'); -INSERT IGNORE INTO visits VALUES (3, 8, '2009-06-04', 'neutered'); -INSERT IGNORE INTO visits VALUES (4, 7, '2008-09-04', 'spayed'); +INSERT IGNORE INTO visits (id, pet_id, visit_date, description, uuid) VALUES (1, 7, '2010-03-04', 'rabies shot', '7a9e1b34-4f12-4e2b-8a5d-9f2c6a7b9d3e'); +INSERT IGNORE INTO visits (id, pet_id, visit_date, description, uuid) VALUES (2, 8, '2011-03-04', 'rabies shot', '67a5b9e1-4c56-4e2d-9b6f-c7a5d8e4f3d7'); +INSERT IGNORE INTO visits (id, pet_id, visit_date, description, uuid) VALUES (3, 8, '2009-06-04', 'neutered', '5c7a1e34-8b9e-4d2f-9c56-5e2f7d8b9d6c'); +INSERT IGNORE INTO visits (id, pet_id, visit_date, description, uuid) VALUES (4, 7, '2008-09-04', 'spayed', '9a5d7b12-8e34-4f23-9b6f-8c3d1a6f7b2e'); diff --git a/src/main/resources/db/mysql/schema.sql b/src/main/resources/db/mysql/schema.sql index 2591a516dea..23a6fd5892c 100644 --- a/src/main/resources/db/mysql/schema.sql +++ b/src/main/resources/db/mysql/schema.sql @@ -1,5 +1,6 @@ CREATE TABLE IF NOT EXISTS vets ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE, first_name VARCHAR(30), last_name VARCHAR(30), INDEX(last_name) @@ -7,6 +8,7 @@ CREATE TABLE IF NOT EXISTS vets ( CREATE TABLE IF NOT EXISTS specialties ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE, name VARCHAR(80), INDEX(name) ) engine=InnoDB; @@ -21,12 +23,14 @@ CREATE TABLE IF NOT EXISTS vet_specialties ( CREATE TABLE IF NOT EXISTS types ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE, name VARCHAR(80), INDEX(name) ) engine=InnoDB; CREATE TABLE IF NOT EXISTS owners ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE, first_name VARCHAR(30), last_name VARCHAR(30), address VARCHAR(255), @@ -37,6 +41,7 @@ CREATE TABLE IF NOT EXISTS owners ( CREATE TABLE IF NOT EXISTS pets ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE, name VARCHAR(30), birth_date DATE, type_id INT(4) UNSIGNED NOT NULL, @@ -48,6 +53,7 @@ CREATE TABLE IF NOT EXISTS pets ( CREATE TABLE IF NOT EXISTS visits ( id INT(4) UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, + uuid CHAR(36) NOT NULL DEFAULT (UUID()) UNIQUE, pet_id INT(4) UNSIGNED, visit_date DATE, description VARCHAR(255), diff --git a/src/main/resources/db/postgres/data.sql b/src/main/resources/db/postgres/data.sql index 5b53366ac05..b83a3a7567e 100644 --- a/src/main/resources/db/postgres/data.sql +++ b/src/main/resources/db/postgres/data.sql @@ -1,53 +1,187 @@ -INSERT INTO vets (first_name, last_name) SELECT 'James', 'Carter' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=1); -INSERT INTO vets (first_name, last_name) SELECT 'Helen', 'Leary' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=2); -INSERT INTO vets (first_name, last_name) SELECT 'Linda', 'Douglas' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=3); -INSERT INTO vets (first_name, last_name) SELECT 'Rafael', 'Ortega' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=4); -INSERT INTO vets (first_name, last_name) SELECT 'Henry', 'Stevens' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=5); -INSERT INTO vets (first_name, last_name) SELECT 'Sharon', 'Jenkins' WHERE NOT EXISTS (SELECT * FROM vets WHERE id=6); - -INSERT INTO specialties (name) SELECT 'radiology' WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='radiology'); -INSERT INTO specialties (name) SELECT 'surgery' WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='surgery'); -INSERT INTO specialties (name) SELECT 'dentistry' WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='dentistry'); - -INSERT INTO vet_specialties VALUES (2, 1) ON CONFLICT (vet_id, specialty_id) DO NOTHING; -INSERT INTO vet_specialties VALUES (3, 2) ON CONFLICT (vet_id, specialty_id) DO NOTHING; -INSERT INTO vet_specialties VALUES (3, 3) ON CONFLICT (vet_id, specialty_id) DO NOTHING; -INSERT INTO vet_specialties VALUES (4, 2) ON CONFLICT (vet_id, specialty_id) DO NOTHING; -INSERT INTO vet_specialties VALUES (5, 1) ON CONFLICT (vet_id, specialty_id) DO NOTHING; - -INSERT INTO types (name) SELECT 'cat' WHERE NOT EXISTS (SELECT * FROM types WHERE name='cat'); -INSERT INTO types (name) SELECT 'dog' WHERE NOT EXISTS (SELECT * FROM types WHERE name='dog'); -INSERT INTO types (name) SELECT 'lizard' WHERE NOT EXISTS (SELECT * FROM types WHERE name='lizard'); -INSERT INTO types (name) SELECT 'snake' WHERE NOT EXISTS (SELECT * FROM types WHERE name='snake'); -INSERT INTO types (name) SELECT 'bird' WHERE NOT EXISTS (SELECT * FROM types WHERE name='bird'); -INSERT INTO types (name) SELECT 'hamster' WHERE NOT EXISTS (SELECT * FROM types WHERE name='hamster'); - -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=1); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=2); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=3); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=4); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=5); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=6); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=7); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=8); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=9); -INSERT INTO owners (first_name, last_name, address, city, telephone) SELECT 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487' WHERE NOT EXISTS (SELECT * FROM owners WHERE id=10); - -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Leo', '2000-09-07', 1, 1 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=1); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Basil', '2002-08-06', 6, 2 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=2); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Rosy', '2001-04-17', 2, 3 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=3); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Jewel', '2000-03-07', 2, 3 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=4); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Iggy', '2000-11-30', 3, 4 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=5); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'George', '2000-01-20', 4, 5 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=6); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Samantha', '1995-09-04', 1, 6 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=7); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Max', '1995-09-04', 1, 6 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=8); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Lucky', '1999-08-06', 5, 7 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=9); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Mulligan', '1997-02-24', 2, 8 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=10); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Freddy', '2000-03-09', 5, 9 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=11); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Lucky', '2000-06-24', 2, 10 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=12); -INSERT INTO pets (name, birth_date, type_id, owner_id) SELECT 'Sly', '2002-06-08', 1, 10 WHERE NOT EXISTS (SELECT * FROM pets WHERE id=13); - -INSERT INTO visits (pet_id, visit_date, description) SELECT 7, '2010-03-04', 'rabies shot' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=1); -INSERT INTO visits (pet_id, visit_date, description) SELECT 8, '2011-03-04', 'rabies shot' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=2); -INSERT INTO visits (pet_id, visit_date, description) SELECT 8, '2009-06-04', 'neutered' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=3); -INSERT INTO visits (pet_id, visit_date, description) SELECT 7, '2008-09-04', 'spayed' WHERE NOT EXISTS (SELECT * FROM visits WHERE id=4); +INSERT INTO vets (first_name, last_name, uuid) +SELECT 'James', 'Carter', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM vets WHERE id=1); + +INSERT INTO vets (first_name, last_name, uuid) +SELECT 'Helen', 'Leary', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM vets WHERE id=2); + +INSERT INTO vets (first_name, last_name, uuid) +SELECT 'Linda', 'Douglas', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM vets WHERE id=3); + +INSERT INTO vets (first_name, last_name, uuid) +SELECT 'Rafael', 'Ortega', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM vets WHERE id=4); + +INSERT INTO vets (first_name, last_name, uuid) +SELECT 'Henry', 'Stevens', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM vets WHERE id=5); + +INSERT INTO vets (first_name, last_name, uuid) +SELECT 'Sharon', 'Jenkins', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM vets WHERE id=6); + +INSERT INTO specialties (name, uuid) +SELECT 'radiology', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='radiology'); + +INSERT INTO specialties (name, uuid) +SELECT 'surgery', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='surgery'); + +INSERT INTO specialties (name, uuid) +SELECT 'dentistry', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM specialties WHERE name='dentistry'); + +INSERT INTO vet_specialties (vet_id, specialty_id) +VALUES (2, 1) +ON CONFLICT (vet_id, specialty_id) DO NOTHING; + +INSERT INTO vet_specialties (vet_id, specialty_id) +VALUES (3, 2) +ON CONFLICT (vet_id, specialty_id) DO NOTHING; + +INSERT INTO vet_specialties (vet_id, specialty_id) +VALUES (3, 3) +ON CONFLICT (vet_id, specialty_id) DO NOTHING; + +INSERT INTO vet_specialties (vet_id, specialty_id) +VALUES (4, 2) +ON CONFLICT (vet_id, specialty_id) DO NOTHING; + +INSERT INTO vet_specialties (vet_id, specialty_id) +VALUES (5, 1) +ON CONFLICT (vet_id, specialty_id) DO NOTHING; + +INSERT INTO types (name, uuid) +SELECT 'cat', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM types WHERE name='cat'); + +INSERT INTO types (name, uuid) +SELECT 'dog', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM types WHERE name='dog'); + +INSERT INTO types (name, uuid) +SELECT 'lizard', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM types WHERE name='lizard'); + +INSERT INTO types (name, uuid) +SELECT 'snake', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM types WHERE name='snake'); + +INSERT INTO types (name, uuid) +SELECT 'bird', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM types WHERE name='bird'); + +INSERT INTO types (name, uuid) +SELECT 'hamster', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM types WHERE name='hamster'); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'George', 'Franklin', '110 W. Liberty St.', 'Madison', '6085551023', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=1); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Betty', 'Davis', '638 Cardinal Ave.', 'Sun Prairie', '6085551749', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=2); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Eduardo', 'Rodriquez', '2693 Commerce St.', 'McFarland', '6085558763', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=3); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Harold', 'Davis', '563 Friendly St.', 'Windsor', '6085553198', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=4); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Peter', 'McTavish', '2387 S. Fair Way', 'Madison', '6085552765', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=5); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Jean', 'Coleman', '105 N. Lake St.', 'Monona', '6085552654', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=6); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Jeff', 'Black', '1450 Oak Blvd.', 'Monona', '6085555387', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=7); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Maria', 'Escobito', '345 Maple St.', 'Madison', '6085557683', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=8); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'David', 'Schroeder', '2749 Blackhawk Trail', 'Madison', '6085559435', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=9); + +INSERT INTO owners (first_name, last_name, address, city, telephone, uuid) +SELECT 'Carlos', 'Estaban', '2335 Independence La.', 'Waunakee', '6085555487', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM owners WHERE id=10); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Leo', '2000-09-07', 1, 1, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=1); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Basil', '2002-08-06', 6, 2, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=2); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Rosy', '2001-04-17', 2, 3, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=3); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Jewel', '2000-03-07', 2, 3, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=4); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Iggy', '2000-11-30', 3, 4, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=5); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'George', '2000-01-20', 4, 5, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=6); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Samantha', '1995-09-04', 1, 6, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=7); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Max', '1995-09-04', 1, 6, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=8); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Lucky', '1999-08-06', 5, 7, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=9); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Mulligan', '1997-02-24', 2, 8, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=10); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Freddy', '2000-03-09', 5, 9, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=11); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Lucky', '2000-06-24', 2, 10, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=12); + +INSERT INTO pets (name, birth_date, type_id, owner_id, uuid) +SELECT 'Sly', '2002-06-08', 1, 10, gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM pets WHERE id=13); + +INSERT INTO visits (pet_id, visit_date, description, uuid) +SELECT 7, '2010-03-04', 'rabies shot', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM visits WHERE id=1); + +INSERT INTO visits (pet_id, visit_date, description, uuid) +SELECT 8, '2011-03-04', 'rabies shot', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM visits WHERE id=2); + +INSERT INTO visits (pet_id, visit_date, description, uuid) +SELECT 8, '2009-06-04', 'neutered', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM visits WHERE id=3); + +INSERT INTO visits (pet_id, visit_date, description, uuid) +SELECT 7, '2008-09-04', 'spayed', gen_random_uuid() +WHERE NOT EXISTS (SELECT * FROM visits WHERE id=4); diff --git a/src/main/resources/db/postgres/schema.sql b/src/main/resources/db/postgres/schema.sql index 1bd582dc20c..34d2aaeb421 100644 --- a/src/main/resources/db/postgres/schema.sql +++ b/src/main/resources/db/postgres/schema.sql @@ -1,13 +1,15 @@ CREATE TABLE IF NOT EXISTS vets ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, first_name TEXT, - last_name TEXT + last_name TEXT, + uuid UUID DEFAULT gen_random_uuid() UNIQUE ); CREATE INDEX ON vets (last_name); CREATE TABLE IF NOT EXISTS specialties ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - name TEXT + name TEXT, + uuid UUID DEFAULT gen_random_uuid() UNIQUE ); CREATE INDEX ON specialties (name); @@ -19,7 +21,8 @@ CREATE TABLE IF NOT EXISTS vet_specialties ( CREATE TABLE IF NOT EXISTS types ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, - name TEXT + name TEXT, + uuid UUID DEFAULT gen_random_uuid() UNIQUE ); CREATE INDEX ON types (name); @@ -29,7 +32,8 @@ CREATE TABLE IF NOT EXISTS owners ( last_name TEXT, address TEXT, city TEXT, - telephone TEXT + telephone TEXT, + uuid UUID DEFAULT gen_random_uuid() UNIQUE ); CREATE INDEX ON owners (last_name); @@ -38,7 +42,8 @@ CREATE TABLE IF NOT EXISTS pets ( name TEXT, birth_date DATE, type_id INT NOT NULL REFERENCES types (id), - owner_id INT REFERENCES owners (id) + owner_id INT REFERENCES owners (id), + uuid UUID DEFAULT gen_random_uuid() UNIQUE ); CREATE INDEX ON pets (name); CREATE INDEX ON pets (owner_id); @@ -47,6 +52,7 @@ CREATE TABLE IF NOT EXISTS visits ( id INT GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, pet_id INT REFERENCES pets (id), visit_date DATE, - description TEXT + description TEXT, + uuid UUID DEFAULT gen_random_uuid() UNIQUE ); CREATE INDEX ON visits (pet_id); diff --git a/src/main/resources/templates/vets/vetDetails.html b/src/main/resources/templates/vets/vetDetails.html new file mode 100644 index 00000000000..577e67a6bb2 --- /dev/null +++ b/src/main/resources/templates/vets/vetDetails.html @@ -0,0 +1,33 @@ + + + +

Vet Details

+ +
+ +
+ +
+ +
+ + + + + + + + + + + + + + +
First Name
Last Name
Specialties + + None +
+ + diff --git a/src/main/resources/templates/vets/vetList.html b/src/main/resources/templates/vets/vetList.html index e0b8e705010..0618350125c 100644 --- a/src/main/resources/templates/vets/vetList.html +++ b/src/main/resources/templates/vets/vetList.html @@ -12,6 +12,7 @@

Veterinarians

Name Specialties + Actions @@ -20,6 +21,12 @@

Veterinarians

none + +
+ + +
+ diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java index 20c3f46ce33..84d2c5a53c5 100644 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java @@ -31,8 +31,12 @@ import org.springframework.test.web.servlet.ResultActions; import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import static java.util.Optional.of; +import static java.util.UUID.randomUUID; import static org.mockito.ArgumentMatchers.any; import static org.mockito.BDDMockito.given; +import static org.mockito.Mockito.when; +import static org.springframework.samples.petclinic.vet.VetTestUtil.setPrivateField; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; @@ -56,6 +60,7 @@ private Vet james() { james.setFirstName("James"); james.setLastName("Carter"); james.setId(1); + setPrivateField(james, "uuid", randomUUID().toString()); return james; } @@ -68,6 +73,7 @@ private Vet helen() { radiology.setId(1); radiology.setName("radiology"); helen.addSpecialty(radiology); + setPrivateField(helen, "uuid", randomUUID().toString()); return helen; } @@ -97,4 +103,14 @@ void testShowResourcesVetList() throws Exception { .andExpect(jsonPath("$.vetList[0].id").value(1)); } + @Test + void testShowVetProfile() throws Exception { + Vet james = james(); + when(vets.findByUuid(james.getUuid())).thenReturn(of(james).orElseThrow()); + mockMvc.perform(get("/vets/" + james.getUuid())) + .andExpect(status().isOk()) + .andExpect(model().attributeExists("vet")) + .andExpect(view().name("vets/vetDetails")); + } + } diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetTestUtil.java b/src/test/java/org/springframework/samples/petclinic/vet/VetTestUtil.java new file mode 100644 index 00000000000..a07e2bafc8b --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetTestUtil.java @@ -0,0 +1,23 @@ +package org.springframework.samples.petclinic.vet; + +import org.springframework.samples.petclinic.model.BaseEntity; + +import java.lang.reflect.Field; + +import static org.assertj.core.api.Assertions.fail; + +public class VetTestUtil { + + static void setPrivateField(Object targetObject, String fieldName, String value) { + try { + Field field = BaseEntity.class.getDeclaredField(fieldName); + field.setAccessible(true); + field.set(targetObject, value); + + } + catch (Exception e) { + fail(e.getMessage()); + } + } + +} diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java index b29c6d1009e..8fdb0c24552 100644 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java +++ b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java @@ -18,7 +18,9 @@ import org.junit.jupiter.api.Test; import org.springframework.util.SerializationUtils; +import static java.util.UUID.randomUUID; import static org.assertj.core.api.Assertions.assertThat; +import static org.springframework.samples.petclinic.vet.VetTestUtil.setPrivateField; /** * @author Dave Syer @@ -31,11 +33,13 @@ void testSerialization() { vet.setFirstName("Zaphod"); vet.setLastName("Beeblebrox"); vet.setId(123); + setPrivateField(vet, "uuid", randomUUID().toString()); @SuppressWarnings("deprecation") Vet other = (Vet) SerializationUtils.deserialize(SerializationUtils.serialize(vet)); assertThat(other.getFirstName()).isEqualTo(vet.getFirstName()); assertThat(other.getLastName()).isEqualTo(vet.getLastName()); assertThat(other.getId()).isEqualTo(vet.getId()); + assertThat(other.getUuid()).isEqualTo(vet.getUuid()); } }