Ejemplo:

import fastapi
from fastapi.encoders import jsonable_encoder
from starlette.requests import Request

# Definimos las interfaces del Dominio
class UserService:
    def get_user(self, user_id):
        # implementación de la lógica de negocio
        pass

# Definimos la capa de Aplicación
class UserResource:
    def __init__(self, user_service):
        self.user_service = user_service

    async def get(self, request: Request, user_id: str):
        user = self.user_service.get_user(user_id)
        return jsonable_encoder(user)

# Definimos la capa de Infraestructura
app = fastapi.FastAPI()

@app.get("/users/{user_id}")
def get_user(request: Request, user_id: str):
    user_resource = UserResource(UserService())
    return user_resource.get(request, user_id)
ตัวอย่าง: import fastapi from fastapi.encoders import jsonable_encoder from starlette.requests import Request # Definimos las interfaces del Dominio class UserService: def get_user(self, user_id): # Implementación de la lógica de negocio pass # Definimos la capa de Aplicación class UserResource: def __init__ (ตนเอง, user_service): self.user_service = user_service async def get (ตนเอง, คำขอ: คำขอ, user_id: str): user = self.user_service.get_user (user_id) ส่งคืน jsonable_encoder (ผู้ใช้) # Definimos la capa de Infraestructura app = fastapi.FastAPI() @app.get("/users/{user_id}") def get_user(คำขอ: คำขอ, user_id: str): user_resource = UserResource(UserService()) ส่งคืน user_resource.get(คำขอ, user_id)
spam fails_task lang_mismatch pii not_appropriate hate_speech sexual_content quality toxicity humor helpfulness creativity violence