示例#1
0
def delete_product(request):
    try:
        requestbody = request.body.decode("utf-8")
        product = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if not len(product) or not "productID" in product or not validate_integer(
            product["productID"]):
        return customResponse(400,
                              error_code=5,
                              error_details="Id for product not sent")

    productPtr = Product.objects.filter(id=int(product["productID"]),
                                        delete_status=False)

    if len(productPtr) == 0:
        return customResponse(400,
                              error_code=6,
                              error_details="Invalid id for product sent")

    productPtr = productPtr[0]

    try:
        productPtr.delete_status = True
        productPtr.save()
    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=3)
    else:
        closeDBConnection()
        return customResponse(200, {"product": "product deleted"})
def put_buyer_firebase_token_details(request, parameters):
    try:
        requestbody = request.body.decode("utf-8")
        buyer = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if not len(buyer) or not BuyerFireBaseToken.validateBuyerFireBaseTokenData(
            buyer):
        return customResponse(400,
                              error_code=5,
                              error_details="Invalid data sent in request")
    try:
        buyerID = parameters["buyersArr"][0]
    except Exception as e:
        buyerID = None

    try:

        buyerFireBaseTokenPtr, created = BuyerFireBaseToken.objects.get_or_create(
            instance_id=buyer["instance_id"])
        buyerFireBaseTokenPtr.buyer_id = buyerID
        buyerFireBaseTokenPtr.token = buyer["token"]
        buyerFireBaseTokenPtr.save()

    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=1)
    else:
        return customResponse(200, {"token": "token successfully created"})
示例#3
0
def buyer_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateBuyerProductParameters(request, {}, version)

	if request.method == "GET":

		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0 and parameters["isBuyerStore"] == 0:
			return customResponse(403, error_code = 8)

		return buyer.get_buyer_details(request,parameters)
	elif request.method == "POST":
		if parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)
		return buyer.post_new_buyer(request)
	elif request.method == "PUT":

		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)

		return buyer.update_buyer(request, parameters)
	elif request.method == "DELETE":

		if parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)

		return buyer.delete_buyer(request, parameters)

	return customResponse(404, error_code = 7)
示例#4
0
def delete_article(request):
    try:
        requestbody = request.body.decode("utf-8")
        article = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if not len(article) or not "articleID" in article or not validate_integer(
            article["articleID"]):
        return customResponse(400,
                              error_code=5,
                              error_details="Id for article not sent")

    articlePtr = Article.objects.filter(id=int(article["articleID"]))

    if len(articlePtr) == 0:
        return customResponse(400,
                              error_code=6,
                              error_details="Invalid ID for article sent")

    articlePtr = articlePtr[0]

    try:
        articlePtr.delete_status = True
        articlePtr.save()
    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=3)
    else:
        closeDBConnection()
        return customResponse(200, {"body": "article deleted"})
示例#5
0
def delete_buyer(request, parameters):
    try:
        requestbody = request.body.decode("utf-8")
        buyer = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if not len(buyer) or not "buyerID" in buyer or not buyer[
            "buyerID"] or not validate_integer(buyer["buyerID"]):
        return customResponse(400,
                              error_code=5,
                              error_details="Id for buyer not sent")

    buyerPtr = Buyer.objects.filter(id=int(buyer["buyerID"]),
                                    delete_status=False)

    if len(buyerPtr) == 0:
        return customResponse(400,
                              error_code=6,
                              error_details="Invalid id for buyer sent")

    buyerPtr = buyerPtr[0]

    try:
        buyerPtr.delete_status = True
        buyerPtr.save()
    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=3)
    else:
        closeDBConnection()
        return customResponse(200, {"buyer": "buyer deleted"})
示例#6
0
def seller_login(request, version = "0"):

	version = getApiVersion(request)

	response = {}
	if request.method == 'POST':
		email = request.POST.get('email', '')
		password = request.POST.get('password', '')

		if not email or not password:
			return customResponse(400, error_code=5, error_details= "Either email or password was empty")

		# if check_token(request)
		try:
			seller = Seller.objects.get(email=email, delete_status=False)
		except Seller.DoesNotExist:
			return customResponse(401, error_code=9, error_details="Invalid seller credentials")

		if password == seller.password:
			response = {
				"token": getSellerToken(seller),
				"seller": serialize_seller(seller)
			}
			return customResponse(200, response)
		else:
			return customResponse(401, error_code=9, error_details="Invalid seller credentials")

	return customResponse(404, error_code = 7)
