Example #1
0
 def post(self):
     """create a comment"""
     args = _comment_parser.parse_args()
     db = get_db()
     query_id = db.comments.insert_one(args).inserted_id
     return marshal(db.comments.find_one({'_id': query_id}),
                    _comment_fields), 201
Example #2
0
 def put(self, comment_id):
     """更新 评论"""
     args = _comment_parser.parse_args()
     r = get_db().comments.find_one_and_update(
         {'_id': ObjectId(comment_id)}, {'$set': {
             'username': '******'
         }},
         return_document=ReturnDocument.AFTER)
     return marshal(r, _comment_fields), 201
Example #3
0
 def post(self):
     """添加一个分类信息"""
     args = _catalog_parser.parse_args()
     db = get_db()
     max_id = max([ item.get('catalog_id',0) for item in list(db.catalogs.find()) ] or (0,))
     args.update({
         'catalog_id': max_id + 1
         })
     query_id = db.catalogs.insert_one(args).inserted_id
     return marshal(db.catalogs.find_one({'_id': query_id}), _catalog_fields), 201
Example #4
0
 def post(self):
     """添加一个收藏"""
     args = _stars_parser.parse_args()
     db = get_db()
     max_id = max([item.get("id", 0) for item in list(db.stars.find())]
                  or (0, ))
     args.update({
         "id": max_id + 1,
         "date": datetime.strptime(args["date"], '%Y/%m/%d')
     })
     query_id = db.stars.insert_one(args).inserted_id
     return marshal(db.stars.find_one({"_id": query_id}),
                    _stars_fields), 201
Example #5
0
 def post(self):
     args = _blog_parser.parse_args()
     db = get_db()
     create_at = datetime.now()    # 官网建议用 utcnow()
     update_at = datetime.now()
     max_id = max([item.get('blog_id',0) for item in list(db.blogs.find())] or (0,)) # 找到最大的id
     args.update({
         'blog_id': max_id + 1,
         'read_size': 0,
         'comment_size': 0,
         'create_at': create_at,
         'update_at': update_at,
         'username': ''
         })
     query_id = db.blogs.insert_one(args).inserted_id
     return marshal(db.blogs.find_one({'_id':query_id}), _blog_fields), 201
Example #6
0
 def get(self):
     blogs = get_db().blogs.find()
     return list(blogs)
Example #7
0
 def delete(self, catalog_id):
     """删除一个分类"""
     get_db().catalogs.find_one_and_delete({'catalog_id': catalog_id})
     return '', 204
Example #8
0
 def put(self,catalog_id):
     """更新一个分类名"""
     args = _catalog_parser.parse_args()
     result = get_db().catalogs.find_one_and_update({'catalog_id': catalog_id},{'$set': args},return_document=ReturnDocument.AFTER)
     return marshal(result, _catalog_fields), 201
Example #9
0
 def get(self,catalog_id):
     """得到一个分类"""
     return get_db().catalogs.find_one({'catalog_id': catalog_id})
Example #10
0
 def delete(self):
     """删除所有的分类"""
     get_db().catalogs.delete_many({})
     return '', 204
Example #11
0
 def put(self,blog_id):
     """update blog"""
     args = _blog_parser.parse_args()
     args.update({'update_at': datetime.now()})
     result = get_db().blogs.find_one_and_update({'blog_id': blog_id}, {'$set': args }, return_document=ReturnDocument.AFTER)
     return marshal(result, _blog_fields), 201
Example #12
0
 def delete(self, star_id):
     """delete one star"""
     get_db().stars.find_one_and_delete({'id': star_id})
     return '', 204
Example #13
0
 def get(self):
     """get all star list"""
     return list(get_db().stars.find())
Example #14
0
 def delete(self, comment_id):
     """delete a comment"""
     get_db().comments.find_one_and_delete({'_id': ObjectId(comment_id)})
     return '', 204
Example #15
0
 def get(self, comment_id):
     """get a comment"""
     return get_db().comments.find_one({'_id': ObjectId(comment_id)})
Example #16
0
 def delete(self):
     get_db().comments.delete_many({})
     return '', 204
Example #17
0
 def get(self,blog_id):
     return get_db().blogs.find_one({'blog_id': blog_id})
Example #18
0
 def get(self):
     """get all catalogs"""
     return list(get_db().catalogs.find())
Example #19
0
 def delete(self,blog_id):
     """delete blog"""
     get_db().blogs.find_one_and_delete({'blog_id': blog_id})
     return '', 204
Example #20
0
 def get(self):
     """ get all comments """
     comments = get_db().comments.find()
     return list(comments)