pre-prod deploy
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
2025-09-26 06:43:56 +09:00
parent d47f8679ec
commit 24c1a0c85c
2 changed files with 80 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import asyncio import asyncio
import os
import time import time
from typing import Dict, Any, Optional, List from typing import Dict, Any, Optional, List
@@ -52,11 +53,11 @@ app.add_middleware(
# Service registry # Service registry
SERVICES = { SERVICES = {
"users": "http://localhost:8001", "users": os.getenv("USER_SERVICE_URL", "http://localhost:8001"),
"emergency": "http://localhost:8002", "emergency": os.getenv("EMERGENCY_SERVICE_URL", "http://localhost:8002"),
"location": "http://localhost:8003", "location": os.getenv("LOCATION_SERVICE_URL", "http://localhost:8003"),
"calendar": "http://localhost:8004", "calendar": os.getenv("CALENDAR_SERVICE_URL", "http://localhost:8004"),
"notifications": "http://localhost:8005", "notifications": os.getenv("NOTIFICATION_SERVICE_URL", "http://localhost:8005"),
} }
# Rate limiting (simple in-memory implementation) # Rate limiting (simple in-memory implementation)
@@ -202,8 +203,31 @@ async def register_user(user_create: UserCreate, request: Request):
if response.status_code == 200: if response.status_code == 200:
return response.json() return response.json()
elif response.status_code == 400:
# Handle specific registration errors
try:
error_json = response.json()
error_detail = error_json.get("detail", "Registration failed")
if "Email already registered" in error_detail:
raise HTTPException(
status_code=400,
detail=f"Email {user_create.email} is already registered. Please use a different email or try logging in."
)
elif "Username already taken" in error_detail:
raise HTTPException(
status_code=400,
detail=f"Username {user_create.username} is already taken. Please choose a different username."
)
else:
raise HTTPException(status_code=400, detail=error_detail)
except ValueError:
# JSON parsing failed
raise HTTPException(
status_code=400,
detail="Registration failed. Please check your input data."
)
else: else:
error_detail = response.text error_detail = "Registration failed"
try: try:
error_json = response.json() error_json = response.json()
error_detail = error_json.get("detail", error_detail) error_detail = error_json.get("detail", error_detail)
@@ -214,7 +238,10 @@ async def register_user(user_create: UserCreate, request: Request):
except HTTPException: except HTTPException:
raise raise
except Exception as e: except Exception as e:
raise HTTPException(status_code=500, detail=f"Registration error: {str(e)}") raise HTTPException(
status_code=500,
detail=f"Registration service error: {str(e)}"
)
@app.post("/api/v1/auth/login", response_model=Token, tags=["Authentication"], summary="Login user") @app.post("/api/v1/auth/login", response_model=Token, tags=["Authentication"], summary="Login user")
@@ -248,6 +275,46 @@ async def login_user(user_login: UserLogin, request: Request):
raise HTTPException(status_code=500, detail=f"Login error: {str(e)}") raise HTTPException(status_code=500, detail=f"Login error: {str(e)}")
# Utility endpoints
@app.get("/api/v1/auth/check-email", tags=["Authentication"], summary="Check if email is available")
async def check_email_availability(email: str):
"""Check if email is available for registration"""
async with httpx.AsyncClient(timeout=10.0) as client:
try:
# Make request to user service to check if email exists
response = await client.get(
f"{SERVICES['users']}/api/v1/check-email",
params={"email": email}
)
if response.status_code == 200:
return response.json()
else:
return {"available": True, "message": "Email is available"}
except Exception:
return {"available": True, "message": "Unable to check availability"}
@app.get("/api/v1/auth/generate-test-data", tags=["Development"], summary="Generate test user data")
async def generate_test_user_data():
"""Generate unique test user data for development"""
import random
import string
# Generate unique email with timestamp
from datetime import datetime
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
random_suffix = ''.join(random.choices(string.ascii_lowercase + string.digits, k=4))
return {
"email": f"test_{timestamp}_{random_suffix}@example.com",
"username": f"testuser_{timestamp}_{random_suffix}",
"password": "TestPassword123!",
"first_name": "Test",
"last_name": "User",
"phone": f"+123456{random.randint(1000, 9999)}"
}
# User Service routes # User Service routes
@app.post("/api/v1/users/register", operation_id="user_register", response_model=UserResponse, tags=["Users"], summary="Register a new user") @app.post("/api/v1/users/register", operation_id="user_register", response_model=UserResponse, tags=["Users"], summary="Register a new user")
@app.get("/api/v1/users/me", operation_id="user_me_get", response_model=UserResponse, tags=["Users"], summary="Get current user profile") @app.get("/api/v1/users/me", operation_id="user_me_get", response_model=UserResponse, tags=["Users"], summary="Get current user profile")

View File

@@ -43,12 +43,12 @@ check_api_response() {
echo -e "\n${GREEN}1. Проверка доступности сервисов${NC}" echo -e "\n${GREEN}1. Проверка доступности сервисов${NC}"
services=( services=(
"http://localhost:8000" "http://192.168.0.103:8000"
"http://localhost:8001" "http://192.168.0.103:8001"
"http://localhost:8002" "http://192.168.0.103:8002"
"http://localhost:8003" "http://192.168.0.103:8003"
"http://localhost:8004" "http://192.168.0.103:8004"
"http://localhost:8005" "http://192.168.0.103:8005"
) )
service_names=( service_names=(