Feat: user blacklist

This commit is contained in:
sunwoo1524 2024-11-03 18:10:56 +09:00
parent a7e1aae744
commit b676ba7429
2 changed files with 21 additions and 0 deletions

15
database/blacklist.py Normal file
View file

@ -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

View file

@ -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()