Search in sources :

Example 1 with Photo

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));
}
Also used : Photo(com.arnaugarcia.uplace.domain.Photo) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Photo

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);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) Photo(com.arnaugarcia.uplace.domain.Photo) URI(java.net.URI) Timed(com.codahale.metrics.annotation.Timed)

Example 3 with Photo

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));
}
Also used : Photo(com.arnaugarcia.uplace.domain.Photo) Timed(com.codahale.metrics.annotation.Timed)

Example 4 with 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);
}
Also used : Photo(com.arnaugarcia.uplace.domain.Photo) Timed(com.codahale.metrics.annotation.Timed)

Example 5 with Photo

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;
}
Also used : Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Marker(com.arnaugarcia.uplace.domain.Marker) PageRequest(org.springframework.data.domain.PageRequest) PropertyRepository(com.arnaugarcia.uplace.repository.PropertyRepository) Collectors(java.util.stream.Collectors) Photo(com.arnaugarcia.uplace.domain.Photo) List(java.util.List) Service(org.springframework.stereotype.Service) Pageable(org.springframework.data.domain.Pageable) MarkerDTO(com.arnaugarcia.uplace.service.dto.MarkerDTO) Transactional(org.springframework.transaction.annotation.Transactional) TransformMarkerToMarkerDTO.markerToMarkerDTO(com.arnaugarcia.uplace.service.util.TransformMarkerToMarkerDTO.markerToMarkerDTO) PageRequest(org.springframework.data.domain.PageRequest) Pageable(org.springframework.data.domain.Pageable) List(java.util.List) Marker(com.arnaugarcia.uplace.domain.Marker) MarkerDTO(com.arnaugarcia.uplace.service.dto.MarkerDTO) TransformMarkerToMarkerDTO.markerToMarkerDTO(com.arnaugarcia.uplace.service.util.TransformMarkerToMarkerDTO.markerToMarkerDTO) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Photo (com.arnaugarcia.uplace.domain.Photo)8 Transactional (org.springframework.transaction.annotation.Transactional)5 Test (org.junit.Test)4 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)4 Timed (com.codahale.metrics.annotation.Timed)3 Marker (com.arnaugarcia.uplace.domain.Marker)1 PropertyRepository (com.arnaugarcia.uplace.repository.PropertyRepository)1 MarkerDTO (com.arnaugarcia.uplace.service.dto.MarkerDTO)1 TransformMarkerToMarkerDTO.markerToMarkerDTO (com.arnaugarcia.uplace.service.util.TransformMarkerToMarkerDTO.markerToMarkerDTO)1 BadRequestAlertException (com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 Logger (org.slf4j.Logger)1 LoggerFactory (org.slf4j.LoggerFactory)1 PageRequest (org.springframework.data.domain.PageRequest)1 Pageable (org.springframework.data.domain.Pageable)1 Service (org.springframework.stereotype.Service)1