Skip to content

Commit fe41d1d

Browse files
committed
fix merge conflicts
2 parents 7b9060f + 412eabe commit fe41d1d

File tree

14 files changed

+1915
-68
lines changed

14 files changed

+1915
-68
lines changed

backend/src/main.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from fastapi import FastAPI, HTTPException, Request
22
from fastapi.middleware.cors import CORSMiddleware
33
from fastapi.responses import JSONResponse
4+
from src.modules.account.account_router import account_router
45
from src.modules.location.location_router import location_router
5-
from src.modules.student.student_router import student_router
66
from src.modules.party.party_router import party_router
7+
from src.modules.student.student_router import student_router
78

89
app = FastAPI()
910

@@ -37,6 +38,7 @@ def read_root():
3738
return {"message": "Successful Test"}
3839

3940

41+
app.include_router(account_router)
4042
app.include_router(party_router)
4143
app.include_router(student_router)
4244
app.include_router(location_router)
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
from fastapi import APIRouter, Depends, Query
2+
from src.core.authentication import authenticate_admin
3+
from src.modules.account.account_model import Account, AccountData, AccountRole
4+
from src.modules.account.account_service import AccountService
5+
from src.modules.police.police_model import PoliceAccount, PoliceAccountUpdate
6+
from src.modules.police.police_service import PoliceService
7+
8+
account_router = APIRouter(prefix="/api/accounts", tags=["accounts"])
9+
10+
11+
@account_router.get("/police")
12+
async def get_police_credentials(
13+
police_service: PoliceService = Depends(),
14+
_=Depends(authenticate_admin),
15+
) -> PoliceAccount:
16+
police_entity = await police_service.get_police()
17+
return PoliceAccount(email=police_entity.email)
18+
19+
20+
@account_router.put("/police")
21+
async def update_police_credentials(
22+
data: PoliceAccountUpdate,
23+
police_service: PoliceService = Depends(),
24+
_=Depends(authenticate_admin),
25+
) -> PoliceAccount:
26+
police_entity = await police_service.update_police(data.email, data.password)
27+
return PoliceAccount(email=police_entity.email)
28+
29+
30+
@account_router.get("")
31+
async def list_accounts(
32+
role: list[AccountRole] | None = Query(
33+
None, description="Filter by role(s): admin, staff, student"
34+
),
35+
account_service: AccountService = Depends(),
36+
_=Depends(authenticate_admin),
37+
) -> list[Account]:
38+
return await account_service.get_accounts_by_roles(role)
39+
40+
41+
@account_router.post("")
42+
async def create_account(
43+
data: AccountData,
44+
account_service: AccountService = Depends(),
45+
_=Depends(authenticate_admin),
46+
) -> Account:
47+
return await account_service.create_account(data)
48+
49+
50+
@account_router.put("/{account_id}")
51+
async def update_account(
52+
account_id: int,
53+
data: AccountData,
54+
account_service: AccountService = Depends(),
55+
_=Depends(authenticate_admin),
56+
) -> Account:
57+
return await account_service.update_account(account_id, data)
58+
59+
60+
@account_router.delete("/{account_id}")
61+
async def delete_account(
62+
account_id: int,
63+
account_service: AccountService = Depends(),
64+
_=Depends(authenticate_admin),
65+
) -> Account:
66+
return await account_service.delete_account(account_id)

backend/src/modules/account/account_service.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,18 @@ async def get_accounts(self) -> list[Account]:
5050
accounts = result.scalars().all()
5151
return [Account.from_entity(account) for account in accounts]
5252

53+
async def get_accounts_by_roles(
54+
self, roles: list[AccountRole] | None = None
55+
) -> list[Account]:
56+
if not roles:
57+
return await self.get_accounts()
58+
59+
result = await self.session.execute(
60+
select(AccountEntity).where(AccountEntity.role.in_(roles))
61+
)
62+
accounts = result.scalars().all()
63+
return [Account.from_entity(account) for account in accounts]
64+
5365
async def get_account_by_id(self, account_id: int) -> Account:
5466
account_entity = await self._get_account_entity_by_id(account_id)
5567
return Account.from_entity(account_entity)

0 commit comments

Comments
 (0)