Subversion Repositories SmartDukaan

Rev

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

Rev Author Line No. Line
130 ashish 1
'''
2
Created on 28-Apr-2010
3
 
4
@author: ashish
5
'''
6
from shop2020.utils.Utils import log_entry
557 chandransh 7
from shop2020.model.v1.user.impl.UserDataAccessors import create_user, update_user, get_user_by_id, update_password,\
8
    set_user_as_logged_out, set_user_as_logged_in, remove_address_for_user,\
9
    add_address_for_user, delete_user, authenticate_user, user_exists, get_user_state, initialize, set_default_address,\
581 rajveer 10
    create_anonymous_user, forgot_password
557 chandransh 11
from shop2020.model.v1.user.impl.CartDataAccessors import create_cart, get_cart,\
12
    get_cart_by_id, get_cart_by_user_id_and_status, get_carts_by_status,\
13
    get_carts_between, change_cart_status, add_item_to_cart,\
14
    change_item_quantity, change_item_status, add_address_to_cart, commit_cart,\
15
    validate_cart, merge_cart, delete_item_from_cart
16
from shop2020.model.v1.user.impl.Converters import to_t_user, to_t_user_state, to_t_cart
576 chandransh 17
 
557 chandransh 18
from shop2020.thriftpy.model.v1.user.ttypes import ShoppingCartException
130 ashish 19
 
557 chandransh 20
from shop2020.model.v1.user.impl.WidgetDataAccessor import add_widget,\
21
    add_items_to_widget, update_my_research, update_widget, get_widget_by_type,\
22
    get_my_research, get_ratings, update_ratings, get_browse_history,\
23
    update_browse_history, delete_item_from_my_research, delete_item_from_widget
24
from shop2020.model.v1.user.impl.WidgetConverters import to_t_widget, to_t_ratings
25
 
130 ashish 26
class UserContextServiceHandler:
27
 
404 rajveer 28
 
29
    def __init__(self):
30
        initialize()
557 chandransh 31
 
130 ashish 32
    """
557 chandransh 33
    service
130 ashish 34
    """
557 chandransh 35
    def createAnonymousUser(self, jsessionId):
36
        cart = create_cart(-1)
37
        return to_t_user(create_anonymous_user(jsessionId, cart))
38
 
39
    def getUserById(self, userId):
130 ashish 40
        """
41
        Parameters:
557 chandransh 42
        - userId
130 ashish 43
        """
557 chandransh 44
        return to_t_user(get_user_by_id(userId))
130 ashish 45
 
557 chandransh 46
    def createUser(self, user):
130 ashish 47
        """
48
        Parameters:
557 chandransh 49
        - user
130 ashish 50
        """
557 chandransh 51
        cart = create_cart(-1)
52
        return to_t_user(create_user(user, cart))
130 ashish 53
 
557 chandransh 54
    def updateUser(self, user):
130 ashish 55
        """
56
        Parameters:
557 chandransh 57
        - user
130 ashish 58
        """
557 chandransh 59
        return to_t_user(update_user(user))
130 ashish 60
 
557 chandransh 61
    def deleteUser(self, userId):
130 ashish 62
        """
63
        Parameters:
557 chandransh 64
        - userId
130 ashish 65
        """
557 chandransh 66
        return delete_user(userId)
67
 
68
    def getUserState(self, userId):
69
        """
70
        Parameters:
71
        - userId
72
        """
130 ashish 73
        log_entry(self, "get State")
557 chandransh 74
        return to_t_user_state(get_user_state(userId))
130 ashish 75
 
557 chandransh 76
    def authenticateUser(self, email, password):
130 ashish 77
        """
78
        Parameters:
557 chandransh 79
        - email
80
        - password
81
        """
82
        log_entry(self, "authenticate user")
83
        return to_t_user(authenticate_user(email, password))
84
 
85
    def userExists(self, email):
86
        """
87
        Parameters:
88
        - email
89
        """
90
        log_entry(self, "user exists")
91
        return user_exists(email)
92
 
567 rajveer 93
    def addAddressForUser(self, userId, address, setDefault):
557 chandransh 94
        """
95
        Parameters:
96
        - userId
97
        - address
98
        - setDefault
99
        """
100
        log_entry(self, "add address for user")
567 rajveer 101
        return add_address_for_user(address, userId, setDefault)
557 chandransh 102
 
103
    def removeAddressForUser(self, userid, addressId):
104
        """
105
        Parameters:
106
        - userid
107
        - addressId
108
        """
109
        log_entry(self, "removing address")
110
        return remove_address_for_user(userid, addressId)
111
 
112
    def setUserAsLoggedIn(self, userId, timestamp):
113
        """
114
        Parameters:
115
        - userId
116
        - timestamp
117
        """
118
        log_entry(self, "set_user_as_logged_in")
