Deretardify the fucking events
Good job claude complicate everything why don't you
This commit is contained in:
30
api.go
30
api.go
@@ -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)
|
||||
|
Reference in New Issue
Block a user