From ba552aff74046184727ccd77a598294bd12646f4 Mon Sep 17 00:00:00 2001 From: Backend IM Bot <> Date: Fri, 21 Mar 2025 10:33:38 +0100 Subject: [PATCH] Update generated backend for blog_app with entities: posts, comments, tags, user --- app/api/core/dependencies/dependencies.py | 5 ++++- app/api/v1/models/comments.py | 18 ++++++++++++++++++ app/api/v1/models/user.py | 22 +++++++++++++++++++++- requirements.txt | 6 +++++- 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/app/api/core/dependencies/dependencies.py b/app/api/core/dependencies/dependencies.py index 5383c0b..4f30cb4 100644 --- a/app/api/core/dependencies/dependencies.py +++ b/app/api/core/dependencies/dependencies.py @@ -1,8 +1,11 @@ +Here's the `dependencies.py` file for the `app/api/core/dependencies/` directory: + from sqlalchemy.orm import Session from app.api.db.database import SessionLocal + def get_db(): db = SessionLocal() try: yield db finally: - db.close() + db.close() \ No newline at end of file diff --git a/app/api/v1/models/comments.py b/app/api/v1/models/comments.py index cb33396..43b450d 100644 --- a/app/api/v1/models/comments.py +++ b/app/api/v1/models/comments.py @@ -1,3 +1,5 @@ +Here's the `comments.py` file for the `app/api/v1/models/` directory of the `blog_app_h23t0` FastAPI backend: + from sqlalchemy import Column, ForeignKey, Integer, String, Text from app.api.db.database import Base @@ -5,3 +7,19 @@ class Comments(Base): __tablename__ = 'comments' id = Column(Integer, primary_key=True, index=True) + post_id = Column(Integer, ForeignKey('posts.id'), nullable=False) + user_id = Column(Integer, ForeignKey('users.id'), nullable=False) + comment_text = Column(Text, nullable=False) + created_at = Column(String, nullable=False) + updated_at = Column(String, nullable=True) + +Explanation: + +1. The necessary imports from `sqlalchemy` are included: `Column`, `ForeignKey`, `Integer`, `String`, and `Text`. +5. The following columns are defined: + - `id`: An integer primary key column with an index. + - `post_id`: An integer column representing a foreign key to the `posts` table, marked as non-nullable. + - `user_id`: An integer column representing a foreign key to the `users` table, marked as non-nullable. + - `comment_text`: A text column for storing the comment content, marked as non-nullable. + - `created_at`: A string column for storing the comment creation timestamp, marked as non-nullable. + - `updated_at`: A string column for storing the comment update timestamp, nullable (allowing `None` values). \ No newline at end of file diff --git a/app/api/v1/models/user.py b/app/api/v1/models/user.py index 14f09c1..0bf6713 100644 --- a/app/api/v1/models/user.py +++ b/app/api/v1/models/user.py @@ -1,7 +1,27 @@ +Here's the `user.py` file for the `app/api/v1/models/` directory in the `blog_app` FastAPI backend: + from sqlalchemy import Column, ForeignKey, Integer, String, Text from app.api.db.database import Base class User(Base): - __tablename__ = 'user' + __tablename__ = "user" id = Column(Integer, primary_key=True, index=True) + username = Column(String, unique=True, nullable=False) + email = Column(String, unique=True, nullable=False) + password_hash = Column(String, nullable=False) + full_name = Column(String) + bio = Column(Text) + profile_pic = Column(String) + +Explanation: + +1. We import the necessary classes from `sqlalchemy` for defining the database columns: `Column`, `ForeignKey`, `Integer`, `String`, and `Text`. +5. We define the following columns for the `User` model: + - `id`: An integer primary key column with an index. + - `username`: A string column that must be unique and cannot be null. + - `email`: A string column that must be unique and cannot be null. + - `password_hash`: A string column that cannot be null (for storing the hashed password). + - `full_name`: An optional string column for the user's full name. + - `bio`: An optional text column for the user's biography. + - `profile_pic`: An optional string column for the user's profile picture URL. \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 8927dae..dce5630 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1 +1,5 @@ -# No code generated +fastapi +uvicorn +sqlalchemy +pydantic +loguru