LH :: Updated pets page

This commit is contained in:
Lim Han 2015-02-04 23:56:41 +08:00
parent 8d30eb2d4f
commit b230d9dd3c
25 changed files with 94 additions and 137 deletions

View file

@ -57,5 +57,12 @@ public interface PetRepository {
* @see BaseEntity#isNew * @see BaseEntity#isNew
*/ */
void save(Pet pet) throws DataAccessException; void save(Pet pet) throws DataAccessException;
/**
* Get all pets
* @return
*
*/
List<Pet> findAll() throws DataAccessException;
} }

View file

@ -15,15 +15,19 @@
*/ */
package org.springframework.samples.petclinic.repository.jdbc; package org.springframework.samples.petclinic.repository.jdbc;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import javax.sql.DataSource; import javax.sql.DataSource;
import org.joda.time.DateTime;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.dao.EmptyResultDataAccessException; import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.namedparam.MapSqlParameterSource; import org.springframework.jdbc.core.namedparam.MapSqlParameterSource;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate; import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper; import org.springframework.jdbc.core.simple.ParameterizedBeanPropertyRowMapper;
@ -130,4 +134,25 @@ public class JdbcPetRepositoryImpl implements PetRepository {
.addValue("owner_id", pet.getOwner().getId()); .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;
}
});
}
} }

View file

@ -20,6 +20,7 @@ import java.util.List;
import javax.persistence.EntityManager; import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext; import javax.persistence.PersistenceContext;
import org.springframework.dao.DataAccessException;
import org.springframework.samples.petclinic.model.Pet; import org.springframework.samples.petclinic.model.Pet;
import org.springframework.samples.petclinic.model.PetType; import org.springframework.samples.petclinic.model.PetType;
import org.springframework.samples.petclinic.repository.PetRepository; 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();
}
} }

View file

@ -56,16 +56,9 @@ public class PetRestController {
return pet; return pet;
} }
@RequestMapping(value = "/owners/{ownerId}/pets", method = RequestMethod.PUT) @RequestMapping(value = "/pets", method = RequestMethod.GET)
public Collection<Pet> addPets(@PathVariable("ownerId") int ownerId, @RequestBody Collection<Pet> pets) { public Collection<Pet> findAllPets() {
Owner owner = this.clinicService.findOwnerById(ownerId); return this.clinicService.findPets();
for(Pet pet : pets) {
owner.addPet(pet);
this.clinicService.savePet(pet);
}
return pets;
} }
} }

View file

@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.service; package org.springframework.samples.petclinic.service;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.springframework.dao.DataAccessException; import org.springframework.dao.DataAccessException;
import org.springframework.samples.petclinic.model.Owner; import org.springframework.samples.petclinic.model.Owner;
@ -48,4 +49,6 @@ public interface ClinicService {
Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException; Collection<Owner> findOwnerByLastName(String lastName) throws DataAccessException;
List<Pet> findPets() throws DataAccessException;
} }

View file

@ -16,6 +16,7 @@
package org.springframework.samples.petclinic.service; package org.springframework.samples.petclinic.service;
import java.util.Collection; import java.util.Collection;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Cacheable;
@ -105,5 +106,10 @@ public class ClinicServiceImpl implements ClinicService {
return vetRepository.findAll(); return vetRepository.findAll();
} }
@Override
@Transactional(readOnly = true)
@Cacheable(value = "pets")
public List<Pet> findPets() throws DataAccessException {
return petRepository.findAll();
}
} }

View file

@ -13,5 +13,15 @@
diskPersistent="false" diskPersistent="false"
diskExpiryThreadIntervalSeconds="1" diskExpiryThreadIntervalSeconds="1"
memoryStoreEvictionPolicy="LRU"/> memoryStoreEvictionPolicy="LRU"/>
<cache name="pets"
timeToLiveSeconds="60"
maxElementsInMemory="100"
eternal="false"
overflowToDisk="false"
maxElementsOnDisk="10000000"
diskPersistent="false"
diskExpiryThreadIntervalSeconds="1"
memoryStoreEvictionPolicy="LRU"/>
</ehcache> </ehcache>

View file

@ -4,7 +4,7 @@
<div class="row thumbnail-wrapper"> <div class="row thumbnail-wrapper">
<div class="col-md-3"> <div class="col-md-3">
<div class="thumbnail"> <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"> <div class="caption">
<h3 class="caption-heading">Basil</h3> <h3 class="caption-heading">Basil</h3>
<p class="caption-meta">08 August 2012</p> <p class="caption-meta">08 August 2012</p>
@ -14,7 +14,7 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="thumbnail"> <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"> <div class="caption">
<h3 class="caption-heading">Basil</h3> <h3 class="caption-heading">Basil</h3>
<p class="caption-meta">08 August 2012</p> <p class="caption-meta">08 August 2012</p>
@ -24,7 +24,7 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="thumbnail"> <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"> <div class="caption">
<h3 class="caption-heading">Basil</h3> <h3 class="caption-heading">Basil</h3>
<p class="caption-meta">08 August 2012</p> <p class="caption-meta">08 August 2012</p>
@ -34,7 +34,7 @@
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
<div class="thumbnail"> <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"> <div class="caption">
<h3 class="caption-heading">Basil</h3> <h3 class="caption-heading">Basil</h3>
<p class="caption-meta">08 August 2012</p> <p class="caption-meta">08 August 2012</p>
@ -46,7 +46,7 @@
<!-- /row --> <!-- /row -->
<div class="row"> <div class="row">
<div class="col-md-4 col-md-offset-4"> <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> </div>
</div> </div>

