Feat: user blacklist
This commit is contained in:
parent
a7e1aae744
commit
b676ba7429
15
database/blacklist.py
Normal file
15
database/blacklist.py
Normal 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
|
6
main.py
6
main.py
|
@ -4,6 +4,7 @@ from typing import Annotated
|
||||||
import datetime, re
|
import datetime, re
|
||||||
|
|
||||||
from database.feed import Feed, FeedCreate, FeedPublic, FeedUpdate
|
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.feed_generator import generate_feed_of_user, USER_NOT_FOUND, CANNOT_ACCESS_INSTANCE
|
||||||
from utils.database import get_session, create_db_and_tables
|
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:
|
if re.match(HANDLE_PATTERN, user_handle) is None:
|
||||||
return HTTPException(status_code=400, detail="The handle is invalid.")
|
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
|
# get feed on database
|
||||||
feed_db = session.exec(select(Feed).where(Feed.handle == user_handle)).first()
|
feed_db = session.exec(select(Feed).where(Feed.handle == user_handle)).first()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue