removed intermediate /internal directory
This commit is contained in:
@@ -0,0 +1,43 @@
|
||||
package wix
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
"ruben/inventory2/domains/raw_events"
|
||||
"ruben/inventory2/logging"
|
||||
"ruben/inventory2/server/response"
|
||||
)
|
||||
|
||||
func Routes(
|
||||
r *gin.RouterGroup,
|
||||
logger *logging.Logger,
|
||||
db *raw_events.Store,
|
||||
) {
|
||||
r.POST("/test", response.Handler(func(c *gin.Context) (response.Response, error) {
|
||||
r := c.Request
|
||||
|
||||
var body json.RawMessage
|
||||
if err := json.NewDecoder(r.Body).Decode(&body); err != nil {
|
||||
return nil, fmt.Errorf("failed to decode body as json: %w", err)
|
||||
}
|
||||
|
||||
ts := time.Now().UTC()
|
||||
|
||||
err := db.Save(r.Context(), &raw_events.Event{
|
||||
Platform: "wix",
|
||||
StoreID: "test-store-1",
|
||||
EventID: fmt.Sprint(ts.Unix()),
|
||||
EventTimestamp: ts,
|
||||
Payload: body,
|
||||
})
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("error occurred saving the body as the event payload: %w", err)
|
||||
}
|
||||
|
||||
return response.Status(201), nil
|
||||
}))
|
||||
}
|
||||
Reference in New Issue
Block a user