use of com.arnaugarcia.uplace.domain.Photo in project uplace.es by Uplace.
the class PropertyResourceIntTest method getAllPropertiesByPhotoIsEqualToSomething.
@Test
@Transactional
public void getAllPropertiesByPhotoIsEqualToSomething() throws Exception {
// Initialize the database
Photo photo = PhotoResourceIntTest.createEntity(em);
em.persist(photo);
em.flush();
property.addPhoto(photo);
propertyRepository.saveAndFlush(property);
Long photoId = photo.getId();
// Get all the propertyList where photo equals to photoId
defaultPropertyShouldBeFound("photoId.equals=" + photoId);
// Get all the propertyList where photo equals to photoId + 1
defaultPropertyShouldNotBeFound("photoId.equals=" + (photoId + 1));
}
use of com.arnaugarcia.uplace.domain.Photo in project uplace.es by Uplace.
the class PhotoResource method createPhoto.
/**
* POST /photos : Create a new photo.
*
* @param photo the photo to create
* @return the ResponseEntity with status 201 (Created) and with body the new photo, or with status 400 (Bad Request) if the photo has already an ID
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PostMapping("/photos")
@Timed
public ResponseEntity<Photo> createPhoto(@Valid @RequestBody Photo photo) throws URISyntaxException {
log.debug("REST request to save Photo : {}", photo);
if (photo.getId() != null) {
throw new BadRequestAlertException("A new photo cannot already have an ID", ENTITY_NAME, "idexists");
}
Photo result = photoRepository.save(photo);
return ResponseEntity.created(new URI("/api/photos/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
use of com.arnaugarcia.uplace.domain.Photo in project uplace.es by Uplace.
the class PhotoResource method getPhoto.
/**
* GET /photos/:id : get the "id" photo.
*
* @param id the id of the photo to retrieve
* @return the ResponseEntity with status 200 (OK) and with body the photo, or with status 404 (Not Found)
*/
@GetMapping("/photos/{id}")
@Timed
public ResponseEntity<Photo> getPhoto(@PathVariable Long id) {
log.debug("REST request to get Photo : {}", id);
Photo photo = photoRepository.findOne(id);
return ResponseUtil.wrapOrNotFound(Optional.ofNullable(photo));
}
use of com.arnaugarcia.uplace.domain.Photo in project uplace.es by Uplace.
the class PhotoResource method updatePhoto.
/**
* PUT /photos : Updates an existing photo.
*
* @param photo the photo to update
* @return the ResponseEntity with status 200 (OK) and with body the updated photo,
* or with status 400 (Bad Request) if the photo is not valid,
* or with status 500 (Internal Server Error) if the photo couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/photos")
@Timed
public ResponseEntity<Photo> updatePhoto(@Valid @RequestBody Photo photo) throws URISyntaxException {
log.debug("REST request to update Photo : {}", photo);
if (photo.getId() == null) {
return createPhoto(photo);
}
Photo result = photoRepository.save(photo);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, photo.getId().toString())).body(result);
}
use of com.arnaugarcia.uplace.domain.Photo in project uplace.es by Uplace.
the class MarkerService method getAllMarkers.
@Transactional(readOnly = true)
public List<MarkerDTO> getAllMarkers() {
List<Marker> markerList = propertyRepository.findAllMarkers();
List<MarkerDTO> markerDTOS = markerList.parallelStream().map(markerToMarkerDTO).collect(Collectors.toList());
// This can be made with JPA 1.7 findTop or inner join query
Pageable limit = new PageRequest(0, 1);
markerDTOS.parallelStream().forEach((markerDTO -> {
List<Photo> photos = propertyRepository.findThumbnailByReference(markerDTO.getPropertyReference(), limit);
if (!photos.isEmpty())
markerDTO.setPhoto(photos.get(0));
}));
/*markerDTOList.parallelStream().forEach((markerDTO -> {
if (markerDTO.getDate() != null) {
LocalDate localDate = markerDTO.getDate().toLocalDate();
LocalDate today = LocalDate.now();
Period period = Period.between(localDate, today);
if (period.getMonths() >= 1) {
markerDTO.setNew(false);
} else {
markerDTO.setNew(true);
}
} else {
markerDTO.setNew(false);
}
}));
List<MarkerDTO> result = markerDTOList.parallelStream()
.filter(markerDTO -> Objects.nonNull(markerDTO.getLatitude()))
.filter(markerDTO -> markerDTO.getLatitude() > 0)
.filter(markerDTO -> Objects.nonNull(markerDTO.getLongitude()))
.filter(markerDTO -> markerDTO.getLongitude() > 0)
.collect(Collectors.toList());*/
return markerDTOS;
}
Aggregations