refactor(backend): update API routes and service layer

- Update agent router/service/repository with new endpoints
- Update auth routes with phone-based authentication
- Update users service with new phone lookup
- Update schedule_items with new schemas
- Update message schemas with visibility support
- Update settings with new automation scheduler config
- Update CLI with new commands
- Update tests to match new API contracts
This commit is contained in:
qzl
2026-03-19 18:42:59 +08:00
parent 641d847008
commit f0af44d840
36 changed files with 1083 additions and 1853 deletions
@@ -9,12 +9,12 @@ from fastapi.testclient import TestClient
from app import app
from core.auth.models import CurrentUser
from schemas.user.context import UserContext
from v1.friendships.dependencies import get_friendship_service
from v1.friendships.schemas import (
FriendRequestCreate,
FriendRequestResponse,
FriendResponse,
UserBasicInfo,
)
from v1.friendships.service import FriendshipService
from v1.users.dependencies import get_current_user
@@ -31,9 +31,9 @@ class FakeFriendshipService(FriendshipService):
async def send_request(self, request: FriendRequestCreate) -> FriendRequestResponse:
return FriendRequestResponse(
id=UUID("11111111-1111-1111-1111-111111111111"),
sender=UserBasicInfo(id="user-1", username="sender", avatar_url=None),
recipient=UserBasicInfo(id="user-2", username="recipient", avatar_url=None),
content=request.content,
sender=UserContext(id="user-1", username="sender", avatar_url=None),
recipient=UserContext(id="user-2", username="recipient", avatar_url=None),
content={"text": request.content} if request.content else None,
status="pending",
created_at=datetime.now(timezone.utc),
)
@@ -41,9 +41,9 @@ class FakeFriendshipService(FriendshipService):
async def accept_request(self, friendship_id: UUID) -> FriendRequestResponse:
return FriendRequestResponse(
id=friendship_id,
sender=UserBasicInfo(id="user-1", username="sender", avatar_url=None),
recipient=UserBasicInfo(id="user-2", username="recipient", avatar_url=None),
content="Hello!",
sender=UserContext(id="user-1", username="sender", avatar_url=None),
recipient=UserContext(id="user-2", username="recipient", avatar_url=None),
content={"text": "Hello!"},
status="accepted",
created_at=datetime.now(timezone.utc),
)
@@ -51,9 +51,9 @@ class FakeFriendshipService(FriendshipService):
async def decline_request(self, friendship_id: UUID) -> FriendRequestResponse:
return FriendRequestResponse(
id=friendship_id,
sender=UserBasicInfo(id="user-1", username="sender", avatar_url=None),
recipient=UserBasicInfo(id="user-2", username="recipient", avatar_url=None),
content="Hello!",
sender=UserContext(id="user-1", username="sender", avatar_url=None),
recipient=UserContext(id="user-2", username="recipient", avatar_url=None),
content={"text": "Hello!"},
status="rejected",
created_at=datetime.now(timezone.utc),
)
@@ -61,9 +61,9 @@ class FakeFriendshipService(FriendshipService):
async def cancel_request(self, friendship_id: UUID) -> FriendRequestResponse:
return FriendRequestResponse(
id=friendship_id,
sender=UserBasicInfo(id="user-1", username="sender", avatar_url=None),
recipient=UserBasicInfo(id="user-2", username="recipient", avatar_url=None),
content="Hello!",
sender=UserContext(id="user-1", username="sender", avatar_url=None),
recipient=UserContext(id="user-2", username="recipient", avatar_url=None),
content={"text": "Hello!"},
status="canceled",
created_at=datetime.now(timezone.utc),
)
@@ -72,11 +72,11 @@ class FakeFriendshipService(FriendshipService):
return [
FriendRequestResponse(
id=UUID("11111111-1111-1111-1111-111111111111"),
sender=UserBasicInfo(id="user-1", username="sender", avatar_url=None),
recipient=UserBasicInfo(
sender=UserContext(id="user-1", username="sender", avatar_url=None),
recipient=UserContext(
id="user-2", username="recipient", avatar_url=None
),
content="Hello!",
content={"text": "Hello!"},
status="pending",
created_at=datetime.now(timezone.utc),
)
@@ -86,10 +86,8 @@ class FakeFriendshipService(FriendshipService):
return [
FriendRequestResponse(
id=UUID("22222222-2222-2222-2222-222222222222"),
sender=UserBasicInfo(id="user-1", username="sender", avatar_url=None),
recipient=UserBasicInfo(
id="user-3", username="target", avatar_url=None
),
sender=UserContext(id="user-1", username="sender", avatar_url=None),
recipient=UserContext(id="user-3", username="target", avatar_url=None),
content=None,
status="pending",
created_at=datetime.now(timezone.utc),
@@ -100,7 +98,7 @@ class FakeFriendshipService(FriendshipService):
return [
FriendResponse(
id=UUID("33333333-3333-3333-3333-333333333333"),
friend=UserBasicInfo(id="user-2", username="friend", avatar_url=None),
friend=UserContext(id="user-2", username="friend", avatar_url=None),
status="active",
created_at=datetime.now(timezone.utc),
accepted_at=datetime.now(timezone.utc),
@@ -110,7 +108,7 @@ class FakeFriendshipService(FriendshipService):
async def remove_friend(self, friend_id: UUID) -> FriendResponse:
return FriendResponse(
id=UUID("33333333-3333-3333-3333-333333333333"),
friend=UserBasicInfo(id=str(friend_id), username="friend", avatar_url=None),
friend=UserContext(id=str(friend_id), username="friend", avatar_url=None),
status="active",
created_at=datetime.now(timezone.utc),
accepted_at=datetime.now(timezone.utc),
@@ -129,7 +127,7 @@ def _override_friendship_service(
def _get_fake_current_user() -> CurrentUser:
return CurrentUser(
id=UUID("00000000-0000-0000-0000-000000000001"),
email="test@example.com",
phone="+8613812345678",
)