Skip to content

Commit

Permalink
Merge pull request #4 from me0w00f/V2
Browse files Browse the repository at this point in the history
Add the feature: cover image.
  • Loading branch information
WeepingDogel authored Apr 26, 2024
2 parents 5f8e247 + b797347 commit 9a1a577
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 4 deletions.
8 changes: 6 additions & 2 deletions model/crud.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,10 @@ def create_admin(db: Session, AdminReg: schemas.UserReg) -> bool | User:


def create_post(post_uuid: str, user_uuid: str, posts_title: str, tags: str, category_id: int,
comment: bool, db: Session):
comment: bool, cover_url: str, db: Session):
"""
Create a data of a post in the database.
:param cover_url: URL of the cover.
:param post_uuid: Uuid of the post.
:param user_uuid: Uuid of the user.
:param posts_title: Title of the post.
Expand All @@ -149,6 +150,7 @@ def create_post(post_uuid: str, user_uuid: str, posts_title: str, tags: str, cat
author_uuid=user_uuid,
category_id=category_id,
tags=tags,
cover_url=cover_url,
comment=comment,
create_time=date,
update_time=date
Expand All @@ -170,9 +172,10 @@ def create_post(post_uuid: str, user_uuid: str, posts_title: str, tags: str, cat


def update_post(post_uuid: str, user_uuid: str, posts_title: str, tags: str, category_id: int,
comment: bool, db: Session):
comment: bool, cover_url: str, db: Session):
"""
Update a post.
:param cover_url: URL of the cover.
:param post_uuid: Uuid of the post.
:param user_uuid: Uuid of the user.
:param posts_title: Title of the post.
Expand All @@ -192,6 +195,7 @@ def update_post(post_uuid: str, user_uuid: str, posts_title: str, tags: str, cat
'title': posts_title,
'tags': tags,
'category_id': category_id,
'cover_url': cover_url,
'comment': comment,
'update_time': update_date
},
Expand Down
1 change: 1 addition & 0 deletions model/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class Posts(Base):
title = Column(TEXT, nullable=False)
author_uuid = Column(VARCHAR(36), nullable=False)
tags = Column(TEXT, nullable=False)
cover_url = Column(VARCHAR(255), nullable=True)
category_id = Column(INT, ForeignKey('categories.id'), nullable=False)
comment = Column(BOOLEAN, nullable=False)
create_time = Column(DATETIME, nullable=False)
Expand Down
8 changes: 6 additions & 2 deletions routers/posts.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,13 @@ def create_a_post(posts_title: str = Form(),
tags: str = Form(),
category_id: int = Form(),
comment: bool = Form(),
cover_url: str = Form(),
content_file: UploadFile = File(),
token: str = Depends(oauth2Scheme),
db: Session = Depends(get_db)):
"""
* Send a post with a file.
* :param cover_url: URL of the cover.
* :param posts_title: Title of the post.
* :param tags: Tags of the post.
* :param category_id: Category of the post.
Expand Down Expand Up @@ -71,7 +73,7 @@ def create_a_post(posts_title: str = Form(),
)

if crud.create_post(post_uuid=post_uuid, posts_title=posts_title, tags=tags,
comment=comment, category_id=category_id, user_uuid=author_uuid, db=db):
comment=comment, category_id=category_id, user_uuid=author_uuid, cover_url=cover_url, db=db):
return {
"Status": "Success!"
}
Expand All @@ -80,6 +82,7 @@ def create_a_post(posts_title: str = Form(),
@router_posts.put('/update')
def update_a_post(post_uuid: str = Form(),
posts_title: str = Form(),
cover_url: str = Form(),
tags: str = Form(),
category_id: int = Form(),
comment: bool = Form(),
Expand All @@ -88,6 +91,7 @@ def update_a_post(post_uuid: str = Form(),
db: Session = Depends(get_db)):
"""
* Update a post with new information and a file.
* :param cover_url: URL of the cover.
* :param post_uuid: Uuid of the post.
* :param posts_title: Title of the post.
* :param tags: Tags of the post.
Expand Down Expand Up @@ -132,7 +136,7 @@ def update_a_post(post_uuid: str = Form(),
)

if crud.update_post(post_uuid=post_uuid, user_uuid=author_uuid, posts_title=posts_title,
tags=tags, category_id=category_id, comment=comment, db=db):
tags=tags, category_id=category_id, comment=comment, cover_url=cover_url, db=db):
return {
"Status": "Success!"
}
Expand Down
2 changes: 2 additions & 0 deletions routers/resources.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ def get_posts(page: int, db: Session = Depends(get_db)):
'title': x.title,
'author_uuid': x.author_uuid,
'author_name': author.nick_name,
'cover_url': x.cover_url,
'tags': x.tags,
'category_id': x.category_id,
'category': category_name,
Expand Down Expand Up @@ -83,6 +84,7 @@ def get_single_post(post_uuid: str, db: Session = Depends(get_db)):
"post_uuid": db_post_info.post_uuid,
"title": db_post_info.title,
"tags": db_post_info.tags,
"cover_url": db_post_info.cover_url,
"author_uuid": db_post_info.author_uuid,
"author": author.nick_name,
"category_id": db_post_info.category_id,
Expand Down

0 comments on commit 9a1a577

Please sign in to comment.