def getMerchantOffers(request): ms = MerchantService(); st = None if 'status' in request.GET and not request.GET['status'] is None and request.GET['status'] != '': st = request.GET['status'] serializer = MerchantOfferSerializer(ms.getOffers(request.user.id, st), many=True) return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)
def addOffer(request): ms = MerchantService() title = None description = None endDate = None code = None codeType = "text" categoryId = None imgUrl = None if not 'title' in request.POST or request.POST['title'] is None: return JSONResponse(SSUtil.err("Title is required"), status=status.HTTP_412_PRECONDITION_FAILED) else: title = request.POST['title'] if 'description' in request.POST and not request.POST['description'] is None: description = request.POST['description'] if 'endDate' in request.POST and not request.POST['endDate'] is None: endDate = request.POST['endDate'] if 'code' in request.POST and not request.POST['code'] is None: code = request.POST['code'] if 'codeType' in request.POST and not request.POST['codeType'] is None: codeType = request.POST['codeType'] if 'imgUrl' in request.FILES and not request.FILES['imgUrl'] is None: print "imgurl is not none" imgUrl = request.FILES['imgUrl'] # try: ser = MerchantOfferSerializer(ms.addOffer(request.user.id,title,description, code,codeType,endDate,categoryId, imgUrl)) return JSONResponse(SSUtil.success(ser.data), status=status.HTTP_200_OK)
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)
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)
def markOfferStatus(request, offerId): ms = MerchantService(); st = None if not 'status' in request.DATA or request.DATA['status'] is None: return JSONResponse(SSUtil.err("Status is required"), status=status.HTTP_412_PRECONDITION_FAILED) else: st = request.DATA['status'] try: ser = MerchantOfferSerializer(ms.markOfferStatus(offerId,st)) 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)
def getAllOffers(request): ssConst = SSConst() st = ssConst.OFFER_STATUSES[0][0] ms = MerchantService(); serializer = MerchantOfferSerializer(ms.getAllOffers(st), many=True) return JSONResponse(SSUtil.success(serializer.data), status=status.HTTP_200_OK)