API client

This commit is contained in:
valenti 2026-04-16 12:35:11 -04:00
parent 9990de0d52
commit f7afd0c7af
2 changed files with 0 additions and 70 deletions

View File

@ -7,7 +7,6 @@ from fastapi import APIRouter, Depends, HTTPException, status
from motor.motor_asyncio import AsyncIOMotorDatabase from motor.motor_asyncio import AsyncIOMotorDatabase
from fastcheck_api.app.api.dependencies import CurrentUser, get_current_user from fastcheck_api.app.api.dependencies import CurrentUser, get_current_user
from fastcheck_api.app.core.config import settings
from fastcheck_api.app.core.mongodb import get_db from fastcheck_api.app.core.mongodb import get_db
from fastcheck_api.app.core.security import create_access_token from fastcheck_api.app.core.security import create_access_token
from fastcheck_api.app.schemas.auth import LoginRequest, LoginResponse, UserOut from fastcheck_api.app.schemas.auth import LoginRequest, LoginResponse, UserOut
@ -15,7 +14,6 @@ from fastcheck_api.app.services.auth_service import AuthService
router = APIRouter(prefix="/auth", tags=["auth"]) router = APIRouter(prefix="/auth", tags=["auth"])
API_PREFIX = settings.normalized_api_prefix or "/api/v1"
@router.post( @router.post(
@ -23,25 +21,6 @@ API_PREFIX = settings.normalized_api_prefix or "/api/v1"
response_model=LoginResponse, response_model=LoginResponse,
summary="Login", summary="Login",
description="Authenticate with email and password and receive a bearer JWT token compatible with the existing Node.js backend.", description="Authenticate with email and password and receive a bearer JWT token compatible with the existing Node.js backend.",
openapi_extra={
"x-code-samples": [
{
"lang": "curl",
"label": "cURL",
"source": f"curl -X POST 'http://127.0.0.1:8181{API_PREFIX}/auth/login' \\\n -H 'Content-Type: application/json' \\\n -d '{{\"email\":\"user@example.com\",\"password\":\"********\"}}'",
},
{
"lang": "python",
"label": "httpx",
"source": f"import httpx\nresp = httpx.post('http://127.0.0.1:8181{API_PREFIX}/auth/login', json={{\n 'email': 'user@example.com',\n 'password': '********'\n}})\nprint(resp.json())",
},
{
"lang": "js",
"label": "fetch",
"source": f"const resp = await fetch('http://127.0.0.1:8181{API_PREFIX}/auth/login', {{\n method: 'POST',\n headers: {{ 'Content-Type': 'application/json' }},\n body: JSON.stringify({{ email: 'user@example.com', password: '********' }})\n}});\nconsole.log(await resp.json());",
},
]
},
) )
async def login(payload: LoginRequest, db: Annotated[AsyncIOMotorDatabase, Depends(get_db)]): async def login(payload: LoginRequest, db: Annotated[AsyncIOMotorDatabase, Depends(get_db)]):
try: try:
@ -81,20 +60,6 @@ async def me(
"/refresh", "/refresh",
summary="Refresh token", summary="Refresh token",
description="Issue a new JWT token using the current token's identity and tenant context.", description="Issue a new JWT token using the current token's identity and tenant context.",
openapi_extra={
"x-code-samples": [
{
"lang": "curl",
"label": "cURL",
"source": f"curl -X POST 'http://127.0.0.1:8181{API_PREFIX}/auth/refresh' \\\n -H 'Authorization: Bearer <jwt>'",
},
{
"lang": "python",
"label": "httpx",
"source": f"import httpx\nresp = httpx.post('http://127.0.0.1:8181{API_PREFIX}/auth/refresh', headers={{\n 'Authorization': 'Bearer <jwt>'\n}})\nprint(resp.json())",
},
]
},
) )
async def refresh(user: Annotated[CurrentUser, Depends(get_current_user)]): async def refresh(user: Annotated[CurrentUser, Depends(get_current_user)]):
token = create_access_token(user_id=user.id, email=user.email, role=user.role, tenant_id=user.tenant) token = create_access_token(user_id=user.id, email=user.email, role=user.role, tenant_id=user.tenant)

