Пример #1
0
 def on_get(self, req, res, account, friend):
     limit = req.context['pagination']['limit']
     page = req.context['pagination']['offset']
     if (page == 0):
         page += 1
     next = URL_PAGINATION + req.path + '?limit=' + \
         '10' + '&page=' + \
         str(page+1)
     pagination = {'page': page, 'count': limit, 'next': next}
     try:
         array = []
         account_one = findCollection(SCHEMA, starting_account_id=account)
         account_two = findCollection(SCHEMA, starting_account_id=friend)
         for x in account_one:
             for y in account_two:
                 if (x['ending_account_id'] == y['ending_account_id']):
                     array.append(y)
         start = (page * 10) - 10
         end = start + limit
         data = array[start:end]
         self.on_success(res, to_camel_case(data), pagination)
     except Exception as e:
         print(e)
         self.on_error(
             res,
             error={
                 'code': 500,
                 'message':
                 'El servidor encontró una condición inesperada que le impidió cumplir con la solicitud.',
                 'status': falcon.HTTP_500
             })
Пример #2
0
 def on_post(self, req, res):
     req = to_snake_case(req.context['json'])
     req['permissions'] = []
     if (req['password'] != req['password_confirmation']):
         raise PasswordNotMatch(
             description='Password and passwordConfirmation don\'t match!')
     del req['password_confirmation']
     username_length = 0
     try:
         user_exists = findOne(SCHEMA, username=req['username'])
         username_length = len(user_exists['username'])
         if (username_length > 0):
             raise UsernameNotAvailable(
                 description='Username is not available')
     except Exception as e:
         if (username_length > 0):
             raise UsernameNotAvailable(
                 description='Username is not available')
         try:
             req['password'] = b_encode(req['password'])
             user = create(SCHEMA, req)
             del user['password']
             token = jwt_encode(user)
             data = {'apikey': token, 'user': user}
             self.on_success(res, to_camel_case(data))
         except Exception as e:
             self.on_error(
                 res,
                 error={
                     'code': 500,
                     'message':
                     'El servidor encontró una condición inesperada que le impidió cumplir con la solicitud.',
                     'status': falcon.HTTP_500
                 })
Пример #3
0
 def on_post(self, req, res):
     req = to_snake_case(req.context['json'])
     try:
         username = req['user']
         try:
             user = findOne(SCHEMA_USERS, username=username)
             try:
                 req['id'] = str(uuid.uuid4())
                 req['friend_collection_url'] = '/account/' + \
                     req['id'] + '/friends'
                 data = create(SCHEMA, req)
                 data['friend_collection_url'] = os.getenv(
                     'URL_WEB') + data['friend_collection_url']
                 self.on_success(res, to_camel_case(data))
             except Exception as e:
                 self.on_error(res,
                               error={
                                   'code': 404,
                                   'message':
                                   'No se encontro ningun registro!',
                                   'status': falcon.HTTP_400
                               })
         except Exception as e:
             self.on_error(res,
                           error={
                               'code': 404,
                               'message': 'No se encontro ningun registro!',
                               'status': falcon.HTTP_400
                           })
     except Exception as e:
         try:
             req['id'] = str(uuid.uuid4())
             req['user'] = ''
             index = req['id']
             req['friend_collection_url'] = '/account/' + index + '/friends'
             data = create(SCHEMA, req)
             data['friend_collection_url'] = os.getenv(
                 'URL_WEB') + data['friend_collection_url']
             self.on_success(res, to_camel_case(data))
         except Exception as e:
             self.on_error(res,
                           error={
                               'code': 404,
                               'message': 'No se encontro ningun registro!',
                               'status': falcon.HTTP_400
                           })
Пример #4
0
 def on_get(self, req, res, id):
     try:
         data = findOne(SCHEMA, id=id)
         self.on_success(res, to_camel_case(data))
     except Exception as e:
         self.on_error(res,
                       error={
                           'code': 404,
                           'message': 'No se encontro ningun registro!',
                           'status': falcon.HTTP_400
                       })
Пример #5
0
 def on_put(self, req, res, id):
     req = to_snake_case(req.context['json'])
     try:
         username = req['user']
         try:
             user = findOne(SCHEMA_USERS, username=username)
             try:
                 data = update(SCHEMA, req, id=id)
                 data['friend_collection_url'] = os.getenv(
                     'URL_WEB') + data['friend_collection_url']
                 self.on_success(res, to_camel_case(data))
             except Exception as e:
                 self.on_error(res,
                               error={
                                   'code': 404,
                                   'message':
                                   'No se encontro ningun registro!',
                                   'status': falcon.HTTP_400
                               })
         except Exception as e:
             self.on_error(res,
                           error={
                               'code': 404,
                               'message': 'No se encontro ningun registro!',
                               'status': falcon.HTTP_400
                           })
     except Exception as e:
         try:
             req['user'] = ''
             data = update(SCHEMA, req, id=id)
             data['friend_collection_url'] = os.getenv(
                 'URL_WEB') + data['friend_collection_url']
             self.on_success(res, to_camel_case(data))
         except Exception as e:
             self.on_error(res,
                           error={
                               'code': 404,
                               'message': 'No se encontro ningun registro!',
                               'status': falcon.HTTP_400
                           })
