use of com.arnaugarcia.uplace.service.dto.LocationDTO in project uplace.es by Uplace.
the class LocationResourceIntTest method updateLocation.
@Test
@Transactional
public void updateLocation() throws Exception {
// Initialize the database
locationRepository.saveAndFlush(location);
int databaseSizeBeforeUpdate = locationRepository.findAll().size();
// Update the location
Location updatedLocation = locationRepository.findOne(location.getId());
// Disconnect from session so that the updates on updatedLocation are not directly saved in db
em.detach(updatedLocation);
updatedLocation.latitude(UPDATED_LATITUDE).postalCode(UPDATED_POSTAL_CODE).longitude(UPDATED_LONGITUDE).city(UPDATED_CITY).fullAddress(UPDATED_FULL_ADDRESS).hide(UPDATED_HIDE).urlGMaps(UPDATED_URL_G_MAPS);
LocationDTO locationDTO = locationMapper.toDto(updatedLocation);
restLocationMockMvc.perform(put("/api/locations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(locationDTO))).andExpect(status().isOk());
// Validate the Location in the database
List<Location> locationList = locationRepository.findAll();
assertThat(locationList).hasSize(databaseSizeBeforeUpdate);
Location testLocation = locationList.get(locationList.size() - 1);
assertThat(testLocation.getLatitude()).isEqualTo(UPDATED_LATITUDE);
assertThat(testLocation.getPostalCode()).isEqualTo(UPDATED_POSTAL_CODE);
assertThat(testLocation.getLongitude()).isEqualTo(UPDATED_LONGITUDE);
assertThat(testLocation.getCity()).isEqualTo(UPDATED_CITY);
assertThat(testLocation.getFullAddress()).isEqualTo(UPDATED_FULL_ADDRESS);
assertThat(testLocation.isHide()).isEqualTo(UPDATED_HIDE);
assertThat(testLocation.getUrlGMaps()).isEqualTo(UPDATED_URL_G_MAPS);
}
use of com.arnaugarcia.uplace.service.dto.LocationDTO in project uplace.es by Uplace.
the class LocationResourceIntTest method updateNonExistingLocation.
@Test
@Transactional
public void updateNonExistingLocation() throws Exception {
int databaseSizeBeforeUpdate = locationRepository.findAll().size();
// Create the Location
LocationDTO locationDTO = locationMapper.toDto(location);
// If the entity doesn't have an ID, it will be created instead of just being updated
restLocationMockMvc.perform(put("/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(databaseSizeBeforeUpdate + 1);
}
use of com.arnaugarcia.uplace.service.dto.LocationDTO in project uplace.es by Uplace.
the class LocationResourceIntTest method createLocationWithExistingId.
@Test
@Transactional
public void createLocationWithExistingId() throws Exception {
int databaseSizeBeforeCreate = locationRepository.findAll().size();
// Create the Location with an existing ID
location.setId(1L);
LocationDTO locationDTO = locationMapper.toDto(location);
// An entity with an existing ID cannot be created, so this API call must fail
restLocationMockMvc.perform(post("/api/locations").contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(locationDTO))).andExpect(status().isBadRequest());
// Validate the Location in the database
List<Location> locationList = locationRepository.findAll();
assertThat(locationList).hasSize(databaseSizeBeforeCreate);
}
use of com.arnaugarcia.uplace.service.dto.LocationDTO in project uplace.es by Uplace.
the class LocationResource method updateLocation.
/**
* PUT /locations : Updates an existing location.
*
* @param locationDTO the locationDTO to update
* @return the ResponseEntity with status 200 (OK) and with body the updated locationDTO,
* or with status 400 (Bad Request) if the locationDTO is not valid,
* or with status 500 (Internal Server Error) if the locationDTO couldn't be updated
* @throws URISyntaxException if the Location URI syntax is incorrect
*/
@PutMapping("/locations")
@Timed
public ResponseEntity<LocationDTO> updateLocation(@RequestBody LocationDTO locationDTO) throws URISyntaxException {
log.debug("REST request to update Location : {}", locationDTO);
if (locationDTO.getId() == null) {
return createLocation(locationDTO);
}
Location location = locationMapper.toEntity(locationDTO);
location = locationRepository.save(location);
LocationDTO result = locationMapper.toDto(location);
return ResponseEntity.ok().headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, locationDTO.getId().toString())).body(result);
}
use of com.arnaugarcia.uplace.service.dto.LocationDTO 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);
}
Aggregations