Renames: - platform/ → workspace-server/ (Go module path stays as "platform" for external dep compat — will update after plugin module republish) - workspace-template/ → workspace/ Removed (moved to separate repos or deleted): - PLAN.md — internal roadmap (move to private project board) - HANDOFF.md, AGENTS.md — one-time internal session docs - .claude/ — gitignored entirely (local agent config) - infra/cloudflare-worker/ → Molecule-AI/molecule-tenant-proxy - org-templates/molecule-dev/ → standalone template repo - .mcp-eval/ → molecule-mcp-server repo - test-results/ — ephemeral, gitignored Security scrubbing: - Cloudflare account/zone/KV IDs → placeholders - Real EC2 IPs → <EC2_IP> in all docs - CF token prefix, Neon project ID, Fly app names → redacted - Langfuse dev credentials → parameterized - Personal runner username/machine name → generic Community files: - CONTRIBUTING.md — build, test, branch conventions - CODE_OF_CONDUCT.md — Contributor Covenant 2.1 All Dockerfiles, CI workflows, docker-compose, railway.toml, render.yaml, README, CLAUDE.md updated for new directory names. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
92 lines
2.2 KiB
Go
92 lines
2.2 KiB
Go
package handlers
|
|
|
|
import (
|
|
"encoding/json"
|
|
"log"
|
|
"net/http"
|
|
"time"
|
|
|
|
"github.com/Molecule-AI/molecule-monorepo/platform/internal/db"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
type EventsHandler struct{}
|
|
|
|
func NewEventsHandler() *EventsHandler {
|
|
return &EventsHandler{}
|
|
}
|
|
|
|
// List handles GET /events
|
|
func (h *EventsHandler) List(c *gin.Context) {
|
|
rows, err := db.DB.QueryContext(c.Request.Context(), `
|
|
SELECT id, event_type, workspace_id, payload, created_at
|
|
FROM structure_events
|
|
ORDER BY created_at DESC
|
|
LIMIT 100
|
|
`)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "query failed"})
|
|
return
|
|
}
|
|
defer rows.Close()
|
|
|
|
events := make([]map[string]interface{}, 0)
|
|
for rows.Next() {
|
|
var id, eventType string
|
|
var workspaceID *string
|
|
var payload []byte
|
|
var createdAt time.Time
|
|
|
|
if err := rows.Scan(&id, &eventType, &workspaceID, &payload, &createdAt); err != nil {
|
|
log.Printf("Events scan error: %v", err)
|
|
continue
|
|
}
|
|
events = append(events, map[string]interface{}{
|
|
"id": id,
|
|
"event_type": eventType,
|
|
"workspace_id": workspaceID,
|
|
"payload": json.RawMessage(payload),
|
|
"created_at": createdAt,
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, events)
|
|
}
|
|
|
|
// ListByWorkspace handles GET /events/:workspaceId
|
|
func (h *EventsHandler) ListByWorkspace(c *gin.Context) {
|
|
workspaceID := c.Param("workspaceId")
|
|
|
|
rows, err := db.DB.QueryContext(c.Request.Context(), `
|
|
SELECT id, event_type, workspace_id, payload, created_at
|
|
FROM structure_events
|
|
WHERE workspace_id = $1
|
|
ORDER BY created_at DESC
|
|
LIMIT 100
|
|
`, workspaceID)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": "query failed"})
|
|
return
|
|
}
|
|
defer rows.Close()
|
|
|
|
events := make([]map[string]interface{}, 0)
|
|
for rows.Next() {
|
|
var id, eventType string
|
|
var wsID *string
|
|
var payload []byte
|
|
var createdAt time.Time
|
|
|
|
if err := rows.Scan(&id, &eventType, &wsID, &payload, &createdAt); err != nil {
|
|
continue
|
|
}
|
|
events = append(events, map[string]interface{}{
|
|
"id": id,
|
|
"event_type": eventType,
|
|
"workspace_id": wsID,
|
|
"payload": json.RawMessage(payload),
|
|
"created_at": createdAt,
|
|
})
|
|
}
|
|
c.JSON(http.StatusOK, events)
|
|
}
|