Пример #6
0
 def on_get(self, req, res, id):
     try:
         data = findOne(SCHEMA, id=id)
         data['friend_collection_url'] = os.getenv(
             'URL_WEB') + data['friend_collection_url']
         self.on_success(res, to_camel_case(data))
     except Exception as e:
         self.on_error(res,
                       error={
                           'code': 404,
                           'message': 'No se encontro ningun registro!',
                           'status': falcon.HTTP_400
                       })
Пример #7
0
 def on_get(self, req, res):
     try:
         token = req.headers.get('AUTHORIZATION', None)
         encode = token.split(' ')
         userpayload = jwt_decode(token)
         data = {'apikey': encode[1], 'user': userpayload}
         self.on_success(res, to_camel_case(data))
     except Exception as e:
         self.on_error(
             res,
             error={
                 'code': 500,
                 'message':
                 'El servidor encontró una condición inesperada que le impidió cumplir con la solicitud.',
                 'status': falcon.HTTP_500
             })
Пример #8
0
 def on_get(self, req, res):
     limit = req.context['pagination']['limit']
     page = req.context['pagination']['offset']
     if (page == 0):
         page += 1
     next = URL_PAGINATION + req.path + '?limit=' + \
         '10' + '&page=' + \
         str(page+1)
     pagination = {'page': page, 'count': limit, 'next': next}
     try:
         data = find(SCHEMA, page, limit)
         self.on_success(res, to_camel_case(data), pagination)
     except Exception as e:
         print(e)
         self.on_error(res,
                       error={
                           'code': 404,
                           'message': 'No se encontro ningun registro!',
                           'status': falcon.HTTP_400
                       })
Пример #9
0
 def on_post(self, req, res):
     try:
         req = to_snake_case(req.context['json'])
         try:
             one = findOne(SCHEMA, **req)
             if (one):
                 self.on_error(res,
                               error={
                                   'code': 404,
                                   'message': 'Ya existe el registro!',
                                   'status': falcon.HTTP_400
                               })
         except Exception as e:
             try:
                 one_one = findOne(SCHEMA_ACCOUNT,
                                   id=req['starting_account_id'])
                 one_two = findOne(SCHEMA_ACCOUNT,
                                   id=req['starting_account_id'])
                 req['id'] = str(uuid.uuid4())
                 data = create(SCHEMA, req)
                 self.on_success(res, to_camel_case(data))
             except Exception as e:
                 self.on_error(
                     res,
                     error={
                         'code': 404,
                         'message':
                         'No existe alguno de los registros proveidos!',
                         'status': falcon.HTTP_400
                     })
     except Exception as e:
         self.on_error(
             res,
             error={
                 'code': 500,
                 'message':
                 'El servidor encontró una condición inesperada que le impidió cumplir con la solicitud.',
                 'status': falcon.HTTP_500
             })
Пример #10
0
 def on_post(self, req, res):
     req = to_snake_case(req.context['json'])
     try:
         user = findOne(SCHEMA, username=req['username'])
     except Exception as e:
         raise UserNotExistsError(
             description='User or password is not available')
     if (b_compare(req['password'], user['password']) is False):
         raise UserNotExistsError(
             description='User or password is not available')
     try:
         del user['password']
         token = jwt_encode(user)
         data = {'apikey': token, 'user': user}
         self.on_success(res, to_camel_case(data))
     except Exception as e:
         self.on_error(
             res,
             error={
                 'code': 500,
                 'message':
                 'El servidor encontró una condición inesperada que le impidió cumplir con la solicitud.',
                 'status': falcon.HTTP_500
             })
Пример #11
0
 def on_get(self, req, res, account):
     limit = req.context['pagination']['limit']
     page = req.context['pagination']['offset']
     if (page == 0):
         page += 1
     next = URL_PAGINATION + req.path + '?limit=' + \
         '10' + '&page=' + \
         str(page+1)
     pagination = {'page': page, 'count': limit, 'next': next}
     try:
         data = findCollection(SCHEMA,
                               page,
                               limit,
                               starting_account_id=account)
         self.on_success(res, to_camel_case(data), pagination)
     except Exception as e:
         self.on_error(
             res,
             error={
                 'code': 500,
                 'message':
                 'El servidor encontró una condición inesperada que le impidió cumplir con la solicitud.',
                 'status': falcon.HTTP_500
             })