Exemplo n.º 1
0
def del_favorite(user_id, article_id):
    from models import Favorite
    obj = Favorite.objects(user_id=user_id)
    if obj:
        favorite = obj.get()
        if article_id in favorite.article_list:
            obj.update_one(pull__article_list=article_id)
            return jsonify({"response_msg": "success",
                            "response_code": 200}), 200
    return jsonify({"response_msg": "Not Found", "response_code": 404}), 404
Exemplo n.º 2
0
def get_favorite(id):
    from models import Favorite, Item
    favorite_items = []
    obj = Favorite.objects(user_id=id)
    if obj:
        favorite = obj.get()
        for article_id in favorite.article_list:
            item = Item.objects(artical_id=article_id).get()
            favorite_items.append(item)
    return dumps(convert_items_to_list(favorite_items))
Exemplo n.º 3
0
def post_favorite():
    if not request.json or not 'user_id' in request.json or not 'article_id' in request.json:
        abort(400)
    user_id = request.json['user_id']
    article_id = request.json['article_id']
    from models import Favorite
    obj = Favorite.objects(user_id=user_id)
    if obj:
        favorite = obj.get()
    else:
        favorite = Favorite(user_id=user_id)
    favorite.article_list.append(article_id)
    favorite.article_list.sort(reverse=True)
    favorite.save()
    return jsonify({"response_msg": "success", "response_code": 201}), 201
Exemplo n.º 4
0
def article_with_user(article_id):
    if not request.json:
        abort(400)
    if not 'user_id' in request.json:
        abort(400)
    user_id = request.json['user_id']
    from models import Artical, Favorite
    article = Artical.objects(artical_id=article_id).get()
    obj = Favorite.objects(user_id=user_id)
    if obj:
        favorite = obj.get()
        article_list = favorite.article_list
        if article_id in article_list:
            return dumps(convert_artical_to_dict(article, True))
    return dumps(convert_artical_to_dict(article, False))