Exemple #1
0
def post():

    fullName = request.json["fullName"]
    companyName = request.json["companyName"]
    taxId = request.json["taxId"]
    email = request.json["email"]
    phoneNumber = request.json["phoneNumber"]

    taxId, errors = ApiValidators.validateTaxId(taxId)
    email, errors = ApiValidators.validateEmail(email)
    companyName, errors = ApiValidators.validateCompanyName(companyName)
    phoneNumber, errors = ApiValidators.validatePhone(phoneNumber)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    try:
        Advertiser.newItem(fullName=fullName,
                           companyName=companyName,
                           taxId=taxId,
                           email=email,
                           phoneNumber=phoneNumber)
        return ApiResponses.successMessage(
            message="sucesso",
            item="Empresa '{}' foi registrada".format(companyName))
    except Exception as error:
        return ApiResponses.badRequestMessage("{}".format(error))
Exemple #2
0
def get():
    queryStringTaxId = request.args.get("taxId")
    queryStringCategory = request.args.get("category")
    title = request.args.get("title")
    tags = request.args.get("tags")
    price = request.args.get("price")
    creationDate = request.args.get("creationDate")

    taxId, errors = ApiValidators.validateTaxId(taxId=queryStringTaxId)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    if queryStringTaxId:
        advertisement = Advertisement.queryByTaxId(taxId)
        return ApiResponses.successMessage(item=advertisement)

    if not title or not tags:
        return ApiResponses.badRequestMessage("Parâmetro querystring 'title' ou 'tags' está faltando.")

    if price and not isinstance(price, float):
        return ApiResponses.badRequestMessage("Campo 'price' inválido, ex: 103.5 deve ser do tipo inteiro.")

    if creationDate and not ApiValidators.isDateISO8601(creationDate):
        return ApiResponses.badRequestMessage("Parâmetro 'creationDate' incorreto, ex: '2016-11-14'.")

    return ApiResponses.badRequestMessage("Não foi possível fazer requisição")
Exemple #3
0
def get():
    queryStringTaxId = request.args.get("taxId")
    queryStringEmail = request.args.get("email")

    taxId, errors = ApiValidators.validateTaxId(taxId=queryStringTaxId)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    if queryStringTaxId:
        advertiser = Advertiser.queryByTaxId(taxId)
        return ApiResponses.successMessage(item=advertiser)

    if queryStringEmail and queryStringTaxId:
        email = ApiValidators.validateEmail(queryStringEmail)
        taxId = ApiValidators.validateTaxId(queryStringTaxId)
        advertiser = Advertiser.queryByTaxIdAndEmail(taxId, email)
        return ApiResponses.successMessage(item=advertiser)

    if Advertiser.exists():
        advertiser = Advertiser.queryByTaxId(taxId=queryStringTaxId)
        return ApiResponses.successMessage(Advertiser.json(advertiser))

    if not queryStringEmail and not queryStringTaxId:
        advertisers = Advertiser.scanAll()
        return ApiResponses.successMessage(item=advertisers)
Exemple #4
0
def delete():
    queryStringTaxId = request.args.get("taxId")
    queryStringEmail = request.args.get("email")

    taxId = ApiValidators.validateTaxId(queryStringTaxId)
    email = ApiValidators.validateEmail(queryStringEmail)
    try:
        advertiser = Advertiser.deleteItem(taxId, email)
        return ApiResponses.successMessage(
            message="Empresa deletada com sucesso",
            item=Advertiser.json(advertiser))
    except Exception as error:
        return ApiResponses.badRequestMessage(
            "Não foi possível deletar empresa {0}, {1}".format(taxId, error))
