Search in sources :

Example 1 with CreateUserDTO

use of org.c4sg.dto.CreateUserDTO in project c4sg-services by Code4SocialGood.

the class UserController method createUser.

@RequestMapping(method = RequestMethod.POST)
@ApiOperation(value = "Add a new user")
public UserDTO createUser(@ApiParam(value = "User object to return", required = true) @RequestBody CreateUserDTO createUserDTO) {
    //calculate lat and long
    try {
        UserDTO userDTO = userService.createUser(createUserDTO);
        GeoCodeUtil geoCodeUtil = new GeoCodeUtil(userDTO);
        Map<String, BigDecimal> geoCode = geoCodeUtil.getGeoCode();
        userDTO.setLatitude(geoCode.get("lat"));
        userDTO.setLongitude(geoCode.get("lon"));
        return userService.saveUser(userDTO);
    } catch (Exception e) {
        throw new NotFoundException("Error getting geocode");
    }
}
Also used : GeoCodeUtil(org.c4sg.util.GeoCodeUtil) CreateUserDTO(org.c4sg.dto.CreateUserDTO) UserDTO(org.c4sg.dto.UserDTO) NotFoundException(org.c4sg.exception.NotFoundException) BigDecimal(java.math.BigDecimal) NotFoundException(org.c4sg.exception.NotFoundException) IOException(java.io.IOException)

Aggregations

IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1 CreateUserDTO (org.c4sg.dto.CreateUserDTO)1 UserDTO (org.c4sg.dto.UserDTO)1 NotFoundException (org.c4sg.exception.NotFoundException)1 GeoCodeUtil (org.c4sg.util.GeoCodeUtil)1