Subversion Repositories SmartDukaan

Rev

Rev 13990 | Rev 14004 | 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")
30
        try:
31
            if string1 is None or string1 == "":
32
                searchMap = json.loads(string1, encoding='utf-8')
33
        except:
34
            raise falcon.HTTPError(falcon.HTTP_400,
35
                'Malformed JSON',
36
                'Could not decode the request body. The '
37
                'JSON was incorrect.')
38
        result = Mongo.getMerchantOrdersByUser(int(userId), page, window, searchMap)
13868 amit.gupta 39
        resp.body = json.dumps(result, encoding='utf-8')
40
 
41
class Track():
13939 amit.gupta 42
    def on_post(self, req, resp, userId):
13868 amit.gupta 43
        try:
44
            string1 = req.stream.read()
45
            req_json = json.loads(string1, encoding='utf-8')
46
        except ValueError:
47
            raise falcon.HTTPError(falcon.HTTP_400,
48
                'Malformed JSON',
49
                'Could not decode the request body. The '
50
                'JSON was incorrect.')
13927 amit.gupta 51
        try:
52
            store = main.getStore(req.get_param_as_int("storeId"))
53
            if req.get_param_as_int("storeId") == 1:
13939 amit.gupta 54
                result = store.trackOrdersForUser(int(userId),req_json['url'],req_json['html'])
13927 amit.gupta 55
                resp.body = json.dumps({'result':result}, encoding='utf-8')
56
            else:
57
                resp.body = json.dumps({'result':'NOT_IMPLEMENTED'}, encoding='utf-8')
58
        except:
59
            resp.body = json.dumps({'result':'PARSE_ERROR'}, encoding='utf-8')
13868 amit.gupta 60
 
13939 amit.gupta 61
    def on_get(self, req, resp, userId):
13868 amit.gupta 62
        try:
63
            storeId = req.get_param_as_int("storeId")
13939 amit.gupta 64
            result = main.getStore(storeId).getTrackingUrls(int(userId))
13887 amit.gupta 65
            resp.body = json.dumps({'result':result}, encoding='utf-8')
13868 amit.gupta 66
        except ValueError:
67
            raise falcon.HTTPError(falcon.HTTP_400,
68
                'Malformed JSON',
69
                'Could not decode the request body. The '
70
                'JSON was incorrect.')
71
 
13927 amit.gupta 72
class Refunds():
13990 amit.gupta 73
    def on_get(self, req, resp, userId):
13927 amit.gupta 74
        try:
75
            page = req.get_param_as_int("page")
76
            window = req.get_param_as_int("window")
13990 amit.gupta 77
            result = Mongo.getRefunds(int(userId),page,window)
13927 amit.gupta 78
            resp.body = json.dumps(result, encoding='utf-8')
79
        except ValueError:
80
            raise falcon.HTTPError(falcon.HTTP_400,
81
                'Malformed JSON',
82
                'Could not decode the request body. The '
83
                'JSON was incorrect.')
84
 
85
class PendingRefunds():
86
    def on_get(self, req, resp,userId):
87
        try:
88
            result = Mongo.getPendingRefunds(int(userId))
89
            resp.body = json.dumps(result, encoding='utf-8')
90
        except ValueError:
91
            raise falcon.HTTPError(falcon.HTTP_400,
92
                'Malformed JSON',
93
                'Could not decode the request body. The '
94
                'JSON was incorrect.')