Compare commits
1 Commits
main
...
update-174
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ba552aff74 |
@ -1,5 +1,8 @@
|
||||
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:
|
||||
|
@ -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).
|
@ -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.
|
@ -1 +1,5 @@
|
||||
# No code generated
|
||||
fastapi
|
||||
uvicorn
|
||||
sqlalchemy
|
||||
pydantic
|
||||
loguru
|
||||
|
Loading…
x
Reference in New Issue
Block a user