Subversion Repositories SmartDukaan

Rev

Rev 13582 | Rev 13629 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

import falcon
import json
from dtr import main
from dtr.storage import Mongo 


class CategoryDiscountInfo(object):
    
    def on_get(self, req, resp):
        
        resp.body = str(Mongo.getAllCategoryDiscount()) 
    
    def on_post(self, req, resp):
        
        try:
            result_json = json.loads(req.stream.read(), encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')
            
        result = Mongo.addCategoryDiscount(result_json)
        resp.body = json.dumps(result, encoding='utf-8')

class SkuSchemeDetails(object):
    
    def on_get(self, req, resp):

        resp.body = str(Mongo.getAllSkuWiseSchemeDetails()) 
    
    def on_post(self, req, resp):
        
        try:
            result_json = json.loads(req.stream.read(), encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')
            
        result = Mongo.addSchemeDetailsForSku(result_json)
        resp.body = json.dumps(result, encoding='utf-8')
        
class SkuDiscountInfo():
    
    def on_get(self, req, resp):

        resp.body = str(Mongo.getallSkuDiscountInfo()) 
    
    def on_post(self, req, resp):
        
        try:
            result_json = json.loads(req.stream.read(), encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')
            
        result = Mongo.addSkuDiscountInfo(result_json)
        resp.body = json.dumps(result, encoding='utf-8')

class ExceptionalNlc():
    
    def on_get(self, req, resp):

        resp.body = str(Mongo.getAllExceptionlNlcItems()) 
    
    def on_post(self, req, resp):
        
        try:
            result_json = json.loads(req.stream.read(), encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')
            
        result = Mongo.addExceptionalNlc(result_json)
        resp.body = json.dumps(result, encoding='utf-8')
        
class StoreOrder():
    def on_post(self, req, resp):
        
        try:
            req_json = json.loads(req.stream.read(), encoding='utf-8')
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')
            
        store = main.getStore(req_json['sourceId'])
        result = store.parseOrderRawHtml(req_json['orderId'], req_json['subTagId'], req_json['userId'], req_json['rawHtml'], req_json['orderSuccessUrl'])
        resp.body = json.dumps({"result":result}, encoding='utf-8')
    
    def on_get(self, req, resp, userId):
        page = req.get_param_as_int("page")
        window = req.get_param_as_int("window")
        result = Mongo.getMerchantOrdersByUser(int(userId), page, window)
        print result
        resp.body = json.dumps(result, encoding='utf-8')