Deretardify the fucking events

Good job claude complicate everything why don't you
This commit is contained in:
2025-09-29 09:36:42 +02:00
parent e9047ef2cb
commit 5f21d144c0
5 changed files with 108 additions and 95 deletions

30
api.go
View File

@@ -9,7 +9,7 @@ import (
// setupAPIRoutes sets up the event store API routes
func setupAPIRoutes(app core.App, eventStore *SimpleEventStore) {
app.OnServe().BindFunc(func(se *core.ServeEvent) error {
// JSON Patch endpoint using PATCH method
// JSON Patch endpoint using PATCH method - ONE OPERATION PER REQUEST
se.Router.PATCH("/api/collections/{collection}/items/{itemId}", func(e *core.RequestEvent) error {
collection := e.Request.PathValue("collection")
itemID := e.Request.PathValue("itemId")
@@ -18,16 +18,24 @@ func setupAPIRoutes(app core.App, eventStore *SimpleEventStore) {
return e.BadRequestError("Collection and itemId are required", nil)
}
var patches []PatchOperation
if err := e.BindBody(&patches); err != nil {
return e.BadRequestError("Failed to parse JSON Patch data", err)
var operation struct {
Op string `json:"op"`
Path string `json:"path"`
Value string `json:"value"`
From string `json:"from"`
}
if err := e.BindBody(&operation); err != nil {
return e.BadRequestError("Failed to parse operation data", err)
}
// Create event with patches
// Create event with single operation
incomingEvent := &Event{
ItemID: itemID,
ItemID: itemID,
Collection: collection,
Patches: patches,
Operation: operation.Op,
Path: operation.Path,
Value: operation.Value,
From: operation.From,
}
// Process the event
@@ -47,8 +55,8 @@ func setupAPIRoutes(app core.App, eventStore *SimpleEventStore) {
}
// Validate required fields
if incomingEvent.ItemID == "" || incomingEvent.Collection == "" || len(incomingEvent.Patches) == 0 {
return e.BadRequestError("Missing required fields: item_id, collection, patches", nil)
if incomingEvent.ItemID == "" || incomingEvent.Collection == "" || incomingEvent.Operation == "" {
return e.BadRequestError("Missing required fields: item_id, collection, operation", nil)
}
// Process the event
@@ -134,8 +142,8 @@ func setupAPIRoutes(app core.App, eventStore *SimpleEventStore) {
processedEvents := make([]Event, 0, len(events))
for _, incomingEvent := range events {
// Validate required fields
if incomingEvent.ItemID == "" || incomingEvent.Collection == "" || len(incomingEvent.Patches) == 0 {
return e.BadRequestError("Missing required fields in event: item_id, collection, patches", nil)
if incomingEvent.ItemID == "" || incomingEvent.Collection == "" || incomingEvent.Operation == "" {
return e.BadRequestError("Missing required fields in event: item_id, collection, operation", nil)
}
processedEvent, err := eventStore.ProcessEvent(&incomingEvent)