119
        return set_user_as_logged_in(userId, timestamp)
120
 
121
    def setUserAsLoggedOut(self, userId, timestamp):
122
        """
123
        Parameters:
124
        - userId
125
        - timestamp
126
        """
127
        log_entry(self, "set user as logged out")
128
        return set_user_as_logged_out(userId, timestamp)
129
 
130
    def setDefaultAddress(self, userId, addressId):
131
        """
132
        Parameters:
133
        - userId
134
        - addressId
135
        """
136
        return set_default_address(userId, addressId)
137
 
138
    def updatePassword(self, userId, password):
139
        """
140
        Parameters:
141
        - userId
142
        - password
143
        """
144
        log_entry(self, "updating password")
145
        return update_password(userId, password)
146
 
581 rajveer 147
    def forgotPassword(self, email):
148
        """
149
        Parameters:
150
         - email
151
        """
152
        log_entry(self, "forgot password")
153
        return forgot_password(email)
557 chandransh 154
 
155
    def createCart(self, userId):
156
        """
157
        Parameters:
158
        - userId
159
        """
160
        return create_cart(userId).id
161
 
162
    def getCurrentCart(self, userId):
163
        """
164
        Parameters:
130 ashish 165
         - userId
166
        """
557 chandransh 167
        cart = get_cart(userId)
168
        if cart:
169
            return to_t_cart(cart)
170
        else:
171
            raise ShoppingCartException(101, "not cart attached to this user")
172
 
173
    def getCart(self, cartId):
174
        """
175
        Parameters:
176
         - cartId
177
        """
178
        cart = get_cart_by_id(cartId)
179
        if cart:
180
            return to_t_cart(cart)
181
        else:
182
            raise ShoppingCartException(101, "not cart attached to this id")
130 ashish 183
 
557 chandransh 184
    def getCartsForUser(self, userId, status):
130 ashish 185
        """
186
        Parameters:
187
         - userId
557 chandransh 188
         - status
130 ashish 189
        """
557 chandransh 190
        if not userId:
191
            raise ShoppingCartException(101, "user_id is not provided")
192
 
193
        carts = get_cart_by_user_id_and_status(userId, status)
194
        t_carts = []
195
        if carts:
196
            for cart in carts:
197
                t_carts.append(to_t_cart(cart))
198
        return t_carts
130 ashish 199
 
557 chandransh 200
    def getCartsByStatus(self, status):
130 ashish 201
        """
202
        Parameters:
557 chandransh 203
         - status
130 ashish 204
        """
557 chandransh 205
        carts = get_carts_by_status(status)
206
        t_carts = []
207
        if carts:
208
            for cart in carts:
209
                t_carts.append(to_t_cart(cart))
210
        return t_carts
130 ashish 211
 
557 chandransh 212
    def getCartsByTime(self, from_time, to_time, status):
130 ashish 213
        """
214
        Parameters:
557 chandransh 215
         - from_time
216
         - to_time
217
         - status
130 ashish 218
        """
557 chandransh 219
        carts = get_carts_between(from_time, to_time, status)
220
        t_carts = []
221
        if carts:
222
            for cart in carts:
223
                t_carts.append(to_t_cart(cart))
224
        return t_carts
130 ashish 225
 
557 chandransh 226
    def changeCartStatus(self, cartId, status):
130 ashish 227
        """
228
        Parameters:
557 chandransh 229
         - cartId
230
         - status
130 ashish 231
        """
557 chandransh 232
        change_cart_status(cartId, status)
130 ashish 233
 
557 chandransh 234
    def addItemToCart(self, cartId, itemId, quantity):
130 ashish 235
        """
236
        Parameters:
557 chandransh 237
         - cartId
238
         - itemId
239
         - quantity
130 ashish 240
        """
557 chandransh 241
        return add_item_to_cart(cartId, itemId, quantity)
130 ashish 242
 
557 chandransh 243
    def deleteItemFromCart(self, cartId, itemId):
130 ashish 244
        """
245
        Parameters:
557 chandransh 246
         - cartId
247
         - itemId
130 ashish 248
        """
557 chandransh 249
        delete_item_from_cart(cartId, itemId)
250
 
251
    def changeQuantity(self, cartId, itemId, quantity):
252
        """
253
        Parameters:
254
         - cartId
255
         - itemId
256
         - quantity
257
        """
258
        return change_item_quantity(cartId, itemId, quantity)
130 ashish 259
 
557 chandransh 260
    def changeItemStatus(self, cartId, itemId, status):
130 ashish 261
        """
262
        Parameters:
557 chandransh 263
         - cartId
264
         - itemId
265
        """
266
        return change_item_status(cartId, itemId, status)
267
 
268
    def addAddressToCart(self, cartId, addressId):
