Skip to content

Commit

Permalink
added create image cover for property on edit property #38
Browse files Browse the repository at this point in the history
  • Loading branch information
alfdocimo committed May 11, 2017
1 parent a8ce43d commit fb49116
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* REST controller for managing Property.
*/
@RestController
@Transactional
@RequestMapping("/api")
public class PropertyResource {

Expand Down Expand Up @@ -121,6 +122,26 @@ public ResponseEntity<Photo> createPropertyPhoto(@Valid @RequestBody Photo photo
.body(result);
}


@PostMapping("/properties/{idProperty}/cover/{idPhoto}")
@Timed
public ResponseEntity<Photo> createCoverPropertyPhoto(@PathVariable Long idProperty,@PathVariable Long idPhoto) throws URISyntaxException {
log.debug("REST request to save createCoverPropertyPhoto {}");

Property property = propertyRepository.findOne(idProperty);
for (Photo photo: property.getPhotos()){
photo.setCover(false);
photoRepository.save(photo);
}
Photo photo = photoRepository.findOne(idPhoto);
photo.setCover(true);
photoRepository.save(photo);

return ResponseEntity.created(new URI("/api/photos/" + photo.getId()))
.headers(HeaderUtil.createEntityCreationAlert("photo", photo.getId().toString()))
.body(photo);
}

/**
* PUT /properties : Updates an existing property.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,17 @@

}

vm.makeCover = function(photoId){
Photo.makeCover({
idProperty:vm.property.id,
idPhoto:photoId

},
{

}, onSaveSuccess, onSaveError);
}


}
})();
Original file line number Diff line number Diff line change
Expand Up @@ -364,11 +364,20 @@ <h3 class="box-title">Localización</h3>
<!--{{vm.storedPhotos}}-->

<div class="col-lg-4" ng-repeat="x in vm.storedPhotos track by x.id">
<div class="text-center">

<img data-ng-src="{{'data:' + x.imageContentType + ';base64,' + x.image}}" style="max-height: 150px; max-width: 130px;"/>
<div>
<button type="button" class="btn btn-block btn-alert" ng-click="vm.deleteFile(x.id)">Delete</button>
</div>
<div>

<div class="col-lg-6">
<button type="button" class="btn btn-block btn-alert" ng-click="vm.deleteFile(x.id)">Delete</button>
</div>
<div class="col-lg-6">
<button type="button" class="btn btn-block btn-info" ng-click="vm.makeCover(x.id)">Make Cover</button>
</div>

</div>
</div>


Expand Down
1 change: 1 addition & 0 deletions src/main/webapp/app/entities/photo/photo.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
'insertPhoto':{method : 'POST', url: '/api/properties/:id/photos'}, //TODO remove hardcoded /1/ and replace with actual id
'getPhotos':{method:'GET',url:'/api/properties/:id/photos',isArray: true},
'deletePhoto':{method:'DELETE',url:'/api/properties/:id/photos'},
'makeCover':{method:'POST',url:'/api/properties/:idProperty/cover/:idPhoto'},
'get': {
method: 'GET',
transformResponse: function (data) {
Expand Down

0 comments on commit fb49116

Please sign in to comment.