99from app .services import auth
1010from app .services .database .models import Community as DBCommunity # Precisa?
1111from app .services .database .orm .community import create_community
12+ from app .services .limiter import limiter
1213
1314# ADMIN_USER = os.getenv("ADMIN_USER")
1415# ADMIN_PASSWORD = os.getenv("ADMIN_PASSWORD")
1516
1617
17- async def create_community_admin (session : AsyncSession ):
18+ async def create_admin (session : AsyncSession ):
1819 ADMIN_USER = os .getenv ("ADMIN_USER" )
1920 ADMIN_PASSWORD = os .getenv ("ADMIN_PASSWORD" )
2021 password = ADMIN_PASSWORD
@@ -25,7 +26,6 @@ async def create_community_admin(session: AsyncSession):
2526 password = hashed_password ,
2627 role = "admin" ,
2728 )
28- session : AsyncSession = session
2929 session .add (community )
3030 await session .commit ()
3131 await session .refresh (community )
@@ -37,30 +37,32 @@ class CommunityPostResponse(BaseModel):
3737
3838
3939def setup ():
40- router = APIRouter (prefix = "/admin" , tags = ["news " ])
40+ router = APIRouter (prefix = "/admin" , tags = ["admin " ])
4141
4242 @router .post (
43- "create_community" ,
43+ "/ create_community" ,
4444 response_model = CommunityPostResponse ,
45- status_code = status .HTTP_200_OK ,
45+ status_code = status .HTTP_201_CREATED ,
4646 summary = "Create Community endpoint" ,
4747 description = "Create Community and returns a confirmation message" ,
4848 )
49+ @limiter .limit ("60/minute" )
4950 async def post_create_community (
5051 request : Request ,
5152 admin_community : Annotated [
5253 DBCommunity , Depends (get_current_active_community )
5354 ],
54- community : Annotated [ DBCommunity ] ,
55+ community : DBCommunity ,
5556 ):
5657 """
57- Server Admin endpoint that creates Community and returns a confirmation message.
58+ Server Admin endpoint that creates Community and returns a confirmation
59+ message.
5860 """
59- admin_role = admin_community .get ( " role" )
61+ admin_role = admin_community .role
6062 if admin_role != "admin" :
6163 return {"status" : "Unauthorized" }
62- await create_community (
63- session = request .app .db_session_factory , community = community
64- )
64+ await create_community (request = request , community = community )
6565
6666 return CommunityPostResponse ()
67+
68+ return router
0 commit comments