Subversion Repositories SmartDukaan

Rev

Rev 594 | Rev 690 | 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,\
594 rajveer 10
    create_anonymous_user, forgot_password, get_all_addresses_for_user, get_default_addredd_id
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,\
643 chandransh 14
    change_item_status, add_address_to_cart, commit_cart,\
557 chandransh 15
    validate_cart, merge_cart, delete_item_from_cart
594 rajveer 16
from shop2020.model.v1.user.impl.Converters import to_t_user, to_t_user_state, to_t_cart, to_t_address
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)
594 rajveer 137
    def updatePassword(self, userid, oldPassword, newPassword):
557 chandransh 138
        """
139
        Parameters:
594 rajveer 140
         - userid
141
         - oldPassword
142
         - newPassword
557 chandransh 143
        """
144
        log_entry(self, "updating password")
594 rajveer 145
        return update_password(userid, oldPassword, newPassword)
557 chandransh 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
 
594 rajveer 155
    def getAllAddressesForUser(self, userId):
156
        """
157
        Parameters:
158
         - userId
159
        """
160
        addresses = get_all_addresses_for_user(userId)
161
 
162
        t_addresses = list()
163
        for address in addresses:
164
            t_addresses.append(to_t_address(address))
165
        return t_addresses
166
 
167
    def getDefaultAddressId(self, userId):
168
        """
169
        Parameters:
170
         - userId
171
        """
172
        return get_default_addredd_id(userId)
173
 
557 chandransh 174
    def createCart(self, userId):
175
        """
176
        Parameters:
177
        - userId
178
        """
179
        return create_cart(userId).id
180
 
181
    def getCurrentCart(self, userId):
182
        """
183
        Parameters:
130 ashish 184
         - userId
185
        """
557 chandransh 186
        cart = get_cart(userId)
187
        if cart:
188
            return to_t_cart(cart)
189
        else:
190
            raise ShoppingCartException(101, "not cart attached to this user")
191
 
192
    def getCart(self, cartId):
193
        """
194
        Parameters:
195
         - cartId
196
        """
197
        cart = get_cart_by_id(cartId)
198
        if cart:
199
            return to_t_cart(cart)
200
        else:
201
            raise ShoppingCartException(101, "not cart attached to this id")
130 ashish 202
 
557 chandransh 203
    def getCartsForUser(self, userId, status):
130 ashish 204
        """
205
        Parameters:
206
         - userId
557 chandransh 207
         - status
130 ashish 208
        """
557 chandransh 209
        if not userId:
210
            raise ShoppingCartException(101, "user_id is not provided")
211
 
212
        carts = get_cart_by_user_id_and_status(userId, status)
213
        t_carts = []
214
        if carts:
215
            for cart in carts:
216
                t_carts.append(to_t_cart(cart))
217
        return t_carts
130 ashish 218
 
557 chandransh 219
    def getCartsByStatus(self, status):
130 ashish 220
        """
221
        Parameters:
557 chandransh 222
         - status
130 ashish 223
        """
557 chandransh 224
        carts = get_carts_by_status(status)
225
        t_carts = []
226
        if carts:
227
            for cart in carts:
228
                t_carts.append(to_t_cart(cart))
229
        return t_carts
130 ashish 230
 
557 chandransh 231
    def getCartsByTime(self, from_time, to_time, status):
130 ashish 232
        """
233
        Parameters:
557 chandransh 234
         - from_time
235
         - to_time
236
         - status
130 ashish 237
        """
557 chandransh 238
        carts = get_carts_between(from_time, to_time, status)
239
        t_carts = []
240
        if carts:
241
            for cart in carts:
242
                t_carts.append(to_t_cart(cart))
243
        return t_carts
130 ashish 244
 
557 chandransh 245
    def changeCartStatus(self, cartId, status):
130 ashish 246
        """
247
        Parameters:
557 chandransh 248
         - cartId
249
         - status
130 ashish 250
        """
557 chandransh 251
        change_cart_status(cartId, status)
130 ashish 252
 
557 chandransh 253
    def addItemToCart(self, cartId, itemId, quantity):
130 ashish 254
        """
255
        Parameters:
557 chandransh 256
         - cartId
257
         - itemId
258
         - quantity
130 ashish 259
        """
643 chandransh 260
        add_item_to_cart(cartId, itemId, quantity)
130 ashish 261
 
557 chandransh 262
    def deleteItemFromCart(self, cartId, itemId):
130 ashish 263
        """
264
        Parameters:
557 chandransh 265
         - cartId
266
         - itemId
130 ashish 267
        """
557 chandransh 268
        delete_item_from_cart(cartId, itemId)
269
 
270
    def changeQuantity(self, cartId, itemId, quantity):
271
        """
272
        Parameters:
273
         - cartId
274
         - itemId
275
         - quantity
276
        """
643 chandransh 277
        add_item_to_cart(cartId, itemId, quantity)
130 ashish 278
 
557 chandransh 279
    def changeItemStatus(self, cartId, itemId, status):
