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
+16 -49
View File
@@ -12,41 +12,24 @@ from app import app
from v1.auth.dependencies import get_auth_service
from v1.auth.schemas import (
AuthUser,
SessionCreateRequest,
OtpSendRequest,
PhoneSessionCreateRequest,
SessionRefreshRequest,
SessionResponse,
VerificationCreateRequest,
VerificationCreateResponse,
VerificationResendRequest,
VerificationVerifyRequest,
)
from v1.auth.service import AuthService
class FakeE2EAuthService(AuthService):
def __init__(self) -> None:
self._user = AuthUser(id="user-1", email="user@example.com")
self._user = AuthUser(id="user-1", phone="+8613812345678")
async def create_verification(
self, request: VerificationCreateRequest
) -> VerificationCreateResponse:
return VerificationCreateResponse(email=request.email)
async def verify_verification(
self, request: VerificationVerifyRequest
) -> SessionResponse:
return SessionResponse(
access_token="access-1",
refresh_token="refresh-1",
expires_in=3600,
token_type="bearer",
user=self._user,
)
async def resend_verification(self, request: VerificationResendRequest) -> None:
async def send_otp(self, request: OtpSendRequest) -> None:
return None
async def create_session(self, request: SessionCreateRequest) -> SessionResponse:
async def create_phone_session(
self, request: PhoneSessionCreateRequest
) -> SessionResponse:
return SessionResponse(
access_token="access-2",
refresh_token="refresh-2",
@@ -105,41 +88,25 @@ def test_auth_flow_e2e() -> None:
base_url=f"http://{host}:{port}"
)
try:
verification = request_context.post(
"/api/v1/auth/verifications",
data=json.dumps(
{
"username": "demo",
"email": "user@example.com",
"password": "secret123",
}
),
send_code = request_context.post(
"/api/v1/auth/otp/send",
data=json.dumps({"phone": "+8613812345678"}),
headers={"Content-Type": "application/json"},
)
assert verification.status == 202
assert send_code.status == 204
verify = request_context.post(
"/api/v1/auth/verify",
login_or_register = request_context.post(
"/api/v1/auth/phone-session",
data=json.dumps(
{
"email": "user@example.com",
"phone": "+8613812345678",
"token": "123456",
}
),
headers={"Content-Type": "application/json"},
)
assert verify.status == 200
assert verify.json()["access_token"] == "access-1"
login = request_context.post(
"/api/v1/auth/sessions",
data=json.dumps(
{"email": "user@example.com", "password": "secret123"}
),
headers={"Content-Type": "application/json"},
)
assert login.status == 200
assert login.json()["access_token"] == "access-2"
assert login_or_register.status == 200
assert login_or_register.json()["access_token"] == "access-2"
refresh = request_context.post(
"/api/v1/auth/sessions/refresh",