raw_store_events store started

This commit is contained in:
2025-12-24 00:55:22 -07:00
parent cdbc08dea2
commit 3823fa7331
17 changed files with 363 additions and 73 deletions
+27 -4
View File
@@ -1,16 +1,39 @@
package etsy
import (
"encoding/json"
"fmt"
"net/http"
"time"
"ruben/inventory2/internal/domains/raw_events"
)
func NewWebhookHandler() http.Handler {
func NewWebhookHandler(db *raw_events.Store) http.Handler {
mux := http.NewServeMux()
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/plain")
w.Write([]byte(fmt.Sprintf("received etsy webhook call: %s %s\n", r.Method, r.URL)))
mux.HandleFunc("POST /test", func(w http.ResponseWriter, r *http.Request) {
var body json.RawMessage
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
http.Error(w, "Failed to decode body as json: "+err.Error(), 500)
return
}
ts := time.Now().UTC()
err := db.Save(r.Context(), &raw_events.Event{
Platform: "etsy",
StoreID: "test-store-1",
EventID: fmt.Sprint(ts.Unix()),
EventTimestamp: ts,
Payload: body,
})
if err != nil {
http.Error(w, "Error occurred saving the body as the event payload: "+err.Error(), 500)
return
}
w.WriteHeader(201)
})
return mux