View file

@ -14,7 +14,7 @@
<!-- Collect the nav links, forms, and other content for toggling --> <!-- Collect the nav links, forms, and other content for toggling -->
<div id="nav-menu" class="navbar-collapse navbar-left collapse"> <div id="nav-menu" class="navbar-collapse navbar-left collapse">
<ul class="nav navbar-nav navbar-menu" data-ng-if="getSession() != null"> <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('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('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> <li data-ng-class="$state.is('vets') ? 'active' : ''"><a data-ui-sref="vets">Vets</a></li>

View file

@ -1,13 +1,13 @@
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-6"> <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>
<div class="col-md-6"> <div class="col-md-6">
<h3 class="section-heading">Services One</h3> <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 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> <p>
<a class="btn btn-primary" href="/business">Learn more »</a> <a class="btn btn-primary" data-ui-sref="landing">Learn more »</a>
</p> </p>
</div> </div>
</div> </div>

View file

@ -14,6 +14,14 @@ var MainController = ['$scope','$rootScope','$state',function($scope, $rootScop
$state.go('landing'); $state.go('landing');
}; };
$scope.goHome = function() {
if ($scope.getSession() == null) {
$state.go('landing');
} else {
$state.go('dashboard');
}
}
$scope.menuTabs = [ { $scope.menuTabs = [ {
'name' : 'Main Page', 'name' : 'Main Page',
'url' : '#', 'url' : '#',

View file

@ -26,25 +26,13 @@
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#">Newest</a></li> <li role="presentation" class="active"><a href="#">Newest</a></li>
<li role="presentation"><a href="#">Popular</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> </ul>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-3" data-ng-repeat="owner in owners"> <div class="col-md-3" data-ng-repeat="owner in owners">
<div class="thumbnail"> <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"> <div class="caption">
<h3><a href="show.html" data-ng-bind="owner.firstName + ' ' +owner.lastName"></a></h3> <h3><a href="show.html" data-ng-bind="owner.firstName + ' ' +owner.lastName"></a></h3>
<p data-ng-bind="owner.city"></p> <p data-ng-bind="owner.city"></p>

View file

@ -1,4 +1,4 @@
var PetController = ['$scope', function($scope) { var PetController = ['$scope', 'Pet', function($scope, Pet) {
$scope.$on('$viewContentLoaded', function(event){ $scope.$on('$viewContentLoaded', function(event){
$('html, body').animate({ $('html, body').animate({
@ -6,4 +6,6 @@ var PetController = ['$scope', function($scope) {
}, 1000); }, 1000);
}); });
$scope.pets = Pet.query();
}]; }];

View file

@ -3,8 +3,8 @@
<div class="container"> <div class="container">
<div class="jumbotron-headline"> <div class="jumbotron-headline">
<div class="jumbotron-headline-cell"> <div class="jumbotron-headline-cell">
<h1>Discover Pet Owners</h1> <h1>Finding your pet</h1>
<p>Helping you discover pet owners near you and connect.</p> <p>Finding the pets that are currently under our care.</p>
<div class="row"> <div class="row">
<div class="col-md-6 col-md-offset-2"> <div class="col-md-6 col-md-offset-2">
<input type="text" class="form-control input-lg" placeholder=".col-md-8"> <input type="text" class="form-control input-lg" placeholder=".col-md-8">
@ -26,91 +26,16 @@
<ul class="nav nav-tabs"> <ul class="nav nav-tabs">
<li role="presentation" class="active"><a href="#">Newest</a></li> <li role="presentation" class="active"><a href="#">Newest</a></li>
<li role="presentation"><a href="#">Popular</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> </ul>
</div> </div>
<div class="row"> <div class="row">
<div class="col-md-3"> <div class="col-md-3" ng-repeat="pet in pets">
<div class="thumbnail"> <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"> <div class="caption">
<a href="show.html"><a href="show.html"><h3>Thumbnail label</h3></a></a> <a href="#"><h3 data-ng-bind="pet.name"></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> <p data-ng-bind="pet.type.name"></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>
</div> </div>
</div> </div>
</div> </div>
@ -151,25 +76,4 @@
</section> </section>
<!-- Contact details --> <!-- Contact details -->
<section id="add_owner" class="sections sections-narrow"> <data-ng-include src="'components/landing/_contact_us.html'"></data-ng-include>
<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>

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 17 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 16 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View file

@ -2,10 +2,14 @@ var Owner = ['$resource', function($resource) {
return $resource('/petclinic/api/owners/:id'); 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'}); 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) { var Vet = ['$resource', function($resource) {
return $resource('/petclinic/api/vets/:vetId'); return $resource('/petclinic/api/vets/:vetId');
}]; }];