def create_user(user, user_by_cellphone, user_by_email): if user_by_email or user_by_cellphone: raise RequestException('Já existe um usuário com o mesmo telefone ou e-mail') if user.oid: raise RequestException("OID deve ser gerado dinamicamente") if not user.password: raise RequestException("Campo 'password' é obrigatório") if not user.cellphone: raise RequestException("Campo 'cellphone' é obrigatório") user.available_votes = 5
def handler(event, context): body = get_json_body(event) if not body: raise RequestException("Request inválido!") if not isinstance(body, list): raise RequestException("Esperado uma lista!") teams = TeamFacade.define_teams_position(body) return buid_default_response(status=200, body=json.dumps(teams, cls=SWMJSONEncoder))
def get_key_value_param(event): body = get_json_body(event) if not body: raise RequestException("Request inválido!") cellphone = body.get("cellphone") email = body.get("email") if not cellphone and not email: raise RequestException("Informe o e-mail ou o telefone") field = 'email' if email else 'cellphone' value = email if email else cellphone return field, value
def handler(event, context): path_params = get_path_params(event) if not path_params: raise RequestException("Request inválido!") oid_request_team = path_params.get('oid') if not oid_request_team: raise RequestException("Solicitação de entrada no time não informado") session = SessionFacade.get_session_from_event(event) team_request = TeamRequestFacade.approve_request(session.real_user, oid_request_team) return buid_default_response(status=200, body=json.dumps(team_request, cls=SWMJSONEncoder))
def handler(event, context): body = get_json_body(event) if not body: raise RequestException("Request inválido!") oid_team = body.get('oid_team') if not oid_team: raise RequestException("Time não informado") session = SessionFacade.get_session_from_event(event) team_request = TeamRequestFacade.create_new_request( session.real_user, oid_team) return buid_default_response(status=201, body=json.dumps(team_request, cls=SWMJSONEncoder))
def handler(event, context): body = event.get('body') if not body: raise RequestException("Request inválido!") path_params = get_path_params(event) oid = path_params.get('oid', None) if not oid: print(json.dumps(path_params)) raise RequestException("ID inválido") session = SessionFacade.get_session_from_event(event) user_photo = UserPhotoFacade.update_user_photo(session, oid, body) return buid_default_response(status=200, body=json.dumps(user_photo, cls=SWMJSONEncoder))
def handler(event, context): body = get_json_body(event) if not body: raise RequestException("Request inválido!") path_params = get_path_params(event) oid = path_params.get('oid', None) if not oid: print(json.dumps(path_params)) raise RequestException("ID inválido") pitch = PitchBuilder().from_json(body).build() oid_user = body.get('oid_user') PitchFacade.edit_pitch(oid, pitch, oid_user) return buid_default_response(status=201, body=json.dumps(pitch, cls=SWMJSONEncoder))
def handler(event, context): body = get_json_body(event) if not body: raise RequestException("Request inválido!") user = UserBuilder().from_json(body, encrypt_password=True).build() UserFacade.create_user(user) return buid_default_response(status=201, body=json.dumps(user, cls=SWMJSONEncoder))
def handler(event, context): path_params = get_path_params(event) oid = path_params.get('oid', None) if not oid: print(json.dumps(path_params)) raise RequestException("ID inválido") session = SessionFacade.get_session_from_event(event) user_photo = UserPhotoFacade.get_user_photo(session, oid) if user_photo: return buid_default_response(status=200, body=user_photo.data, headers={'Content-Type': 'image/jpeg'}, base64encoded=True) else: return buid_default_response(status=404, body=json.dumps( {'message': 'Imagem não encontrada'}, cls=SWMJSONEncoder))