diff --git a/db.py b/db.py index c6a3808..5bf0a84 100644 --- a/db.py +++ b/db.py @@ -24,6 +24,7 @@ class Post(BaseModel): id: int = Field(default_factory=next_post_id) created_at: datetime = Field(default_factory=datetime.now) updated_at: datetime = Field(default_factory=datetime.now) + title_of_post: str = Field(..., max_length=100) body: str author: str diff --git a/posts.py b/posts.py index df0428a..1124c7e 100644 --- a/posts.py +++ b/posts.py @@ -7,6 +7,7 @@ class PostCreateSchema(BaseModel): body: str author: str + title: str router = APIRouter() @@ -29,5 +30,8 @@ def get_by_id(post_id: int): @router.post("/posts") def create_new_post(post_create: PostCreateSchema): + if len(post.title) > 100: + return "Post title should be max. 100 cahracters long" + post = Post(**post_create.dict()) return save_post(post) diff --git a/ticket-MT-846.txt b/ticket-MT-846.txt deleted file mode 100644 index d30ee0b..0000000 --- a/ticket-MT-846.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Add a title to each Post - -The title should have a max length of 100 characters \ No newline at end of file