Yield generated for 19b0b80a-3878-4cbb-82d9-7fdbfd07391b
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

45 lines
1.3 KiB

# coding: utf-8
from flask import Blueprint
from flask_apispec import marshal_with
from flask_jwt_extended import current_user, jwt_required, jwt_optional
from conduit.exceptions import InvalidUsage
from conduit.user.models import User
from .serializers import profile_schema
blueprint = Blueprint('profiles', __name__)
@blueprint.route('/api/profiles/<username>', methods=('GET',))
@jwt_optional
@marshal_with(profile_schema)
def get_profile(username):
user = User.query.filter_by(username=username).first()
if not user:
raise InvalidUsage.user_not_found()
return user.profile
@blueprint.route('/api/profiles/<username>/follow', methods=('POST',))
@jwt_required
@marshal_with(profile_schema)
def follow_user(username):
user = User.query.filter_by(username=username).first()
if not user:
raise InvalidUsage.user_not_found()
current_user.profile.follow(user.profile)
current_user.profile.save()
return user.profile
@blueprint.route('/api/profiles/<username>/follow', methods=('DELETE',))
@jwt_required
@marshal_with(profile_schema)
def unfollow_user(username):
user = User.query.filter_by(username=username).first()
if not user:
raise InvalidUsage.user_not_found()
current_user.profile.unfollow(user.profile)
current_user.profile.save()
return user.profile