269
        """
270
        Parameters:
271
         - cartId
130 ashish 272
         - addressId
273
        """
557 chandransh 274
        return add_address_to_cart(cartId, addressId)
130 ashish 275
 
557 chandransh 276
    def commitCart(self, cartId):
130 ashish 277
        """
278
        Parameters:
557 chandransh 279
         - cartId
130 ashish 280
        """
576 chandransh 281
        return commit_cart(cartId)
130 ashish 282
 
557 chandransh 283
    def validateCart(self, cartId):
130 ashish 284
        """
285
        Parameters:
557 chandransh 286
         - cartId
130 ashish 287
        """
576 chandransh 288
        return validate_cart(cartId)
130 ashish 289
 
557 chandransh 290
    def mergeCart(self, fromCartId, toCartId):
513 rajveer 291
        """
292
        Parameters:
557 chandransh 293
         - fromCartId
294
         - toCartId
513 rajveer 295
        """
557 chandransh 296
        merge_cart(fromCartId, toCartId)
513 rajveer 297
 
557 chandransh 298
    def addWidget(self, widget):
130 ashish 299
        """
300
        Parameters:
557 chandransh 301
         - widget
130 ashish 302
        """
557 chandransh 303
        add_widget(widget)
130 ashish 304
 
557 chandransh 305
    def addItemToWidget(self, widget_id, items):
130 ashish 306
        """
307
        Parameters:
557 chandransh 308
         - widget_id
309
         - items
130 ashish 310
        """
557 chandransh 311
        add_items_to_widget(widget_id, items)
130 ashish 312
 
557 chandransh 313
    def updateMyResearch(self, user_id, item_id):
130 ashish 314
        """
315
        Parameters:
557 chandransh 316
         - user_id
317
         - item_id
130 ashish 318
        """
557 chandransh 319
        return update_my_research(user_id, item_id)
130 ashish 320
 
557 chandransh 321
    def updateWidget(self, widgetId, enable):
130 ashish 322
        """
323
        Parameters:
557 chandransh 324
         - widgetId
325
         - enable
130 ashish 326
        """
557 chandransh 327
        update_widget(widgetId, enable)
130 ashish 328
 
557 chandransh 329
    def updateWidgetItem(self, widgetId, enable):
130 ashish 330
        """
331
        Parameters:
557 chandransh 332
         - widgetId
333
         - enable
130 ashish 334
        """
557 chandransh 335
        update_widget(widgetId, enable)
336
 
337
    def deleteItemFromWidget(self, widget_id, item_id):
338
        """
339
        Parameters:
340
         - widget_id
341
         - item_id
342
        """
343
        return delete_item_from_widget(widget_id, item_id)
130 ashish 344
 
557 chandransh 345
    def deleteItemFromMyResearch(self, user_id, item_id):
130 ashish 346
        """
347
        Parameters:
557 chandransh 348
         - user_id
349
         - item_id
130 ashish 350
        """
557 chandransh 351
        return delete_item_from_my_research(user_id, item_id)
130 ashish 352
 
557 chandransh 353
    def getWidget(self, type, userId, onlyEnabled):
130 ashish 354
        """
355
        Parameters:
557 chandransh 356
         - type
357
         - userId
358
         - onlyEnabled
130 ashish 359
        """
557 chandransh 360
        widget = get_widget_by_type(type, userId, onlyEnabled)
361
        return to_t_widget(widget)
130 ashish 362
 
557 chandransh 363
    def getMyResearch(self, user_id):
130 ashish 364
        """
365
        Parameters:
557 chandransh 366
         - user_id
130 ashish 367
        """
557 chandransh 368
        return to_t_widget(get_my_research(user_id))
130 ashish 369
 
557 chandransh 370
    def updateRatings(self, item_id, type, rating, user_id):
130 ashish 371
        """
372
        Parameters:
557 chandransh 373
        - item_id
374
        - type
375
        - rating
376
        - user_id
130 ashish 377
        """
557 chandransh 378
        update_ratings(user_id, item_id, rating, type)
379
 
380
 
381
    def getRatings(self, item_id, user_id):
382
        """
383
        Parameters:
384
        - item_id
385
        - user_id
386
        """
387
        all_ratings, user_ratings = get_ratings(user_id, item_id)
388
        return to_t_ratings(user_ratings, all_ratings, item_id, user_id)
389
 
390
    def updateBrowseHistory(self, user_id, item_id, is_session_id):
391
        """
392
        Parameters: 
393
        - user_id
394
        - item_id
395
        - isSessionId
396
        """
397
        update_browse_history(user_id, item_id, is_session_id)
398
 
399
    def getBrowseHistory(self, user_id, is_session_id):
400
        """
401
        Parameters:
402
         - user_id
403
         - is_session_id
404
        """
405
        return to_t_widget(get_browse_history(user_id, is_session_id))