Subversion Repositories SmartDukaan

Rev

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

'''
Created on Feb 12, 2015

@author: amit
'''
from dtr import main
from dtr.storage import Mongo
import falcon
import json
class StoreOrder():
    def on_post(self, req, resp):
        
        try:
            string1 = req.stream.read()
            req_json = json.loads(string1, 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(int(req_json['sourceId']))
        result = store.parseOrderRawHtml(int(req_json['orderId']), req_json['subTagId'], int(req_json['userId']), req_json['rawHtml'], req_json['orderSuccessUrl'])
        resp.body = json.dumps(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)
        resp.body = json.dumps(result, encoding='utf-8')
        
class Track():
    def on_post(self, req, resp):
        try:
            string1 = req.stream.read()
            req_json = json.loads(string1, 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(int(req_json['sourceId']))
        return store.getUrls(int(req_json['userId']))
    
    def on_get(self, req, resp):
        try:
            userId = req.get_param_as_int("userId")
            storeId = req.get_param_as_int("storeId")
            store = main.getStore(storeId)
            return store.getTrackingUrls(userId)
        except ValueError:
            raise falcon.HTTPError(falcon.HTTP_400,
                'Malformed JSON',
                'Could not decode the request body. The '
                'JSON was incorrect.')