Skip to content

Commit 2fdbf37

Browse files
committed
FEAT: Update Community model to include role field and modify admin creation logic to use orm
1 parent 1af2992 commit 2fdbf37

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

app/routers/admin/routes.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@ async def create_admin(session: AsyncSession):
2222
hashed_password = auth.hash_password(password)
2323
community = DBCommunity(
2424
username=ADMIN_USER,
25-
email="ADMIN_USER",
25+
email="ADMIN_USER@mail.com",
2626
password=hashed_password,
2727
role="admin",
2828
)
29-
session.add(community)
30-
await session.commit()
31-
await session.refresh(community)
29+
await create_community(session=session, community=community)
30+
31+
# session.add(community)
32+
# await session.commit()
33+
# await session.refresh(community)
3234
return {"msg": "Admin successfully created"}
3335

3436

app/schemas.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,10 @@ class Community(BaseModel):
3434
email: str
3535

3636

37-
# Extends Community Class with hashed password
37+
# Extends Community Class with hashed password and role
3838
class CommunityInDB(Community):
3939
password: str
40+
role: str
4041

4142

4243
class News(BaseModel):

app/services/database/models/communities.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ class Community(SQLModel, table=True):
1717
default_factory=datetime.now,
1818
sa_column_kwargs={"onupdate": datetime.now},
1919
)
20+
role: str = Field(default="user") # user or admin

0 commit comments

Comments
 (0)