This commit is contained in:
@@ -185,9 +185,70 @@ async def rate_limiting_middleware(request: Request, call_next):
|
||||
return await call_next(request)
|
||||
|
||||
|
||||
# Authentication routes
|
||||
@app.post("/api/v1/auth/register", response_model=UserResponse, tags=["Authentication"], summary="Register a new user")
|
||||
async def register_user(user_create: UserCreate, request: Request):
|
||||
"""Register a new user"""
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
try:
|
||||
response = await client.post(
|
||||
f"{SERVICES['users']}/api/v1/auth/register",
|
||||
json=user_create.model_dump(),
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
error_detail = response.text
|
||||
try:
|
||||
error_json = response.json()
|
||||
error_detail = error_json.get("detail", error_detail)
|
||||
except:
|
||||
pass
|
||||
raise HTTPException(status_code=response.status_code, detail=error_detail)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Registration error: {str(e)}")
|
||||
|
||||
|
||||
@app.post("/api/v1/auth/login", response_model=Token, tags=["Authentication"], summary="Login user")
|
||||
async def login_user(user_login: UserLogin, request: Request):
|
||||
"""Login user"""
|
||||
async with httpx.AsyncClient(timeout=30.0) as client:
|
||||
try:
|
||||
response = await client.post(
|
||||
f"{SERVICES['users']}/api/v1/auth/login",
|
||||
json=user_login.model_dump(),
|
||||
headers={
|
||||
"Content-Type": "application/json",
|
||||
"Accept": "application/json"
|
||||
}
|
||||
)
|
||||
|
||||
if response.status_code == 200:
|
||||
return response.json()
|
||||
else:
|
||||
error_detail = response.text
|
||||
try:
|
||||
error_json = response.json()
|
||||
error_detail = error_json.get("detail", error_detail)
|
||||
except:
|
||||
pass
|
||||
raise HTTPException(status_code=response.status_code, detail=error_detail)
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
except Exception as e:
|
||||
raise HTTPException(status_code=500, detail=f"Login error: {str(e)}")
|
||||
|
||||
|
||||
# User Service routes
|
||||
@app.post("/api/v1/auth/register", operation_id="user_auth_register", response_model=UserResponse, tags=["Authentication"], summary="Register a new user")
|
||||
@app.post("/api/v1/auth/login", operation_id="user_auth_login", response_model=Token, tags=["Authentication"], summary="Login 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.patch("/api/v1/users/me", operation_id="user_me_patch", response_model=UserResponse, tags=["Users"], summary="Update user profile")
|
||||
|
||||
Reference in New Issue
Block a user