Search in sources :

Example 6 with Location

use of com.arnaugarcia.uplace.domain.Location in project uplace.es by Uplace.

the class LocationResource method createLocation.

/**
 * POST  /locations : Create a new location.
 *
 * @param locationDTO the locationDTO to create
 * @return the ResponseEntity with status 201 (Created) and with body the new locationDTO, or with status 400 (Bad Request) if the location has already an ID
 * @throws URISyntaxException if the Location URI syntax is incorrect
 */
@PostMapping("/locations")
@Timed
public ResponseEntity<LocationDTO> createLocation(@RequestBody LocationDTO locationDTO) throws URISyntaxException {
    log.debug("REST request to save Location : {}", locationDTO);
    if (locationDTO.getId() != null) {
        throw new BadRequestAlertException("A new location cannot already have an ID", ENTITY_NAME, "idexists");
    }
    Location location = locationMapper.toEntity(locationDTO);
    location = locationRepository.save(location);
    LocationDTO result = locationMapper.toDto(location);
    return ResponseEntity.created(new URI("/api/locations/" + result.getId())).headers(HeaderUtil.createEntityCreationAlert(ENTITY_NAME, result.getId().toString())).body(result);
}
Also used : BadRequestAlertException(com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException) URI(java.net.URI) LocationDTO(com.arnaugarcia.uplace.service.dto.LocationDTO) Location(com.arnaugarcia.uplace.domain.Location) Timed(com.codahale.metrics.annotation.Timed)

Example 7 with Location

use of com.arnaugarcia.uplace.domain.Location in project uplace.es by Uplace.

the class LocationResource method getLocation.

/**
 * GET  /locations/:id : get the "id" location.
 *
 * @param id the id of the locationDTO to retrieve
 * @return the ResponseEntity with status 200 (OK) and with body the locationDTO, or with status 404 (Not Found)
 */
@GetMapping("/locations/{id}")
@Timed
public ResponseEntity<LocationDTO> getLocation(@PathVariable Long id) {
    log.debug("REST request to get Location : {}", id);
    Location location = locationRepository.findOne(id);
    LocationDTO locationDTO = locationMapper.toDto(location);
    return ResponseUtil.wrapOrNotFound(Optional.ofNullable(locationDTO));
}
Also used : LocationDTO(com.arnaugarcia.uplace.service.dto.LocationDTO) Location(com.arnaugarcia.uplace.domain.Location) Timed(com.codahale.metrics.annotation.Timed)

Example 8 with Location

use of com.arnaugarcia.uplace.domain.Location in project uplace.es by Uplace.

the class LocationResourceIntTest method createLocation.

@Test
@Transactional
public void createLocation() throws Exception {
    int databaseSizeBeforeCreate = locationRepository.findAll().size();
    // Create the Location
    LocationDTO locationDTO = locationMapper.toDto(location);
    restLocationMockMvc.perform(post("/api/locations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(locationDTO))).andExpect(status().isCreated());
    // Validate the Location in the database
    List<Location> locationList = locationRepository.findAll();
    assertThat(locationList).hasSize(databaseSizeBeforeCreate + 1);
    Location testLocation = locationList.get(locationList.size() - 1);
    assertThat(testLocation.getLatitude()).isEqualTo(DEFAULT_LATITUDE);
    assertThat(testLocation.getPostalCode()).isEqualTo(DEFAULT_POSTAL_CODE);
    assertThat(testLocation.getLongitude()).isEqualTo(DEFAULT_LONGITUDE);
    assertThat(testLocation.getCity()).isEqualTo(DEFAULT_CITY);
    assertThat(testLocation.getFullAddress()).isEqualTo(DEFAULT_FULL_ADDRESS);
    assertThat(testLocation.isHide()).isEqualTo(DEFAULT_HIDE);
    assertThat(testLocation.getUrlGMaps()).isEqualTo(DEFAULT_URL_G_MAPS);
}
Also used : LocationDTO(com.arnaugarcia.uplace.service.dto.LocationDTO) Location(com.arnaugarcia.uplace.domain.Location) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with Location

use of com.arnaugarcia.uplace.domain.Location in project uplace.es by Uplace.

the class PropertyResourceIntTest method getAllPropertiesByLocationIsEqualToSomething.

@Test
@Transactional
public void getAllPropertiesByLocationIsEqualToSomething() throws Exception {
    // Initialize the database
    Location location = LocationResourceIntTest.createEntity(em);
    em.persist(location);
    em.flush();
    property.setLocation(location);
    propertyRepository.saveAndFlush(property);
    Long locationId = location.getId();
    // Get all the propertyList where location equals to locationId
    defaultPropertyShouldBeFound("locationId.equals=" + locationId);
    // Get all the propertyList where location equals to locationId + 1
    defaultPropertyShouldNotBeFound("locationId.equals=" + (locationId + 1));
}
Also used : Location(com.arnaugarcia.uplace.domain.Location) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Location (com.arnaugarcia.uplace.domain.Location)9 LocationDTO (com.arnaugarcia.uplace.service.dto.LocationDTO)7 Test (org.junit.Test)6 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)6 Transactional (org.springframework.transaction.annotation.Transactional)6 Timed (com.codahale.metrics.annotation.Timed)3 BadRequestAlertException (com.arnaugarcia.uplace.web.rest.errors.BadRequestAlertException)1 URI (java.net.URI)1