diff --git a/database/blacklist.py b/database/blacklist.py new file mode 100644 index 0000000..7399634 --- /dev/null +++ b/database/blacklist.py @@ -0,0 +1,15 @@ +from typing import Optional +from sqlmodel import Field, SQLModel +import datetime + + +class BlacklistBase(SQLModel): + handle: str + + +class Blacklist(BlacklistBase, table=True): + id: int | None = Field(default=None, primary_key=True) + + +class BlacklistCreate(BlacklistBase): + pass \ No newline at end of file diff --git a/main.py b/main.py index 9c3bfa4..85ff721 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,7 @@ from typing import Annotated import datetime, re from database.feed import Feed, FeedCreate, FeedPublic, FeedUpdate +from database.blacklist import Blacklist, BlacklistCreate from utils.feed_generator import generate_feed_of_user, USER_NOT_FOUND, CANNOT_ACCESS_INSTANCE from utils.database import get_session, create_db_and_tables @@ -23,6 +24,11 @@ def get_feed_of_user(user_handle: str, session: SessionDep): if re.match(HANDLE_PATTERN, user_handle) is None: return HTTPException(status_code=400, detail="The handle is invalid.") + # check if there is the user in blacklist + black_user = session.exec(select(Blacklist).where(Blacklist.handle == user_handle)).first + if black_user: + return HTTPException(status_code=401, detail="The user is in blacklist.") + # get feed on database feed_db = session.exec(select(Feed).where(Feed.handle == user_handle)).first()