def post(self): token = request.args.get("token") title = request.args.get("title") content = request.args.get("content") id = cache.get(token) user = Users.query.filter_by(id=id).first() if not user: data = {"msg": "login please", "status": HTTP_401_PERMISSION_FAIL} return data if title == "" or content == "": data = {"msg": "save error", "status": HTTP_400_ERROR} return data blog = UserBlog() blog.title = title blog.content = content blog.user_id = id if not blog.save(): data = {"msg": "save error", "status": HTTP_400_ERROR} return data data = { "msg": "save success", "status": HTTP_200_OK, "data": marshal(blog, blogs_fields) } return data
def post(self): token = request.args.get("token") id = cache.get(token) blog = UserBlog.query.filter_by(user_id=id).first() if not blog: data = {"msg": "find error", "status": HTTP_400_ERROR} return data data = { "msg": "find success", "status": HTTP_200_OK, "data": marshal(blog, blog_fields) } return data
def get_book(self): args = self.parser.parse_args() token = args.get("token") id = cache.get(token) # print(id) books = Books.query.filter_by(b_user_id=id).all() # print(books) if not books: data = {"msg": "no books", "status": 400} return data data = { "msg": "find success", "status": 200, "data": marshal(books, book_fields) } return data
def do_token(self): args = self.parser.parse_args() token = args.token id = cache.get(token) print(id) user = Users.query.filter_by(id=id).first() if not user: data = {"msg": "not find", "status": 404} return data books = Books.query.filter_by(id=user.id).all() data = { "msg": "find success", "status": 200, "data": marshal(books, book_fields) } return data
def do_add(self): args = self.parser.parse_args() b_name = args.b_name b_author = args.b_author token = args.token id = cache.get(token) book = Books() book.b_name = b_name book.b_author = b_author book.b_user_id = id if not book.save(): data = {"msg": "save error", "status": 404} return data data = { "msg": "save success", "status": 200, } return data
def post(self): token = request.args.get("token") blog_id = request.args.get("blog_id") # 传过来的收藏文章的id id = cache.get(token) user = Users.query.filter_by(id=id).first() if not user: data = {"msg": "login please", "status": HTTP_401_PERMISSION_FAIL} return data hobby = HobbyBlog() hobby.user_id = id hobby.blog_id = blog_id if not hobby.save(): data = {"msg": "save error", "status": HTTP_400_ERROR} return data data = { "msg": "save success", "status": HTTP_200_OK, "data": marshal(user, user_fields) } return data
def post(self): token = request.args.get("token") content = request.args.get("content") id = cache.get(token) user = Users.query.filter_by(id=id).first() if not user: data = {"msg": "login please", "status": HTTP_401_PERMISSION_FAIL} return data if content == "": data = {"msg": "error", "status": HTTP_401_PERMISSION_FAIL} return data comment = UserComment() comment.conten = content comment.user_id = id if not comment.save(): data = {"msg": "save error", "status": HTTP_400_ERROR} return data data = { "msg": "save success", "statuc": HTTP_200_OK, "data": marshal(comment, comment_fields) } return data