Пример #1
0
def blog_id_delete(id: int):
    try:
        blog_model = get_blog_by_id(id)
    except BlogNotFoundException:
        return response.not_found('Blog cannot be found')

    if g.user.id != blog_model.author_id:
        return response.unauthorized(
            'Only the author can remove their article')

    delete_blog_by_model(blog_model)
    return response.ok()
Пример #2
0
def blog_id_patch(args, id: int):
    try:
        blog_model = get_blog_by_id(id)
    except BlogNotFoundException:
        return response.not_found('Blog cannot be found')

    if g.user.id != blog_model.author_id:
        return response.unauthorized(
            'Only the author can remove their article')

    tags = args.get('tags', [])
    text = args.get('text', '')
    update_blog_by_model(blog_model, tags, text)
    return response.ok()
Пример #3
0
 def decorated_function(*args, **kwargs):
     if g.user is None:
         return response.unauthorized()
     return func(*args, **kwargs)