Exemplo n.º 1
0
def create_tag(tag: schemas.TagCreate):
    db_tag = models.Tag(title=tag.title, author_id=tag.author_id)
    try:
        db_tag.save()
        return db_tag
    except peewee.IntegrityError:
        raise exceptions.UnprocessableEntityHTTPException()
Exemplo n.º 2
0
def create_post(post: schemas.PostCreate):
    db_post = models.Post(**post.dict())
    try:
        db_post.save()
        return db_post
    except peewee.IntegrityError:
        raise exceptions.UnprocessableEntityHTTPException()
Exemplo n.º 3
0
def create_catalog(catalog: schemas.CatalogCreate):
    db_catalog = models.Catalog(title=catalog.title,
                                author_id=catalog.author_id)
    try:
        db_catalog.save()
        return db_catalog
    except exceptions.UnprocessableEntityHTTPException:
        raise exceptions.UnprocessableEntityHTTPException()
Exemplo n.º 4
0
def create_comment(comment: schemas.CommentCreate):
    # TODO: check comment tree attribute
    db_comment = models.Comment(**comment.dict())
    try:
        db_comment.save()
        return db_comment
    except peewee.IntegrityError:
        raise exceptions.UnprocessableEntityHTTPException()
Exemplo n.º 5
0
def create_user(user: schemas.UserCreate):
    fake_hashed_password = user.password + "not_really_hashed_password"
    fake_random_token = "fake_random_token"
    db_user = models.User(
        username=user.username,
        hashed_password=fake_hashed_password,
        token=fake_random_token,
    )
    try:
        db_user.save()
        return db_user
    except peewee.IntegrityError:
        raise exceptions.UnprocessableEntityHTTPException(detail="用户名重复")