LH :: Updated pets page
|
@ -57,5 +57,12 @@ public interface PetRepository {
|
|||
* @see BaseEntity#isNew
|
||||
*/
|
||||
void save(Pet pet) throws DataAccessException;
|
||||
|
||||
/**
|
||||
* Get all pets
|
||||
* @return
|
||||
*
|
||||
*/
|
||||
List<Pet> findAll() throws DataAccessException;
|
||||
|
||||
}
|
||||
|
|
|
@ -15,15 +15,19 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.repository.jdbc;
|
||||
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.joda.time.DateTime;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.dao.EmptyResultDataAccessException;
|
||||
import org.springframework.jdbc.core.RowMapper;
|
||||
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
|
||||
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
|
||||
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
|
||||
|
@ -130,4 +134,25 @@ public class JdbcPetRepositoryImpl implements PetRepository {
|
|||
.addValue("owner_id", pet.getOwner().getId());
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Pet> findAll() throws DataAccessException {
|
||||
return this.namedParameterJdbcTemplate.query("SELECT * FROM pets", new RowMapper<Pet>(){
|
||||
|
||||
@Override
|
||||
public Pet mapRow(ResultSet rs, int idx) throws SQLException {
|
||||
Pet pet = new Pet();
|
||||
PetType type = new PetType();
|
||||
type.setId(rs.getInt("type_id"));
|
||||
pet.setName(rs.getString("name"));
|
||||
pet.setId(rs.getInt("id"));
|
||||
pet.setBirthDate(new DateTime(rs.getDate("birth_date")));
|
||||
pet.setType(type);
|
||||
|
||||
return pet;
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ import java.util.List;
|
|||
import javax.persistence.EntityManager;
|
||||
import javax.persistence.PersistenceContext;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.Pet;
|
||||
import org.springframework.samples.petclinic.model.PetType;
|
||||
import org.springframework.samples.petclinic.repository.PetRepository;
|
||||
|
@ -61,4 +62,10 @@ public class JpaPetRepositoryImpl implements PetRepository {
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public List<Pet> findAll() throws DataAccessException {
|
||||
return this.em.createQuery("SELECT pet FROM Pet pet").getResultList();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -56,16 +56,9 @@ public class PetRestController {
|
|||
return pet;
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/owners/{ownerId}/pets", method = RequestMethod.PUT)
|
||||
public Collection<Pet> addPets(@PathVariable("ownerId") int ownerId, @RequestBody Collection<Pet> pets) {
|
||||
Owner owner = this.clinicService.findOwnerById(ownerId);
|
||||
|
||||
for(Pet pet : pets) {
|
||||
owner.addPet(pet);
|
||||
this.clinicService.savePet(pet);
|
||||
}
|
||||
|
||||
return pets;
|
||||
@RequestMapping(value = "/pets", method = RequestMethod.GET)
|
||||
public Collection<Pet> findAllPets() {
|
||||
return this.clinicService.findPets();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
|
@ -48,4 +49,6 @@ public interface ClinicService {
|
|||
|
||||
Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException;
|
||||
|
||||
List<Pet> findPets() throws DataAccessException;
|
||||
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
|
@ -105,5 +106,10 @@ public class ClinicServiceImpl implements ClinicService {
|
|||
return vetRepository.findAll();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@Transactional(readOnly = true)
|
||||
@Cacheable(value = "pets")
|
||||
public List<Pet> findPets() throws DataAccessException {
|
||||
return petRepository.findAll();
|
||||
}
|
||||
}
|
||||
|
|
10
src/main/resources/cache/ehcache.xml
vendored
|
@ -13,5 +13,15 @@
|
|||
diskPersistent="false"
|
||||
diskExpiryThreadIntervalSeconds="1"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
<cache name="pets"
|
||||
timeToLiveSeconds="60"
|
||||
maxElementsInMemory="100"
|
||||
eternal="false"
|
||||
overflowToDisk="false"
|
||||
maxElementsOnDisk="10000000"
|
||||
diskPersistent="false"
|
||||
diskExpiryThreadIntervalSeconds="1"
|
||||
memoryStoreEvictionPolicy="LRU"/>
|
||||
|
||||
</ehcache>
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
<div class="row thumbnail-wrapper">
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<img src="images/pet-default.png" class="img-circle" alt="Generic placeholder image">
|
||||
<img src="images/pets/pet1.jpg" class="img-circle" alt="Generic placeholder image">
|
||||
<div class="caption">
|
||||
<h3 class="caption-heading">Basil</h3>
|
||||
<p class="caption-meta">08 August 2012</p>
|
||||
|
@ -14,7 +14,7 @@
|
|||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<img src="images/pet-default.png" class="img-circle" alt="Generic placeholder image">
|
||||
<img src="images/pets/pet2.jpg" class="img-circle" alt="Generic placeholder image">
|
||||
<div class="caption">
|
||||
<h3 class="caption-heading">Basil</h3>
|
||||
<p class="caption-meta">08 August 2012</p>
|
||||
|
@ -24,7 +24,7 @@
|
|||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<img src="images/pet-default.png" class="img-circle" alt="Generic placeholder image">
|
||||
<img src="images/pets/pet3.jpg" class="img-circle" alt="Generic placeholder image">
|
||||
<div class="caption">
|
||||
<h3 class="caption-heading">Basil</h3>
|
||||
<p class="caption-meta">08 August 2012</p>
|
||||
|
@ -34,7 +34,7 @@
|
|||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<img src="images/pet-default.png" class="img-circle" alt="Generic placeholder image">
|
||||
<img src="images/pets/pet4.jpg" class="img-circle" alt="Generic placeholder image">
|
||||
<div class="caption">
|
||||
<h3 class="caption-heading">Basil</h3>
|
||||
<p class="caption-meta">08 August 2012</p>
|
||||
|
@ -46,7 +46,7 @@
|
|||
<!-- /row -->
|
||||
<div class="row">
|
||||
<div class="col-md-4 col-md-offset-4">
|
||||
<p><a class="btn btn-default btn-block" href="/pets">See All Pets</a></p>
|
||||
<p><a class="btn btn-default btn-block" data-ui-sref="pets">See All Pets</a></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -14,7 +14,7 @@
|
|||
<!-- Collect the nav links, forms, and other content for toggling -->
|
||||
<div id="nav-menu" class="navbar-collapse navbar-left collapse">
|
||||
<ul class="nav navbar-nav navbar-menu" data-ng-if="getSession() != null">
|
||||
<li data-ng-class="$state.is('landing') ? 'active' : ''"><a data-ui-sref="landing">Home</a></li>
|
||||
<li data-ng-class="$state.is('landing') ? 'active' : ''"><a href="#" data-ng-click="goHome()">Home</a></li>
|
||||
<li data-ng-class="$state.is('owners') ? 'active' : ''"><a data-ui-sref="owners">Owners</a></li>
|
||||
<li data-ng-class="$state.is('pets') ? 'active' : ''"><a data-ui-sref="pets">Pets</a></li>
|
||||
<li data-ng-class="$state.is('vets') ? 'active' : ''"><a data-ui-sref="vets">Vets</a></li>
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
<div class="container">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<img class="img-thumbnail" src="http://placehold.it/560x250" alt="Generic placeholder image">
|
||||
<img class="img-thumbnail" src="images/services/service1.jpg" alt="Generic placeholder image">
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<h3 class="section-heading">Services One</h3>
|
||||
<p class="section-desc">A small river named Duden flows by their place and supplies it with the necessary regelialia. It is a paradisematic country, in which roasted parts of sentences fly into your mouth.</p>
|
||||
<p>
|
||||
<a class="btn btn-primary" href="/business">Learn more »</a>
|
||||
<a class="btn btn-primary" data-ui-sref="landing">Learn more »</a>
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -14,6 +14,14 @@ var MainController = ['$scope','$rootScope','$state',function($scope, $rootScop
|
|||
$state.go('landing');
|
||||
};
|
||||
|
||||
$scope.goHome = function() {
|
||||
if ($scope.getSession() == null) {
|
||||
$state.go('landing');
|
||||
} else {
|
||||
$state.go('dashboard');
|
||||
}
|
||||
}
|
||||
|
||||
$scope.menuTabs = [ {
|
||||
'name' : 'Main Page',
|
||||
'url' : '#',
|
||||
|
|
|
@ -26,25 +26,13 @@
|
|||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="active"><a href="#">Newest</a></li>
|
||||
<li role="presentation"><a href="#">Popular</a></li>
|
||||
<li role="presentation" class="dropdown open">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">
|
||||
Dropdown <span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="#">McFarland</a></li>
|
||||
<li><a href="#">Sun Prairie</a></li>
|
||||
<li><a href="#">Madison</a></li>
|
||||
<li><a href="#">New York</a></li>
|
||||
<li><a href="#">Madison</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3" data-ng-repeat="owner in owners">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="/petclinic/images/avatars/owner{{owner.id}}.jpg" alt="Generic placeholder image"></img></a>
|
||||
<a href="show.html"><img data-ng-src="images/avatars/owner{{owner.id}}.jpg" alt="Generic placeholder image"></img></a>
|
||||
<div class="caption">
|
||||
<h3><a href="show.html" data-ng-bind="owner.firstName + ' ' +owner.lastName"></a></h3>
|
||||
<p data-ng-bind="owner.city"></p>
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
var PetController = ['$scope', function($scope) {
|
||||
var PetController = ['$scope', 'Pet', function($scope, Pet) {
|
||||
|
||||
$scope.$on('$viewContentLoaded', function(event){
|
||||
$('html, body').animate({
|
||||
|
@ -6,4 +6,6 @@ var PetController = ['$scope', function($scope) {
|
|||
}, 1000);
|
||||
});
|
||||
|
||||
$scope.pets = Pet.query();
|
||||
|
||||
}];
|
|
@ -3,8 +3,8 @@
|
|||
<div class="container">
|
||||
<div class="jumbotron-headline">
|
||||
<div class="jumbotron-headline-cell">
|
||||
<h1>Discover Pet Owners</h1>
|
||||
<p>Helping you discover pet owners near you and connect.</p>
|
||||
<h1>Finding your pet</h1>
|
||||
<p>Finding the pets that are currently under our care.</p>
|
||||
<div class="row">
|
||||
<div class="col-md-6 col-md-offset-2">
|
||||
<input type="text" class="form-control input-lg" placeholder=".col-md-8">
|
||||
|
@ -26,91 +26,16 @@
|
|||
<ul class="nav nav-tabs">
|
||||
<li role="presentation" class="active"><a href="#">Newest</a></li>
|
||||
<li role="presentation"><a href="#">Popular</a></li>
|
||||
<li role="presentation" class="dropdown open">
|
||||
<a class="dropdown-toggle" data-toggle="dropdown" href="#" role="button" aria-expanded="false">
|
||||
Dropdown <span class="caret"></span>
|
||||
</a>
|
||||
<ul class="dropdown-menu" role="menu">
|
||||
<li><a href="#">McFarland</a></li>
|
||||
<li><a href="#">Sun Prairie</a></li>
|
||||
<li><a href="#">Madison</a></li>
|
||||
<li><a href="#">New York</a></li>
|
||||
<li><a href="#">Madison</a></li>
|
||||
</ul>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-3">
|
||||
<div class="col-md-3" ng-repeat="pet in pets">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a></a>
|
||||
<a href="#"><img data-ng-src="images/pets/pet{{pet.id % 10 + 1}}.jpg" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><a href="show.html"><h3>Thumbnail label</h3></a></a>
|
||||
<p>Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><a href="show.html"><h3>Thumbnail label</h3></a></a>
|
||||
<p>Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><h3>Thumbnail label</h3></a>
|
||||
<p>Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><h3>Thumbnail label</h3></a>
|
||||
<p>Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><h3>Thumbnail label</h3></a>
|
||||
<p>Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><h3>Thumbnail label</h3></a>
|
||||
<p>Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><h3>Thumbnail label</h3></a>
|
||||
<p>Even the all-powerful Pointing has no control about the blind texts it is an almost unorthographic life One day however a small line of blind text by the name of Lorem Ipsum.</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-md-3">
|
||||
<div class="thumbnail">
|
||||
<a href="show.html"><img src="http://placehold.it/600x600" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<a href="show.html"><h3>Thumbnail label</h3></a>
|
||||
<p>Mountains, she had a last view back on the skyline of her hometown Bookmarksgrove, the headline of Alphabet Village and the subline of her own road, the Line Lane.</p>
|
||||
<a href="#"><h3 data-ng-bind="pet.name"></h3></a>
|
||||
<p data-ng-bind="pet.type.name"></p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -151,25 +76,4 @@
|
|||
</section>
|
||||
|
||||
<!-- Contact details -->
|
||||
<section id="add_owner" class="sections sections-narrow">
|
||||
<div class="container">
|
||||
<!-- Three columns of text below the carousel -->
|
||||
<div class="row">
|
||||
<div class="col-lg-4">
|
||||
<h3>Business Hours</h3>
|
||||
<p>Donec sed odio dui. Etiam porta sem malesuada magna mollis euismod. Nullam id dolor id nibh ultricies vehicula ut id elit. Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Praesent commodo cursus magna.</p>
|
||||
</div><!-- /.col-lg-4 -->
|
||||
<div class="col-lg-4">
|
||||
<h3>Our Location</h3>
|
||||
<p>Duis mollis, est non commodo luctus, nisi erat porttitor ligula, eget lacinia odio sem nec elit. Cras mattis consectetur purus sit amet fermentum. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh.</p>
|
||||
</div><!-- /.col-lg-4 -->
|
||||
<div class="col-lg-4">
|
||||
<h3>Questions or comments</h3>
|
||||
<p>Cras mattis consectetur purus sit amet fermentum. </p>
|
||||
<p>
|
||||
<a href="mailto:youremail@yourdomain.com" type="submit" class="btn btn-default">Drop us a line</a>
|
||||
</p>
|
||||
</div><!-- /.col-lg-4 -->
|
||||
</div><!-- /.row -->
|
||||
</div>
|
||||
</section>
|
||||
<data-ng-include src="'components/landing/_contact_us.html'"></data-ng-include>
|
||||
|
|
BIN
src/main/webapp/images/pets/pet1.jpg
Normal file
After Width: | Height: | Size: 8.1 KiB |
BIN
src/main/webapp/images/pets/pet10.jpg
Normal file
After Width: | Height: | Size: 13 KiB |
BIN
src/main/webapp/images/pets/pet2.jpg
Normal file
After Width: | Height: | Size: 8 KiB |
BIN
src/main/webapp/images/pets/pet3.jpg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
src/main/webapp/images/pets/pet4.jpg
Normal file
After Width: | Height: | Size: 8.2 KiB |
BIN
src/main/webapp/images/pets/pet5.jpg
Normal file
After Width: | Height: | Size: 10 KiB |
BIN
src/main/webapp/images/pets/pet6.jpg
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
src/main/webapp/images/pets/pet7.jpg
Normal file
After Width: | Height: | Size: 16 KiB |
BIN
src/main/webapp/images/pets/pet8.jpg
Normal file
After Width: | Height: | Size: 7.7 KiB |
BIN
src/main/webapp/images/pets/pet9.jpg
Normal file
After Width: | Height: | Size: 13 KiB |
|
@ -2,10 +2,14 @@ var Owner = ['$resource', function($resource) {
|
|||
return $resource('/petclinic/api/owners/:id');
|
||||
}];
|
||||
|
||||
var Pet = ['$resource', function($resource) {
|
||||
var OwnerPet = ['$resource', function($resource) {
|
||||
return $resource('/petclinic/api/owners/:ownerId/pets', {ownerId : '@ownerId'});
|
||||
}];
|
||||
|
||||
var Pet = ['$resource', function($resource) {
|
||||
return $resource('/petclinic/api/pets/:id');
|
||||
}];
|
||||
|
||||
var Vet = ['$resource', function($resource) {
|
||||
return $resource('/petclinic/api/vets/:vetId');
|
||||
}];
|
||||
|
|