package handlers import ( "encoding/json" "io/ioutil" "log" "time" "github.com/gin-gonic/gin" real "github.com/m3tam3re/real/supplierapi/orders" "github.com/m3tam3re/ordercollect/internal/billbee" "github.com/m3tam3re/ordercollect/internal/models" ) func Addorders(ctx *gin.Context) { user := ctx.MustGet(gin.AuthUserKey).(string) log.Println("User: ", user) var body []models.Wk24order data, err := ioutil.ReadAll(ctx.Request.Body) if err != nil { log.Panicf("error reading request body: %s", err) } err = json.Unmarshal(data, &body) if err != nil { log.Print(err) } var raw json.RawMessage err = json.Unmarshal(data, &raw) if err != nil { log.Println(err) } log.Println("JSON: ", string(raw)) if err != nil { log.Println(err) } for _, order := range body { err := billbee.Wk24ToBillbee(order) time.Sleep(time.Second * 2) if err != nil { log.Println(err) } //TODO make sure the order is stored to Billbee } ctx.JSON(200, gin.H{ "result": "success", }) } func ConfirmRealShipment(ctx *gin.Context) { ro, err := real.GetOrder(ctx.Query("orderid")) log.Println(ro) if err != nil { log.Println(err) } // http://localhost:8080/real/confirmshipment?orderid=6193059&carrier=DPD&trackingid=01096812392974 for _, u := range ro.Units { if ctx.Query("carrier") == "DPD" || ctx.Query("carrier") == "dpd" { u.ShipmentData.Carrier = "dpd" } else { u.ShipmentData.Carrier = "other" } if ctx.Query("trackingid") == "" { u.ShipmentData.TrackingNumber = "nicht vorhanden" } u.ShipmentData.DeliveryNoteNumber = "LS" + ctx.Query("orderid") u.ShipmentData.TrackingNumber = ctx.Query("trackingid") } err = ro.Send() if err != nil { log.Println(err) // TODO ctx.JSON(500, gin.H{ "result": err, }) return } ctx.JSON(200, gin.H{ "result": "success", }) }