130 ashish 280
        """
281
        Parameters:
557 chandransh 282
         - cartId
283
         - itemId
284
        """
285
        return change_item_status(cartId, itemId, status)
286
 
287
    def addAddressToCart(self, cartId, addressId):
288
        """
289
        Parameters:
290
         - cartId
130 ashish 291
         - addressId
292
        """
557 chandransh 293
        return add_address_to_cart(cartId, addressId)
130 ashish 294
 
557 chandransh 295
    def commitCart(self, cartId):
130 ashish 296
        """
297
        Parameters:
557 chandransh 298
         - cartId
130 ashish 299
        """
576 chandransh 300
        return commit_cart(cartId)
130 ashish 301
 
557 chandransh 302
    def validateCart(self, cartId):
130 ashish 303
        """
304
        Parameters:
557 chandransh 305
         - cartId
130 ashish 306
        """
576 chandransh 307
        return validate_cart(cartId)
130 ashish 308
 
557 chandransh 309
    def mergeCart(self, fromCartId, toCartId):
513 rajveer 310
        """
311
        Parameters:
557 chandransh 312
         - fromCartId
313
         - toCartId
513 rajveer 314
        """
557 chandransh 315
        merge_cart(fromCartId, toCartId)
513 rajveer 316
 
557 chandransh 317
    def addWidget(self, widget):
130 ashish 318
        """
319
        Parameters:
557 chandransh 320
         - widget
130 ashish 321
        """
557 chandransh 322
        add_widget(widget)
130 ashish 323
 
557 chandransh 324
    def addItemToWidget(self, widget_id, items):
130 ashish 325
        """
326
        Parameters:
557 chandransh 327
         - widget_id
328
         - items
130 ashish 329
        """
557 chandransh 330
        add_items_to_widget(widget_id, items)
130 ashish 331
 
557 chandransh 332
    def updateMyResearch(self, user_id, item_id):
130 ashish 333
        """
334
        Parameters:
557 chandransh 335
         - user_id
336
         - item_id
130 ashish 337
        """
557 chandransh 338
        return update_my_research(user_id, item_id)
130 ashish 339
 
557 chandransh 340
    def updateWidget(self, widgetId, enable):
130 ashish 341
        """
342
        Parameters:
557 chandransh 343
         - widgetId
344
         - enable
130 ashish 345
        """
557 chandransh 346
        update_widget(widgetId, enable)
130 ashish 347
 
557 chandransh 348
    def updateWidgetItem(self, widgetId, enable):
130 ashish 349
        """
350
        Parameters:
557 chandransh 351
         - widgetId
352
         - enable
130 ashish 353
        """
557 chandransh 354
        update_widget(widgetId, enable)
355
 
356
    def deleteItemFromWidget(self, widget_id, item_id):
357
        """
358
        Parameters:
359
         - widget_id
360
         - item_id
361
        """
362
        return delete_item_from_widget(widget_id, item_id)
130 ashish 363
 
557 chandransh 364
    def deleteItemFromMyResearch(self, user_id, item_id):
130 ashish 365
        """
366
        Parameters:
557 chandransh 367
         - user_id
368
         - item_id
130 ashish 369
        """
557 chandransh 370
        return delete_item_from_my_research(user_id, item_id)
130 ashish 371
 
557 chandransh 372
    def getWidget(self, type, userId, onlyEnabled):
130 ashish 373
        """
374
        Parameters:
557 chandransh 375
         - type
376
         - userId
377
         - onlyEnabled
130 ashish 378
        """
557 chandransh 379
        widget = get_widget_by_type(type, userId, onlyEnabled)
380
        return to_t_widget(widget)
130 ashish 381
 
557 chandransh 382
    def getMyResearch(self, user_id):
130 ashish 383
        """
384
        Parameters:
557 chandransh 385
         - user_id
130 ashish 386
        """
557 chandransh 387
        return to_t_widget(get_my_research(user_id))
130 ashish 388
 
557 chandransh 389
    def updateRatings(self, item_id, type, rating, user_id):
130 ashish 390
        """
391
        Parameters:
557 chandransh 392
        - item_id
393
        - type
394
        - rating
395
        - user_id
130 ashish 396
        """
557 chandransh 397
        update_ratings(user_id, item_id, rating, type)
398
 
399
 
400
    def getRatings(self, item_id, user_id):
401
        """
402
        Parameters:
403
        - item_id
404
        - user_id
405
        """
406
        all_ratings, user_ratings = get_ratings(user_id, item_id)
407
        return to_t_ratings(user_ratings, all_ratings, item_id, user_id)
408
 
409
    def updateBrowseHistory(self, user_id, item_id, is_session_id):
410
        """
411
        Parameters: 
412
        - user_id
413
        - item_id
414
        - isSessionId
415
        """
416
        update_browse_history(user_id, item_id, is_session_id)
417
 
418
    def getBrowseHistory(self, user_id, is_session_id):
419
        """
420
        Parameters:
421
         - user_id
422
         - is_session_id
423
        """
424
        return to_t_widget(get_browse_history(user_id, is_session_id))