Subversion Repositories SmartDukaan

Rev

Rev 14003 | Rev 14006 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
13804 amit.gupta 1
'''
2
Created on Feb 12, 2015
3
 
4
@author: amit
5
'''
6
from dtr import main
7
from dtr.storage import Mongo
8
import falcon
9
import json
10
class StoreOrder():
11
    def on_post(self, req, resp):
12
 
13
        try:
14
            string1 = req.stream.read()
15
            req_json = json.loads(string1, encoding='utf-8')
16
        except ValueError:
17
            raise falcon.HTTPError(falcon.HTTP_400,
18
                'Malformed JSON',
19
                'Could not decode the request body. The '
20
                'JSON was incorrect.')
21
 
22
        store = main.getStore(int(req_json['sourceId']))
23
        result = store.parseOrderRawHtml(int(req_json['orderId']), req_json['subTagId'], int(req_json['userId']), req_json['rawHtml'], req_json['orderSuccessUrl'])
24
        resp.body = json.dumps(result, encoding='utf-8')
25
 
26
    def on_get(self, req, resp, userId):
27
        page = req.get_param_as_int("page")
28
        window = req.get_param_as_int("window")
14003 amit.gupta 29
        string1 = req.get_param("searchMap")
14004 amit.gupta 30
        searchMap={}
14003 amit.gupta 31
        try:
32
            if string1 is None or string1 == "":
33
                searchMap = json.loads(string1, encoding='utf-8')
34
        except:
35
            raise falcon.HTTPError(falcon.HTTP_400,
36
                'Malformed JSON',
37
                'Could not decode the request body. The '
38
                'JSON was incorrect.')
39
        result = Mongo.getMerchantOrdersByUser(int(userId), page, window, searchMap)
13868 amit.gupta 40
        resp.body = json.dumps(result, encoding='utf-8')
41
 
42
class Track():
13939 amit.gupta 43
    def on_post(self, req, resp, userId):
13868 amit.gupta 44
        try:
45
            string1 = req.stream.read()
46
            req_json = json.loads(string1, encoding='utf-8')
47
        except ValueError:
48
            raise falcon.HTTPError(falcon.HTTP_400,
49
                'Malformed JSON',
50
                'Could not decode the request body. The '
51
                'JSON was incorrect.')
13927 amit.gupta 52
        try:
53
            store = main.getStore(req.get_param_as_int("storeId"))
54
            if req.get_param_as_int("storeId") == 1:
13939 amit.gupta 55
                result = store.trackOrdersForUser(int(userId),req_json['url'],req_json['html'])
13927 amit.gupta 56
                resp.body = json.dumps({'result':result}, encoding='utf-8')
57
            else:
58
                resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
59
        except:
60
            resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
13868 amit.gupta 61
 
13939 amit.gupta 62
    def on_get(self, req, resp, userId):
13868 amit.gupta 63
        try:
64
            storeId = req.get_param_as_int("storeId")
13939 amit.gupta 65
            result = main.getStore(storeId).getTrackingUrls(int(userId))
13887 amit.gupta 66
            resp.body = json.dumps({'result':result}, encoding='utf-8')
13868 amit.gupta 67
        except ValueError:
68
            raise falcon.HTTPError(falcon.HTTP_400,
69
                'Malformed JSON',
70
                'Could not decode the request body. The '
71
                'JSON was incorrect.')
72
 
13927 amit.gupta 73
class Refunds():
13990 amit.gupta 74
    def on_get(self, req, resp, userId):
13927 amit.gupta 75
        try:
76
            page = req.get_param_as_int("page")
77
            window = req.get_param_as_int("window")
13990 amit.gupta 78
            result = Mongo.getRefunds(int(userId),page,window)
13927 amit.gupta 79
            resp.body = json.dumps(result, encoding='utf-8')
80
        except ValueError:
81
            raise falcon.HTTPError(falcon.HTTP_400,
82
                'Malformed JSON',
83
                'Could not decode the request body. The '
84
                'JSON was incorrect.')
85
 
86
class PendingRefunds():
87
    def on_get(self, req, resp,userId):
88
        try:
89
            result = Mongo.getPendingRefunds(int(userId))
90
            resp.body = json.dumps(result, encoding='utf-8')
91
        except ValueError:
92
            raise falcon.HTTPError(falcon.HTTP_400,
93
                'Malformed JSON',
94
                'Could not decode the request body. The '
95
                'JSON was incorrect.')