@RequestMapping(value="/get-by-email") @ResponseBody public String getByEmail(String email) { String userId; try { User user = _userDao.getByEmail(email); userId = String.valueOf(user.getId()); } catch(Exception ex) { return "User not found"; } return "The user id is: " + userId; }
/** * Retrieve the id for the user with the passed email address. */ @RequestMapping(value="/get-by-email") @ResponseBody public String getByEmail(String email) { String userId; try { User user = userDao.getByEmail(email); userId = String.valueOf(user.getId()); } catch (Exception ex) { return "User not found: " + ex.toString(); } return "The user id is: " + userId; }
/** * /get-by-email --> Return the id for the user having the passed email. * * @param email The email to search in the database. * @return The user id or a message error if the user is not found. */ @RequestMapping("/get-by-email") @ResponseBody public String getByEmail(String email) { String userId; try { User user = userDao.findByEmail(email); userId = String.valueOf(user.getId()); } catch (Exception ex) { return "User not found"; } return "The user id is: " + userId; }
/** * /user/get?email=[email] -> return the user having the passed email. * * @param email The email to search in the database. * @return The user id or a message error if the user is not found. */ @RequestMapping("/user/get") @ResponseBody public String getUser(String email) { String userId = ""; String userType = ""; try { User user = userRepository.findByEmail(email); userId = String.valueOf(user.getId()); // get the user type if (user instanceof Person) userType = "Person"; else if (user instanceof Company) userType = "Company"; } catch (Exception ex) { return "User not found"; } return "The " + userType + " id is: " + userId; }
/** * /create --> Create a new user and save it in the database. * * @param email User's email * @param name User's name * @return A string describing if the user is successfully created or not. */ @RequestMapping("/create") @ResponseBody public String create(String email, String name) { User user = null; try { user = new User(email, name); userDao.save(user); } catch (Exception ex) { return "Error creating the user: " + ex.toString(); } return "User succesfully created! (id = " + user.getId() + ")"; }