public class UserQueryHandler extends AbstractRequestHandler<EmptyPayload> { private static final ZuzuLogger logger = ZuzuLogger.getLogger(UserQueryHandler.class); private UserService service = null; public UserQueryHandler(UserService service) { super(EmptyPayload.class); this.service = service; } @Override protected Answer processImpl(EmptyPayload value, Map<String, String> urlParams) { logger.entering("processImpl", "{value: %s, urlParams: %s}", value, urlParams); Optional<User> existUser = Optional.empty(); if (urlParams.containsKey(":userid")) { existUser = this.service.getUserById(urlParams.get(":userid")); } else if (urlParams.containsKey(":email")) { existUser = this.service.getUserByEmail(urlParams.get(":email")); } else { return Answer.bad_request(); } if (existUser.isPresent()) { UserQueryPayload userPayload = new UserQueryPayload(); userPayload.fromUser(existUser.get()); return Answer.ok(userPayload); } return Answer.no_data(); } }
@Override protected Answer processImpl(EmptyPayload value, Map<String, String> urlParams) { logger.entering("processImpl", "{value: %s, urlParams: %s}", value, urlParams); Optional<User> existUser = Optional.empty(); if (urlParams.containsKey(":userid")) { existUser = this.service.getUserById(urlParams.get(":userid")); } else if (urlParams.containsKey(":email")) { existUser = this.service.getUserByEmail(urlParams.get(":email")); } else { return Answer.bad_request(); } if (existUser.isPresent()) { UserQueryPayload userPayload = new UserQueryPayload(); userPayload.fromUser(existUser.get()); return Answer.ok(userPayload); } return Answer.no_data(); }