Search in sources :

Example 1 with CreatedEntityInfo

use of com.haulmont.restapi.data.CreatedEntityInfo in project cuba by cuba-platform.

the class EntitiesController method createEntity.

@PostMapping("/{entityName}")
public ResponseEntity<String> createEntity(@RequestBody String entityJson, @PathVariable String entityName, @RequestParam(required = false) String modelVersion, HttpServletRequest request) {
    CreatedEntityInfo entityInfo = entitiesControllerManager.createEntity(entityJson, entityName, modelVersion);
    UriComponents uriComponents = UriComponentsBuilder.fromHttpUrl(request.getRequestURL().toString()).path("/{id}").buildAndExpand(entityInfo.getId().toString());
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setLocation(uriComponents.toUri());
    return new ResponseEntity<>(entityInfo.getJson(), httpHeaders, HttpStatus.CREATED);
}
Also used : HttpHeaders(org.springframework.http.HttpHeaders) UriComponents(org.springframework.web.util.UriComponents) ResponseEntity(org.springframework.http.ResponseEntity) CreatedEntityInfo(com.haulmont.restapi.data.CreatedEntityInfo)

Aggregations

CreatedEntityInfo (com.haulmont.restapi.data.CreatedEntityInfo)1 HttpHeaders (org.springframework.http.HttpHeaders)1 ResponseEntity (org.springframework.http.ResponseEntity)1 UriComponents (org.springframework.web.util.UriComponents)1