Exemple #5
0
def post():
    taxId = request.json.get("taxId")
    password = request.json.get("password")
    fullName = request.json.get("fullName")
    email = request.json.get("email")
    phoneNumber = request.json.get("phoneNumber")
    permissions = request.json.get("permissions")

    taxId, errors = ApiValidators.validateTaxId(taxId)
    email, errors = ApiValidators.validateEmail(email)
    password, errors = ApiValidators.validatePassword(password)
    permissions, errors = ApiValidators.validatePermissions(permissions)
    phoneNumber, errors = ApiValidators.validatePhone(phoneNumber)
    fullName, errors = ApiValidators.validateUsername(fullName)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    if session.get("loggedin"):
        return ApiResponses.badRequestMessage(error="Usuário já logado")

    user = User.queryUserByTaxId(taxId)
    if user:
        return ApiResponses.badRequestMessage(
            error="Usuário já existe, verifique sua conta...")

    try:
        User.newItem(fullName, password, taxId, email, phoneNumber,
                     permissions)
        return ApiResponses.successMessage(
            message="sucesso",
            item="Usuário '{}' foi registrado".format(fullName))
    except Exception as error:
        return ApiResponses.badRequestMessage(
            "Não foi possível criar usuário, {}".format(error))
Exemple #6
0
def get():
    queryStringtaxId = request.args.get("taxId")

    taxId, errors = ApiValidators.validateTaxId(queryStringtaxId)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    try:
        user = validateUser(taxId)
        return ApiResponses.successMessage(
            item="Usuário {} logado".format(user.fullName))
    except:
        return ApiResponses.badRequestMessage("Usuário inválido!")
Exemple #7
0
def post():

    title = request.json.get("title")
    category = request.json.get("category")
    description = request.json.get("description")
    price = request.json.get("price")
    tags = request.json.get("tags")
    phoneNumber = request.json.get("phoneNumber")

    tags, errors = ApiValidators.validateTags(tags)
    price, errors = ApiValidators.validatePrice(price)
    phoneNumber, errors =ApiValidators.validatePhone(phoneNumber)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    whatsAppApi = "None"

    if phoneNumber:
        whatsAppApi = "https://wa.me/{}?text=Ol%C3%A1," \
                      "%20gostaria%20de%20saber%20mais%20sobre%20o%20portal%20ATNAP".format(phoneNumber)

    try:
        Advertisement.newItem(
            title=title,
            description=description,
            price=price,
            category=category,
            advertiserTaxId="06.990.590/0001-23",
            phoneNumber=phoneNumber,
            whatsAppApi=whatsAppApi,
            tags=tags,
        )
        return ApiResponses.successMessage(message="sucesso", item="Anúncio '{}' foi registrado".format(title))
    except Exception as error:
        return ApiResponses.badRequestMessage("Erro ao criar anúncio! {}".format(error))
Exemple #8
0
def delete():

    queryStringtaxId = request.args.get("taxId")
    taxId, errors = ApiValidators.validateTaxId(queryStringtaxId)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    user = User.queryUserByTaxId(taxId)
    if user:
        user.delete()
        return ApiResponses.successMessage(
            message="Usuário deletado com sucesso", item=User.json(user))

    return ApiResponses.notFoundMessage("Usuário não encontrado")
Exemple #9
0
def get():
    queryStringtaxId = request.args.get("taxId")
    taxId, errors = ApiValidators.validateTaxId(queryStringtaxId)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    if not validLoggedUser(taxId):
        return ApiResponses.forbiddenMessage("Cadastro inválido!")

    try:
        validLoggedUser(taxId)
        user = validateUser(taxId)
        return ApiResponses.successMessage(item=User.json(user))
    except:
        return ApiResponses.badRequestMessage("Usuário inválido!")
Exemple #10
0
def post():
    try:
        taxId = request.json.get("taxId")
        password = request.json.get("password")
    except:
        return ApiResponses.badRequestMessage(
            "Parâmetros 'taxId' e 'password' necessários")

    taxId, errors = ApiValidators.validateTaxId(taxId)

    if len(errors) > 0:
        return ApiResponses.badRequestMessage(errors)

    user = validateUser(taxId)

    if validCredentials(user, taxId, password):
        session["loggedin"] = True
        session["user"] = User.json(user)
        return ApiResponses.successMessage(
            item="Usuário {} logado com sucesso".format(taxId))

    return ApiResponses.badRequestMessage("Senha incorreta!")