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
@@ -1,11 +1,13 @@
from __future__ import annotations
import pytest
from datetime import datetime
from uuid import uuid4
import pytest
from pydantic import ValidationError
from schemas.user.context import UserContext
from v1.friendships.schemas import (
UserBasicInfo,
FriendRequestCreate,
FriendRequestResponse,
FriendResponse,
@@ -13,16 +15,16 @@ from v1.friendships.schemas import (
)
def test_user_basic_info_maps_fields() -> None:
user = UserBasicInfo(id="user-1", username="alice", avatar_url=None)
def test_user_context_maps_fields() -> None:
user = UserContext(id="user-1", username="alice", avatar_url=None)
assert user.id == "user-1"
assert user.username == "alice"
assert user.avatar_url is None
def test_user_basic_info_with_avatar() -> None:
user = UserBasicInfo(
def test_user_context_with_avatar() -> None:
user = UserContext(
id="user-2", username="bob", avatar_url="https://example.com/avatar.png"
)
@@ -49,13 +51,13 @@ def test_friend_request_create_without_content() -> None:
def test_friend_request_create_content_max_length() -> None:
target_id = uuid4()
with pytest.raises(Exception):
with pytest.raises(ValidationError):
FriendRequestCreate(target_user_id=target_id, content="x" * 201)
def test_friend_request_response_maps_fields() -> None:
sender = UserBasicInfo(id="user-1", username="alice", avatar_url=None)
recipient = UserBasicInfo(id="user-2", username="bob", avatar_url=None)
sender = UserContext(id="user-1", username="alice", avatar_url=None)
recipient = UserContext(id="user-2", username="bob", avatar_url=None)
request_id = uuid4()
created = datetime(2026, 1, 15, 10, 30, 0)
@@ -63,7 +65,7 @@ def test_friend_request_response_maps_fields() -> None:
id=request_id,
sender=sender,
recipient=recipient,
content="Hello!",
content={"text": "Hello!"},
status="pending",
created_at=created,
)
@@ -76,7 +78,7 @@ def test_friend_request_response_maps_fields() -> None:
def test_friend_response_maps_fields() -> None:
friend_user = UserBasicInfo(id="user-2", username="bob", avatar_url=None)
friend_user = UserContext(id="user-2", username="bob", avatar_url=None)
request_id = uuid4()
created = datetime(2026, 1, 15, 10, 30, 0)
accepted = datetime(2026, 1, 16, 12, 0, 0)
@@ -96,7 +98,7 @@ def test_friend_response_maps_fields() -> None:
def test_friend_response_accepted_at_optional() -> None:
friend_user = UserBasicInfo(id="user-2", username="bob", avatar_url=None)
friend_user = UserContext(id="user-2", username="bob", avatar_url=None)
request_id = uuid4()
created = datetime(2026, 1, 15, 10, 30, 0)