def like_movie(userid='', movie_code=''): if not userservice.check_user_exist(userid=userid): return {}, 0, '用户不存在' if not check_movie_exist(movie_code=movie_code): return {}, 0, '影片不存在' movie = Avmoo.objects(code=movie_code)[0] like = Like.objects(userid=userid, movie_code=movie_code) if like.__len__() > 0: like = like[0] like.valid = 1 like.update_time = datetime.now() else: like = Like(userid=userid, movie_code=movie.code, movieid=str(movie.id), valid=1, update_time=datetime.now()) like.save() if movie.like_count is None: movie.like_count = 1 else: movie.like_count += 1 movie.save() return {}, 1, ''
def create_like(post_id): user = SESSION.get(request.headers.get('Authorization')) if user is None: abort(400, {'message': 'TOKEN_NOT_FOUND'}) # input_data = request.get_json() from model import Like, Post post_exist = Post.find(post_id) if post_exist is None: abort(400, {'message','POST_NOT_FOUND'}) like = Like() like.post_id = post_id like.user_id = user.id like.save() return "Liked."