--- name: crud_create_handler kind: function lang: go domain: infra version: "1.0.0" purity: impure signature: "func CRUDCreateHandler(res CRUDResource, db *sql.DB) http.HandlerFunc" description: "Genera un handler HTTP POST que parsea JSON, valida campos contra la definicion del recurso, genera UUID y timestamps, inserta en SQLite y responde 201 con el registro. 400 en errores de validacion, 409 en violaciones UNIQUE." tags: [crud, create, handler, http, sqlite, uuid, validation, infra] uses_functions: [http_json_response_go_infra, http_error_response_go_infra, http_parse_body_go_infra] uses_types: [CRUDResource_go_infra, HTTPError_go_infra] returns: [] returns_optional: false error_type: "error_go_core" imports: [database/sql, fmt, net/http, strings, time, github.com/google/uuid] params: - name: res desc: "definicion del recurso con campos y validaciones" - name: db desc: "conexion *sql.DB a SQLite" output: "http.HandlerFunc que crea un registro y responde 201" tested: true tests: ["crea un registro valido y retorna 201", "valida campos required y retorna 400 si faltan", "valida min_length y max_length", "valida enum de texto", "valida min y max numericos", "retorna 409 si se viola UNIQUE"] test_file_path: "functions/infra/crud_test.go" file_path: "functions/infra/crud_create_handler.go" --- ## Ejemplo ```go handler := CRUDCreateHandler(res, db) mux.Handle("POST /api/projects", handler) // curl -X POST localhost:8080/api/projects -H 'Content-Type: application/json' -d '{"name":"mi-proyecto"}' ``` ## Notas Impura. Limita el body a 1 MiB. Los ids se generan con github.com/google/uuid (string). Los timestamps created_at y updated_at se escriben en formato RFC3339 UTC con nanosegundos. Los errores de validacion devuelven 400 con code "validation_error" y mensaje descriptivo. Errores UNIQUE de SQLite se mapean a 409.