List of usage examples for org.springframework.web.servlet.mvc.method.annotation MvcUriComponentsBuilder fromMethodName
public static UriComponentsBuilder fromMethodName(UriComponentsBuilder builder, Class<?> controllerType, String methodName, Object... args)
From source file:ch.heigvd.gamification.api.BadgesEndpoint.java
@Override @RequestMapping(method = RequestMethod.POST) public ResponseEntity<Void> badgesPost( @ApiParam(value = "Badge to add", required = true) @RequestBody BadgeDTO body, @ApiParam(value = "token that identifies the app sending the request", required = true) @RequestHeader(value = "X-Gamification-Token", required = true) String xGamificationToken) { AuthenKey apiKey = authenKeyRepository.findByAppKey(xGamificationToken); if (apiKey == null) { return new ResponseEntity(HttpStatus.UNAUTHORIZED); }//w w w . java 2 s . c om Application app = apiKey.getApp(); if (body != null && app != null) { if (badgeRepository.findByNameAndApp(body.getName(), app) != null) { return new ResponseEntity("name already use", HttpStatus.UNPROCESSABLE_ENTITY); } Badge badge = new Badge(); badge.setDescription(body.getDescription()); badge.setName(body.getName()); badge.setImage(body.getImageURI()); badge.setApp(app); badgeRepository.save(badge); HttpHeaders responseHeaders = new HttpHeaders(); UriComponents uriComponents = MvcUriComponentsBuilder .fromMethodName(BadgesEndpoint.class, "badgesBadgeIdGet", 1, badge.getId()).build(); URI locationUri = uriComponents.toUri(); responseHeaders.add("Location", uriComponents.toString()); return new ResponseEntity<>(responseHeaders, HttpStatus.CREATED); } else { return new ResponseEntity("no content is available", HttpStatus.BAD_REQUEST); } }