示例#7
0
def post_new_category(request):
    try:
        requestbody = request.body.decode("utf-8")
        category = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if not len(category) or not validateCategoryData(category, Category(), 1):
        return customResponse(400,
                              error_code=5,
                              error_details="Invalid data for category sent")

    category["slug"] = slugify(category["name"])

    try:
        newCategory = Category()
        populateCategoryData(newCategory, category)
        newCategory.save()

    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=1)
    else:
        closeDBConnection()
        return customResponse(
            200, {"categories": serialize_categories(newCategory)})
示例#8
0
def get_buyer_access_token_details(request, parameters={}):
    try:
        buyerPanelURL = parameters["buyer_panel_url"].split("-")
        try:
            buyerID = int(buyerPanelURL[0])
            timeStamp = int(buyerPanelURL[1])
        except Exception as e:
            return customResponse(400,
                                  error_code=5,
                                  error_details="Invalid data in request sent")

        buyerPtr = Buyer.objects.get(id=buyerID)

        if int(time.mktime(buyerPtr.created_at.timetuple())) != timeStamp:
            closeDBConnection()
            return customResponse(400,
                                  error_code=6,
                                  error_details="Invalid time sent")

        from urlHandlers.user_handler import getBuyerToken

        response = {
            "token": getBuyerToken(buyerPtr),
            "buyer": serialize_buyer(buyerPtr)
        }
        closeDBConnection()

        return customResponse(200, response)
    except Exception as e:
        closeDBConnection()
        log.critical(e)
        return customResponse(500)
示例#9
0
def post_new_buyer_panel_tracking(request, parameters):
	try:
		requestbody = request.body.decode("utf-8")
		buyer = convert_keys_to_string(json.loads(requestbody))
	except Exception as e:
		return customResponse(400, error_code=4)

	#if not len(buyer) or not "buyerID" in buyer or not validate_integer(buyer["buyerID"]):
	#	return customResponse("4XX", {"error": "Id for buyer not sent"})

	buyer["buyerID"] = parameters["buyersArr"][0]

	buyerPtr = Buyer.objects.filter(id=int(buyer["buyerID"]), delete_status=False)

	if not buyerPtr.exists():
		return customResponse(400, error_code=6, error_details= "Invalid id for buyer sent")

	if not "page_closed" in buyer or buyer["page_closed"] ==None:
		return customResponse(400, error_code=6, error_details= "Page number not sent")
	try:
		newBuyerPanelInstructionsTracking = BuyerPanelInstructionsTracking(buyer_id=int(buyer["buyerID"]), page_closed=buyer["page_closed"])
		newBuyerPanelInstructionsTracking.save()

	except Exception as e:
		log.critical(e)
		closeDBConnection()
		return customResponse(500, error_code = 1)
	else:
		closeDBConnection()
		return customResponse(200, {"buyer_product_tracking":"successfully added"})
示例#10
0
def get_buyer_product_response_count_details(request, parameters={}):
    try:
        if not "buyersArr" in parameters:
            return customResponse(400,
                                  error_code=5,
                                  error_details="Id for buyer not sent")

        buyerID = parameters["buyersArr"][0]

        buyerProductResponseCount = BuyerProductResponse.objects.filter(
            product__delete_status=False,
            product__seller__delete_status=False,
            product__seller__show_online=True,
            product__category__delete_status=False,
            buyer_id=buyerID,
            response_code=1).count()

        response = {"like_count": buyerProductResponseCount}

        statusCode = 200

    except Exception as e:
        log.critical(e)
        statusCode = 500
        response = {}

    closeDBConnection()
    return customResponse(statusCode, response)
示例#11
0
def delete_buyer_buys_from(request, parameters):
    try:
        requestbody = request.body.decode("utf-8")
        buyer_buys_from = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if not len(
            buyer_buys_from
    ) or not "buyerbuysfromID" in buyer_buys_from or not validate_integer(
            buyer_buys_from["buyerbuysfromID"]):
        return customResponse(400,
                              error_code=5,
                              error_details="Id for buyer buys_from not sent")

    buyerBuysFromPtr = BuyerBuysFrom.objects.filter(
        id=int(buyer_buys_from["buyerbuysfromID"]))

    if len(buyerBuysFromPtr) == 0:
        return customResponse(
            400,
            error_code=6,
            error_details="Invalid id for buyer buys_from sent")

    try:
        buyerBuysFromPtr.update(delete_status=True, updated_at=timezone.now())
    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=3)
    else:
        closeDBConnection()
        return customResponse(200, {"buyer": "buyer buys_from deleted"})
