From fb491169a8e3eed015de2c1a1bca06e7b6dd8bf6 Mon Sep 17 00:00:00 2001 From: Alfredo Narvaez Date: Thu, 11 May 2017 17:46:45 +0200 Subject: [PATCH] added create image cover for property on edit property #38 --- .../web/rest/PropertyResource.java | 21 +++++++++++++++++++ .../dashboard.locationProperty.controller.js | 11 ++++++++++ .../property/dashboard.property-new.html | 13 ++++++++++-- .../app/entities/photo/photo.service.js | 1 + 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/arnaugarcia/assessoriatorrelles/web/rest/PropertyResource.java b/src/main/java/com/arnaugarcia/assessoriatorrelles/web/rest/PropertyResource.java index 4e49af9..d123564 100644 --- a/src/main/java/com/arnaugarcia/assessoriatorrelles/web/rest/PropertyResource.java +++ b/src/main/java/com/arnaugarcia/assessoriatorrelles/web/rest/PropertyResource.java @@ -37,6 +37,7 @@ * REST controller for managing Property. */ @RestController +@Transactional @RequestMapping("/api") public class PropertyResource { @@ -121,6 +122,26 @@ public ResponseEntity createPropertyPhoto(@Valid @RequestBody Photo photo .body(result); } + + @PostMapping("/properties/{idProperty}/cover/{idPhoto}") + @Timed + public ResponseEntity 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. * diff --git a/src/main/webapp/app/dashboard/entities/property/dashboard.locationProperty.controller.js b/src/main/webapp/app/dashboard/entities/property/dashboard.locationProperty.controller.js index 574e2bf..9c2b4a8 100644 --- a/src/main/webapp/app/dashboard/entities/property/dashboard.locationProperty.controller.js +++ b/src/main/webapp/app/dashboard/entities/property/dashboard.locationProperty.controller.js @@ -142,6 +142,17 @@ } + vm.makeCover = function(photoId){ + Photo.makeCover({ + idProperty:vm.property.id, + idPhoto:photoId + + }, + { + + }, onSaveSuccess, onSaveError); + } + } })(); diff --git a/src/main/webapp/app/dashboard/entities/property/dashboard.property-new.html b/src/main/webapp/app/dashboard/entities/property/dashboard.property-new.html index 3ac22dd..a185e66 100644 --- a/src/main/webapp/app/dashboard/entities/property/dashboard.property-new.html +++ b/src/main/webapp/app/dashboard/entities/property/dashboard.property-new.html @@ -364,11 +364,20 @@

LocalizaciĆ³n

+
+ -
-
+
+
+ +
+
+ +
+ +
diff --git a/src/main/webapp/app/entities/photo/photo.service.js b/src/main/webapp/app/entities/photo/photo.service.js index e2fccaf..f9ed022 100644 --- a/src/main/webapp/app/entities/photo/photo.service.js +++ b/src/main/webapp/app/entities/photo/photo.service.js @@ -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) {