From 40cbdbe301ebd37ba12448d4f9684ffe7b0bc423 Mon Sep 17 00:00:00 2001 From: Alex Lushpai Date: Thu, 20 Sep 2018 11:41:20 +0300 Subject: [PATCH] add order delivery & payments --- v1/client_test.go | 85 ++++++++++++++++++++++++++++++++++++++++++++++- v1/types.go | 45 +++++++++++++++++++++---- 2 files changed, 123 insertions(+), 7 deletions(-) diff --git a/v1/client_test.go b/v1/client_test.go index 9f9af5a..df3080a 100644 --- a/v1/client_test.go +++ b/v1/client_test.go @@ -3,17 +3,28 @@ package v1 import ( "fmt" "log" + "math/rand" "net/http" "os" "strconv" "strings" "testing" + "time" "github.com/joho/godotenv" "github.com/stretchr/testify/assert" ) +const ( + letterBytes = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + letterIdxBits = 6 // 6 bits to represent a letter index + letterIdxMask = 1<= 0; { + if remain == 0 { + cache, remain = src.Int63(), letterIdxMax + } + if idx := int(cache & letterIdxMask); idx < len(letterBytes) { + b[i] = letterBytes[idx] + i-- + } + cache >>= letterIdxBits + remain-- + } + + return string(b) +} diff --git a/v1/types.go b/v1/types.go index ec9d7a2..6279637 100644 --- a/v1/types.go +++ b/v1/types.go @@ -48,6 +48,20 @@ const ( MsgTypeCommand string = "command" MsgTypeOrder string = "order" MsgTypeProduct string = "product" + + MsgOrderStatusCodeNew = "new" + MsgOrderStatusCodeApproval = "approval" + MsgOrderStatusCodeAssembling = "assembling" + MsgOrderStatusCodeDelivery = "delivery" + MsgOrderStatusCodeComplete = "complete" + MsgOrderStatusCodeCancel = "cancel" + + MsgCurrencyRub = "rub" + MsgCurrencyUah = "uah" + MsgCurrencyByr = "byr" + MsgCurrencyKzt = "kzt" + MsgCurrencyUsd = "usd" + MsgCurrencyEur = "eur" ) // MgClient type @@ -366,12 +380,14 @@ type ( } MessageOrder struct { - Number string `json:"number"` - Url string `json:"url,omitempty"` - Date string `json:"date,omitempty"` - Cost *MessageOrderCost `json:"cost,omitempty"` - Status *MessageOrderStatus `json:"status,omitempty"` - Items []MessageOrderItem `json:"items,omitempty"` + Number string `json:"number"` + Url string `json:"url,omitempty"` + Date string `json:"date,omitempty"` + Cost *MessageOrderCost `json:"cost,omitempty"` + Status *MessageOrderStatus `json:"status,omitempty"` + Delivery *MessageOrderDelivery `json:"delivery"` + Payments []MessageOrderPayment `json:"payment"` + Items []MessageOrderItem `json:"items,omitempty"` } MessageOrderStatus struct { @@ -396,6 +412,23 @@ type ( Unit string `json:"unit"` } + MessageOrderPayment struct { + Name string `json:"name"` + Status *MessageOrderPaymentStatus `json:"status"` + Amount *MessageOrderCost `json:"amount"` + } + + MessageOrderPaymentStatus struct { + Name string `json:"name"` + Payed bool `json:"payed"` + } + + MessageOrderDelivery struct { + Name string `json:"name"` + Amount *MessageOrderCost `json:"amount"` + Address string `json:"address"` + } + UserRef struct { ID uint64 `json:"id"` Avatar string `json:"avatar"`