示例#12
0
def get_buyer_renew_access_token(request, parameters):

    refresh_token = getAccessToken(request, "refresh_token")

    if refresh_token == "":
        return customResponse(400,
                              error_code=5,
                              error_details="Refresh token not sent")

    tokenPayload = validateBuyerRefreshToken(refresh_token)

    if tokenPayload == {}:
        return customResponse(403, error_code=7, error_details="Token invalid")

    buyerRefreshTokenPtr = BuyerRefreshToken.objects.filter(
        id=int(tokenPayload["jti"]))
    buyerRefreshTokenPtr = buyerRefreshTokenPtr[0]

    try:
        newBuyerAccessToken = BuyerAccessToken()
        newBuyerAccessToken.populateFromRefreshToken(buyerRefreshTokenPtr)
        newBuyerAccessToken.save()

    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=1)
    else:
        response_body = {}
        response_body["access_token"] = serialize_buyer_access_token(
            newBuyerAccessToken, parameters)

        closeDBConnection()
        return customResponse(200, {"buyer_login": response_body})
示例#13
0
def buyer_interest_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateBuyerParameters(request, {}, version )

	if request.method == "GET":

		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)

		return buyer.get_buyer_interest_details(request,parameters)
	elif request.method == "POST":
		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)
		return buyer.post_new_buyer_interest(request, parameters)
	elif request.method == "PUT":
		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)
		return buyer.update_buyer_interest(request, parameters)
	#elif request.method == "DELETE":
	#	if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0:
	#		return customResponse("4XX", {"error": "Authentication failure"})
	#	return buyer.delete_buyer_interest(request, parameters)

	return customResponse(404, error_code = 7)
示例#14
0
def article_cover_photo_details(request, version="0"):
    version = getApiVersion(request)

    if request.method == 'POST':
        parameters = getArticleParameters(request, {}, version)
        if parameters["isInternalUser"] == 0:
            return customResponse(403, error_code=8)
        return article.upload_article_file(request)

    return customResponse(404, error_code=7)
示例#15
0
def get_buyer_details(request, parameters={}):
    try:
        buyers = filterBuyer(parameters)

        response = {"buyers": parse_buyer(buyers, parameters)}
        closeDBConnection()

        return customResponse(200, response)
    except Exception as e:
        log.critical(e)
        return customResponse(500)
示例#16
0
def get_state_details(request, stateParameters):
    try:
        states = filterState(stateParameters)

        response = {"states": parse_state(states)}
        closeDBConnection()

        return customResponse(200, response)
    except Exception as e:
        log.critical(e)
        return customResponse(500, error_code=0)
示例#17
0
def post_new_buyer_address(request, parameters):
    try:
        requestbody = request.body.decode("utf-8")
        buyer_address = convert_keys_to_string(json.loads(requestbody))
    except Exception as e:
        return customResponse(400, error_code=4)

    if parameters["isBuyer"] == 1:
        buyer_address["buyerID"] = parameters["buyersArr"][0]
    elif not "buyerID" in buyer_address or not validate_integer(
            buyer_address["buyerID"]):
        return customResponse(400,
                              error_code=5,
                              error_details="Id for buyer not sent")

    if not len(buyer_address) or not validateBuyerAddressData(
            buyer_address, BuyerAddress(), 1):
        return customResponse(
            400,
            error_code=5,
            error_details="Invalid data for buyer address sent")

    try:
        addressPresent = False
        if "client_id" in buyer_address and str(
                buyer_address["client_id"]) != "" and len(
                    str(buyer_address["client_id"])) > 6:
            newAddress = BuyerAddress.objects.filter(
                buyer_id=int(buyer_address["buyerID"]),
                client_id=str(buyer_address["client_id"]))
            if len(newAddress) != 0:
                addressPresent = True
                newAddress = newAddress[0]
        if not addressPresent:
            newAddress = BuyerAddress(buyer_id=int(buyer_address["buyerID"]))
            if not BuyerAddress.objects.filter(
                    buyer_id=int(buyer_address["buyerID"])).exists():
                newAddress.priority = 0
        populateBuyerAddress(newAddress, buyer_address)
        newAddress.save()

        newBuyerAddressHistory = BuyerAddressHistory()
        newBuyerAddressHistory.populateFromBuyerAddress(newAddress)
        newBuyerAddressHistory.save()

    except Exception as e:
        log.critical(e)
        closeDBConnection()
        return customResponse(500, error_code=1)
    else:
        closeDBConnection()
        return customResponse(200,
                              {"address": serialize_buyer_address(newAddress)})
示例#18
0
def buyer_panel_tracking_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateBuyerParameters(request, {}, version)

	if request.method == "POST":
		if parameters["isBuyer"] == 0:
			return customResponse(403, error_code = 8)
		return buyer.post_new_buyer_panel_tracking(request, parameters)

	return customResponse(404, error_code = 7)
示例#19
0
def cart_details(request, version = "0"):

	version = getApiVersion(request)

	cartParameters = populateCartParameters(request, {}, version)

	if request.method == "GET":
		if cartParameters["isBuyer"] == 0 and cartParameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)
		return cart.get_cart_details(request,cartParameters)

	return customResponse(404, error_code = 7)
示例#20
0
def buyer_product_master_update(request,version = "0"):

	version = getApiVersion(request)

	parameters = populateInternalUserIDParameters(request, {}, version)

	if request.method == "POST":
		if parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)
		return buyer.master_update_buyer_product(request)

	return customResponse(404, error_code = 7)
示例#21
0
def buyer_product_whatsapp_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateBuyerProductParameters(request, {}, version )
	
	if request.method == "PUT":
		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)
		return buyer.update_buyer_product_whatsapp(request, parameters)

	return customResponse(404, error_code = 7)
示例#22
0
def checkout_payment_method_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateCheckoutParameters(request, {}, version)

	if request.method == "GET":
		if parameters["isBuyer"] == 0:
			return customResponse(403, error_code = 8)
		return checkout.get_payment_method(request, parameters)

	return customResponse(404, error_code = 7)
示例#23
0
def get_internal_user_details(request,parameters = {}):
	try:
		internalUsers = filterInternalUser(parameters)

		response = {
			"internal_users" : parseInternalUser(internalUsers, parameters)
		}
		closeDBConnection()

		return customResponse(200, response)
	except Exception as e:
		log.critical(e)
		return customResponse(500)
示例#24
0
def user_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateAllUserIDParameters(request, {}, version)

	if request.method == "GET":
		if parameters["isBuyer"] == 0 and parameters["isInternalUser"] == 0 and parameters["isSeller"]:
			return customResponse(403, error_code = 8)

		return user.get_user_details(request)

	return customResponse(404, error_code = 7)
示例#25
0
def get_business_type_details(request, parameters={}):
    try:
        businessTypes = filterBusinessType(parameters)

        response = {
            "business_types": parse_business_type(businessTypes, parameters)
        }
        closeDBConnection()

        return customResponse(200, response)
    except Exception as e:
        log.critical(e)
        return customResponse(500, error_code=0)
示例#26
0
def get_buyer_purchasing_state_details(request,parameters = {}):
	try:
		buyersPurchasingState = filterBuyerPurchasingState(parameters)

		response = {
			"buyer_purchasing_states" : parse_buyer_purchasing_state(buyersPurchasingState, parameters)
		}
		closeDBConnection()

		return customResponse(200, response)
	except Exception as e:
		log.critical(e)
		return customResponse(500)
示例#27
0
def business_type_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateBusinessTypeParameters(request, {}, version)

	if request.method == "GET":

		if parameters["isSeller"] == 0 and parameters["isInternalUser"] == 0 and parameters["isBuyer"] == 0 and parameters["isBuyerStore"] == 0:
			return customResponse(403, error_code = 8)
		
		return businesstype.get_business_type_details(request,parameters)

	return customResponse(404, error_code = 7)
示例#28
0
def get_buyer_store_url_exists_details(request, parameters):
	try:
		store_url = request.GET.get("store_url_exists", "")
		if store_url == None or len(store_url) < 6:
			return customResponse(400, error_code=6, error_details=  "Invalid url sent")
		store_url_exists = Buyer.objects.filter(store_url = store_url).exists()
		response = {
			"store_url_exists" : store_url_exists
		}
		closeDBConnection()
		return customResponse(200, response)
	except Exception as e:
		log.critical(e)
		return customResponse(500)
示例#29
0
def internal_user_details(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateInternalUserIDParameters(request, {}, version)

	if request.method == "GET":

		if  parameters["isInternalUser"] == 0:
			return customResponse(403, error_code = 8)

		return internaluser.get_internal_user_details(request,parameters)

	return customResponse(404, error_code = 7)
示例#30
0
def buyer_change_password(request, version = "0"):

	version = getApiVersion(request)

	parameters = populateBuyerIDParameters(request, {}, version)

	if request.method == 'POST':

		if  parameters["isBuyer"] == 0:
			return customResponse(403, error_code = 8)

		return buyer.post_buyer_change_password(request,parameters)

	return customResponse(404, error_code = 7)