View File

@ -7,7 +7,6 @@ from fastapi import APIRouter, Depends, HTTPException, Query, Request, status
from motor.motor_asyncio import AsyncIOMotorDatabase from motor.motor_asyncio import AsyncIOMotorDatabase
from fastcheck_api.app.api.dependencies import CurrentUser, require_permission from fastcheck_api.app.api.dependencies import CurrentUser, require_permission
from fastcheck_api.app.core.config import settings
from fastcheck_api.app.core.mongodb import get_db from fastcheck_api.app.core.mongodb import get_db
from fastcheck_api.app.schemas.checks import ( from fastcheck_api.app.schemas.checks import (
CreateCheckRequest, CreateCheckRequest,
@ -20,7 +19,6 @@ from fastcheck_api.app.services.check_service import CheckService, InsufficientC
router = APIRouter(prefix="/checks", tags=["checks"]) router = APIRouter(prefix="/checks", tags=["checks"])
API_PREFIX = settings.normalized_api_prefix or "/api/v1"
@router.get( @router.get(
@ -44,25 +42,6 @@ async def list_checks(
status_code=status.HTTP_201_CREATED, status_code=status.HTTP_201_CREATED,
summary="Create a check", summary="Create a check",
description="Create a single evaluation job and enqueue processing in RabbitMQ using the existing queue and message format.", description="Create a single evaluation job and enqueue processing in RabbitMQ using the existing queue and message format.",
openapi_extra={
"x-code-samples": [
{
"lang": "curl",
"label": "cURL",
"source": f"curl -X POST 'http://127.0.0.1:8181{API_PREFIX}/checks' \\\n -H 'Authorization: Bearer <jwt>' \\\n -H 'Content-Type: application/json' \\\n -d '{{\"supplier\":{{\"rut\":\"12345678-9\",\"name\":\"ACME SpA\"}}}}'",
},
{
"lang": "python",
"label": "httpx",
"source": f"import httpx\nresp = httpx.post('http://127.0.0.1:8181{API_PREFIX}/checks',\n headers={{'Authorization': 'Bearer <jwt>'}},\n json={{'supplier': {{'rut': '12345678-9', 'name': 'ACME SpA'}}}})\nprint(resp.json())",
},
{
"lang": "js",
"label": "fetch",
"source": f"const resp = await fetch('http://127.0.0.1:8181{API_PREFIX}/checks', {{\n method: 'POST',\n headers: {{\n 'Authorization': 'Bearer <jwt>',\n 'Content-Type': 'application/json'\n }},\n body: JSON.stringify({{ supplier: {{ rut: '12345678-9', name: 'ACME SpA' }} }})\n}});\nconsole.log(await resp.json());",
},
]
},
) )
async def create_check( async def create_check(
request: Request, request: Request,
@ -139,20 +118,6 @@ async def get_check(
response_model=ListResultsResponse, response_model=ListResultsResponse,
summary="List check results", summary="List check results",
description="List evaluation results for a given job id (tenant-scoped).", description="List evaluation results for a given job id (tenant-scoped).",
openapi_extra={
"x-code-samples": [
{
"lang": "curl",
"label": "cURL",
"source": f"curl 'http://127.0.0.1:8181{API_PREFIX}/checks/<job_id>/results?page=1&limit=10' \\\n -H 'Authorization: Bearer <jwt>'",
},
{
"lang": "python",
"label": "httpx",
"source": f"import httpx\nresp = httpx.get('http://127.0.0.1:8181{API_PREFIX}/checks/<job_id>/results',\n params={{'page': 1, 'limit': 10}},\n headers={{'Authorization': 'Bearer <jwt>'}})\nprint(resp.json())",
},
]
},
) )
async def get_check_results( async def get_check_results(
job_id: str, job_id: str,