def update_idea(user: directives.user, id: hug.types.text, body: IdeaSchema()) -> IdeaSchema(): idea = Idea.objects(user=user, id=bson.ObjectId(id)).first() if not idea: raise hug.HTTPNotFound() result = IdeaSchema().update(idea, IdeaSchema().dump(body).data) result.data.save() return result.data
def delete_idea(user: directives.user, id: hug.types.text): idea = Idea.objects(user=user, id=bson.ObjectId(id)).first() if not idea: raise hug.HTTPNotFound() idea.delete()
def get_ideas(user: directives.user, page: hug.types.number = 1, page_size: hug.types.number = 10): items_per_page = page_size offset = (page - 1) * items_per_page return [IdeaSchema().dump(i).data for i in Idea.objects(user=user).order_by("-average_score").skip(offset).limit(items_per_page)]