mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-17 21:35:50 +00:00
TN: Add EditOwner function
This commit is contained in:
parent
3b27132918
commit
10e1b337cf
6 changed files with 37 additions and 12 deletions
|
@ -17,6 +17,7 @@ package org.springframework.samples.petclinic.rest;
|
|||
|
||||
import java.util.Collection;
|
||||
|
||||
import org.springframework.beans.BeanUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.samples.petclinic.model.Owner;
|
||||
import org.springframework.samples.petclinic.service.ClinicService;
|
||||
|
@ -44,7 +45,15 @@ public class OwnerRestController {
|
|||
|
||||
@RequestMapping(value = "/owners", method = RequestMethod.POST)
|
||||
public @ResponseBody Owner create(@RequestBody Owner owner) {
|
||||
this.clinicService.saveOwner(owner);
|
||||
if (owner.getId()!=null && owner.getId()>0){
|
||||
Owner existingOwner = clinicService.findOwnerById(owner.getId());
|
||||
BeanUtils.copyProperties(owner, existingOwner, "pets", "id");
|
||||
clinicService.saveOwner(existingOwner);
|
||||
}
|
||||
else {
|
||||
this.clinicService.saveOwner(owner);
|
||||
}
|
||||
|
||||
return owner;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,19 +4,19 @@
|
|||
<div class="row thumbnail-wrapper">
|
||||
<div class="col-md-3" ng-repeat="owner in owners | limitTo : 8">
|
||||
<div class="thumbnail">
|
||||
<a href="#"><img data-ng-src="images/avatars/owner{{owner.id}}.jpg" class="img-circle" alt="Generic placeholder image"></a>
|
||||
<a data-ui-sref="ownerDetails({id: owner.id})"><img data-ng-src="images/avatars/owner{{owner.id}}.jpg" class="img-circle" alt="Generic placeholder image"></a>
|
||||
<div class="caption">
|
||||
<h3 class="caption-heading"><a href="#" data-ng-bind="owner.firstName + ' ' +owner.lastName"></a></h3>
|
||||
<h3 class="caption-heading"><a data-ui-sref="ownerDetails({id: owner.id})" data-ng-bind="owner.firstName + ' ' +owner.lastName"></a></h3>
|
||||
<p class="caption-meta" data-ng-bind="owner.city"></p>
|
||||
<p class="caption-meta"><span class="glyphicon glyphicon-phone-alt"></span> <span data-ng-bind="owner.telephone"></span></p>
|
||||
</div>
|
||||
<div class="action-bar">
|
||||
<ul>
|
||||
<li>
|
||||
<a href="#"><img data-ng-src="images/pets/pet{{owner.id}}.jpg" class="img-circle img-circle-small" alt="Generic placeholder image" height="30" width="30"></a>
|
||||
<a data-ui-sref="ownerDetails({id: owner.id})"><img data-ng-src="images/pets/pet{{owner.id}}.jpg" class="img-circle img-circle-small" alt="Generic placeholder image" height="30" width="30"></a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#" class="btn-add-pet"><span class="glyphicon glyphicon-plus"></span></a>
|
||||
<a data-ui-sref="ownerDetails({id: owner.id})" class="btn-add-pet"><span class="glyphicon glyphicon-plus"></span></a>
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
|
|
|
@ -17,4 +17,18 @@ var OwnerDetailsController = ['$scope','$stateParams','Owner', function($scope,$
|
|||
$scope.prevOwner = Owner.get({id:prevId});
|
||||
$scope.nextOwner = Owner.get({id:nextId});
|
||||
$scope.currentOwner = Owner.get($stateParams);
|
||||
|
||||
$scope.saveOwner = function(){
|
||||
owner = $scope.currentOwner;
|
||||
Owner.save(owner);
|
||||
}
|
||||
}];
|
||||
|
||||
var AddOwnerController = ['$scope','Owner', function($scope,Owner) {
|
||||
|
||||
$scope.owner={firstName:'firstName',pets:[]};
|
||||
|
||||
$scope.addOwner = function(){
|
||||
Owner.$save($scope.owner);
|
||||
}
|
||||
}];
|
|
@ -258,11 +258,11 @@
|
|||
<div class="col-md-4 col-md-offset-2">
|
||||
<div class="form-group">
|
||||
<label for="firstName">First Name</label>
|
||||
<input type="text" class="form-control" id="firstName" value="Maria">
|
||||
<input type="text" class="form-control" id="firstName" ng-model="currentOwner.firstName">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="lastName">Last Name</label>
|
||||
<input type="text" class="form-control" id="lastName" value="Rodriguez">
|
||||
<input type="text" class="form-control" id="lastName" ng-model="currentOwner.lastName">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="profileImg">Profile Photo</label>
|
||||
|
@ -284,15 +284,15 @@
|
|||
</div>
|
||||
<div class="form-group">
|
||||
<label for="address">Address</label>
|
||||
<input type="text" class="form-control" id="address" value="345 Maple St.">
|
||||
<input type="text" class="form-control" id="address" ng-model="currentOwner.address">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="city">City</label>
|
||||
<input type="text" class="form-control" id="city" value="Madison">
|
||||
<input type="text" class="form-control" id="city" ng-model="currentOwner.city">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="contactNumber">Contact Number</label>
|
||||
<input type="text" class="form-control" id="contactNumber" value="6085557683">
|
||||
<input type="text" class="form-control" id="contactNumber" ng-model="currentOwner.telephone">
|
||||
</div>
|
||||
<div class="form-group">
|
||||
<label for="email">Email</label>
|
||||
|
@ -301,7 +301,7 @@
|
|||
</div>
|
||||
<div class="col-md-8 col-md-offset-2">
|
||||
<div class="form-group form-group-action">
|
||||
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#editOwnerSuccessModal" data-dismiss="modal" aria-label="Close">Update Owner</button>
|
||||
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#editOwnerSuccessModal" data-dismiss="modal" aria-label="Close" ng-click="saveOwner()">Update Owner</button>
|
||||
<button class="btn btn-link" class="close" data-dismiss="modal" aria-label="Close">Cancel</button>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -2,7 +2,7 @@ var app = angular.module('spring-petclinic', ['ui.router','ui.router.stateHelper
|
|||
|
||||
|
||||
/** Start of Configurable constants **/
|
||||
app.constant('useMockData', true);
|
||||
app.constant('useMockData', false);
|
||||
app.constant('context', '/petclinic');
|
||||
/** End of Configurable constants **/
|
||||
|
||||
|
@ -59,6 +59,7 @@ app.controller('VeterinarianController', VeterinarianController);
|
|||
app.controller('PetController', PetController);
|
||||
app.controller('OwnerController', OwnerController);
|
||||
app.controller('OwnerDetailsController', OwnerDetailsController);
|
||||
app.controller('AddOwnerController', AddOwnerController);
|
||||
app.controller('VisitController', VisitController);
|
||||
|
||||
/** Services **/
|
||||
|
|
|
@ -50,6 +50,7 @@ var MockService = ['$httpBackend', '$http', '$q', 'context', function($httpBacke
|
|||
console.log("Setting up passthrough for other urls");
|
||||
var passThroughRegex = new RegExp('/');
|
||||
$httpBackend.whenGET(passThroughRegex).passThrough();
|
||||
$httpBackend.whenPOST(passThroughRegex).passThrough();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue