Ejemplo n.º 1
0
def getOffer(request, offerId):
    print "Here"
    ms = MerchantService();
    try:
        serializer = MerchantOfferSerializer(ms.getOffer(offerId), many=False)
        return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
    except:
        return JSONResponse(SSUtil.err(SSException.INVALID_INPUT), status=status.HTTP_400_BAD_REQUEST)
Ejemplo n.º 2
0
def offer(request, offerId):
    ms = MerchantService();
    if request.method == 'GET':
        try:
            serializer = MerchantOfferSerializer(ms.getOffer(offerId), many=False)
            return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.INVALID_INPUT), status=status.HTTP_400_BAD_REQUEST)
    else:
        title = None
        description = None
        endDate = None
        code = None
        codeType = "text"
        categoryId = None
        if not 'title' in request.DATA or request.DATA['title'] is None:
            return JSONResponse(SSUtil.err("Title  is required"),
                                status=status.HTTP_412_PRECONDITION_FAILED)
        else:
            title =  request.DATA['title']
        if 'description' in request.DATA and not request.DATA['description'] is None:
            description = request.DATA['description']
        if 'endDate' in request.DATA and not request.DATA['endDate'] is None:
            endDate = request.DATA['endDate']
        if 'code' in request.DATA and not request.DATA['code'] is None:
            code = request.DATA['code']
        if 'codeType' in request.DATA and not request.DATA['codeType'] is None:
            codeType = request.DATA['codeType']
        if 'categoryId' in request.DATA and not request.DATA['categoryId'] is None:
            categoryId = request.DATA['categoryId']
        try:
            ser = MerchantOfferSerializer(ms.updateOffer(offerId,title,description,
                            code,codeType,endDate))
            return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
        except:
            return JSONResponse(SSUtil.err(SSException.PROCESSING_FAILED),
                                status=status.HTTP_500_INTERNAL_SERVER_ERROR)