Exemplo n.º 1
0
 def get(self, username):
     try:
         curr_username = TOKEN_AUTH.current_user()
         return UserService.is_following(curr_username, username)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
 def post(self, post_id):
     try:
         username = TOKEN_AUTH.current_user()
         return PostService.unlike_post(post_id, username)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
Exemplo n.º 3
0
 def get(self):
     try:
         username = TOKEN_AUTH.current_user()
         return UserService.get_user(username, auth_info=True)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
 def post(self, post_id):
     try:
         username = TOKEN_AUTH.current_user()
         text = request.json.get('text')
         return PostService.add_post_comment(post_id, username, text)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
 def delete(self, post_id):
     try:
         username = TOKEN_AUTH.current_user()
         return PostService.delete_user_post(
             username=username,
             post_id=post_id,
         )
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
 def get(self):
     try:
         username = TOKEN_AUTH.current_user()
         skip = request.args.get('skip')
         skip = int(skip) if (skip and skip.isdigit()) else 0
         limit = request.args.get('limit')
         limit = int(limit) if (limit and limit.isdigit()) else 10
         return PostService.get_user_posts(username, skip=skip, limit=limit)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
Exemplo n.º 7
0
 def put(self):
     try:
         username = TOKEN_AUTH.current_user()
         updates = {}
         if request.form.get('description'):
             updates['description'] = request.form.get('description')
         if request.files.get('picture'):
             picture_file = request.files.get('picture')
             picture_filepath = save_file(IMAGES_DIR, picture_file)
             updates['picture_filepath'] = picture_filepath
         return UserService.update_user(username=username, **updates)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
 def put(self, post_id):
     try:
         username = TOKEN_AUTH.current_user()
         title = request.form.get('title')
         description = request.form.get('description')
         image_file = request.files.get('image')
         return PostService.update_user_post(
             username=username,
             post_id=post_id,
             title=title,
             description=description,
             image_file=image_file,
         )
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
 def get(self):
     try:
         username = TOKEN_AUTH.current_user()
         skip = request.args.get('skip')
         skip = int(skip) if (skip and skip.isdigit()) else 0
         limit = request.args.get('limit')
         limit = int(limit) if (limit and limit.isdigit()) else 10
         seed = request.args.get('seed')
         seed = int(seed) if (
             seed and seed.isdigit()
         ) else PostDiscoveryController.hash_to_seed(username)
         return PostService.get_user_discover_posts(username,
                                                    skip=skip,
                                                    limit=limit,
                                                    seed=seed)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)
Exemplo n.º 10
0
 def put(self):
     try:
         LOGGER.info(f'Endpoint called: {request.method} {request.path}')
         username = TOKEN_AUTH.current_user()
         change_password_info = {'username': username}
         if ('current_password'
                 in request.json) and (request.json['current_password']
                                       is not None):
             change_password_info['current_password'] = request.json[
                 'current_password']
         if ('new_password'
                 in request.json) and (request.json['new_password']
                                       is not None):
             change_password_info['new_password'] = request.json[
                 'new_password']
         return UserService.change_password(**change_password_info)
     except Exception as e:
         return make_response(jsonify({
             'status': 'fail',
             'error': str(e)
         }), 500)