def create(self, req, body=None): """ Creating new user. body should contains the following params: - mobile the cell phone number of the user - password the password of the user - code the sms-code has send to user """ try: mobile = body.pop('mobile') password = body.pop('password') # code = body.pop('code') except KeyError: return webob.exc.HTTPBadRequest() # if check_exists(mobile): # return # # if not check_code(code): # return password = self.encrypt_password(password) created = round(time.time() * 1000) # __id__ = uuid.uuid4().hex user = {'mobile': mobile, 'password': password, 'created': created} # FIXME(nmg): should catch exception if any self.db.add_user(user) return Response(201)
def update(self, req, id, status): """Updated order status""" try: token = req.headers['X-AUTH-TOKEN'] except KeyError: return webob.exc.HTTPUnauthorized() try: jwt.decode(token) except jwt.InvalidTokenError: return webob.exc.HTTPUnauthorized() # FIXME(nmg): should catch exception if any self.db.update_order(id, status) return Response(201)
def update(self, req, id, body): """Updated container information""" try: token = req.headers['X-AUTH-TOKEN'] except KeyError: return webob.exc.HTTPUnauthorized() try: jwt.decode(token) except jwt.InvalidTokenError: return webob.exc.HTTPUnauthorized() # FIXME(nmg): should catch exception if any self.db.update_address(id, body) return Response(200)
def delete(self, req, id): """ delete item according to item id `id` """ try: token = req.headers['X-AUTH-TOKEN'] except KeyError: return webob.exc.HTTPUnauthorized() try: jwt.decode(token) except jwt.InvalidTokenError: return webob.exc.HTTPUnauthorized() # FIXME(nmg): should catch exception if any self.db.delete_address(id) return Response(201)
def create(self, req, body=None): """ For creating item, body should not be None and should contains the following params: - name the name of the user - mobile the mobile of the user - address the address of the user """ try: token = req.headers['X-AUTH-TOKEN'] except KeyError: return webob.exc.HTTPUnauthorized() try: payload = jwt.decode(token) except jwt.InvalidTokenError: return webob.exc.HTTPUnauthorized() uid = payload['uid'] name = body.pop('name') mobile = body.pop('mobile') address = body.pop('address') created = round(time.time() * 1000) address = { 'uid': uid, 'name': name, 'mobile': mobile, 'address': address, 'created': created } # FIXME(nmg): should catch exception if any self.db.add_address(address) return Response(201)
def create(self, req, body=None): """ For creating item, body should not be None and should contains the following params: - address the address of the order name:mobile:address - items the items list [{'id': x, 'count': y}, ...] - price the total price of the order float - weight the total weight of the order float """ try: token = req.headers['X-AUTH-TOKEN'] except KeyError: return webob.exc.HTTPUnauthorized() try: payload = jwt.decode(token) except jwt.InvalidTokenError: return webob.exc.HTTPUnauthorized() uid = payload['uid'] try: address = body.pop('address') items = body.pop('items') price = body.pop('price') weight = body.pop('weight') except KeyError as exc: logger.error(exc) return webob.exc.HTTPBadRequest() # __id__ = uuid.uuid4().hex number = utils.generate_order_number() # payment = 0 # delivery = 0 status = 0 uid = uid created = round(time.time() * 1000) order = { # 'id': __id__, 'number': number, 'uid': uid, 'price': price, 'weight': weight, # 'payment': payment, # 'delivery': delivery, 'status': status, 'address': address, 'freight': 0, 'discount': 0, 'created': created } # FIXME(nmg): should catch exception if any self.db.add_order(order) """ Inset item in table `order_item`. For doing this you should get the following value for each item: - id - number - iid - name - img - price - size - count - created """ item_list = [] for member in items: iid = member['id'] # FIXME(nmg): should catch exception if any __item__ = self.db.get_item(iid) try: name = __item__['name'] img = __item__['img'] price = __item__['price'] size = __item__['size'] except KeyError as exc: logger.error(exc) return webob.exc.HTTPBadRequest() count = member['count'] created = created __id__ = uuid.uuid4().hex item = { 'id': __id__, 'iid': iid, 'number': number, 'name': name, 'img': img, 'price': price, 'size': size, 'count': count, 'created': created } item_list.append(item) # FIXME(nmg): should catch exception if any self.db.add_order_items(item_list) return Response(201)