Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New Feature - #1671 - Added Profile Page for Vets #1672

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
Expand All @@ -48,4 +52,8 @@ public boolean isNew() {
return this.id == null;
}

public String getUuid() {
return uuid;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -75,4 +76,10 @@ private Page<Vet> 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";
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,13 @@ public interface VetRepository extends Repository<Vet, Integer> {
@Cacheable("vets")
Page<Vet> findAll(Pageable pageable) throws DataAccessException;

/**
* Get <code>Vet</code> 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;

}
94 changes: 47 additions & 47 deletions src/main/resources/db/h2/data.sql
Original file line number Diff line number Diff line change
@@ -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');
6 changes: 6 additions & 0 deletions src/main/resources/db/h2/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ 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)
);
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);
Expand All @@ -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),
Expand All @@ -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,
Expand All @@ -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)
Expand Down
Loading