Compare commits
13 Commits
refactor/h
...
db918730d5
| Author | SHA1 | Date | |
|---|---|---|---|
| db918730d5 | |||
| 8ecad3060f | |||
|
|
c060680768 | ||
|
|
15089862d5 | ||
|
|
cdb0241c8a | ||
|
|
07a7ec5781 | ||
|
|
fa89670553 | ||
|
|
9ab0c08e79 | ||
| 8682daf481 | |||
|
|
8c2bcf5e75 | ||
|
|
47adb12112 | ||
|
|
4835041f14 | ||
| 104f9fbb4c |
@@ -47,6 +47,9 @@ jobs:
|
|||||||
docker push registry.knatofs.se/go-cart-actor-amd64:${{ needs.Metadata.outputs.version }}
|
docker push registry.knatofs.se/go-cart-actor-amd64:${{ needs.Metadata.outputs.version }}
|
||||||
- name: Apply deployment manifests
|
- name: Apply deployment manifests
|
||||||
run: kubectl apply -f deployment/deployment.yaml -n cart
|
run: kubectl apply -f deployment/deployment.yaml -n cart
|
||||||
|
- name: Rollout amd64 backoffice deployment
|
||||||
|
run: |
|
||||||
|
kubectl rollout restart deployment/cart-backoffice-x86 -n cart
|
||||||
- name: Rollout amd64 deployment (pin to version)
|
- name: Rollout amd64 deployment (pin to version)
|
||||||
run: |
|
run: |
|
||||||
kubectl set image deployment/cart-actor-x86 -n cart cart-actor-amd64=registry.knatofs.se/go-cart-actor-amd64:${{ needs.Metadata.outputs.version }}
|
kubectl set image deployment/cart-actor-x86 -n cart cart-actor-amd64=registry.knatofs.se/go-cart-actor-amd64:${{ needs.Metadata.outputs.version }}
|
||||||
|
|||||||
@@ -59,6 +59,13 @@ RUN --mount=type=cache,target=/go/build-cache \
|
|||||||
-X main.BuildDate=${BUILD_DATE}" \
|
-X main.BuildDate=${BUILD_DATE}" \
|
||||||
-o /out/go-cart-actor ./cmd/cart
|
-o /out/go-cart-actor ./cmd/cart
|
||||||
|
|
||||||
|
RUN --mount=type=cache,target=/go/build-cache \
|
||||||
|
go build -trimpath -ldflags="-s -w \
|
||||||
|
-X main.Version=${VERSION} \
|
||||||
|
-X main.GitCommit=${GIT_COMMIT} \
|
||||||
|
-X main.BuildDate=${BUILD_DATE}" \
|
||||||
|
-o /out/go-cart-backoffice ./cmd/backoffice
|
||||||
|
|
||||||
############################
|
############################
|
||||||
# Runtime Stage
|
# Runtime Stage
|
||||||
############################
|
############################
|
||||||
@@ -67,6 +74,7 @@ FROM gcr.io/distroless/static-debian12:nonroot AS runtime
|
|||||||
WORKDIR /
|
WORKDIR /
|
||||||
|
|
||||||
COPY --from=build /out/go-cart-actor /go-cart-actor
|
COPY --from=build /out/go-cart-actor /go-cart-actor
|
||||||
|
COPY --from=build /out/go-cart-backoffice /go-cart-backoffice
|
||||||
|
|
||||||
# Document (not expose forcibly) typical ports: 8080 (HTTP), 1337 (gRPC)
|
# Document (not expose forcibly) typical ports: 8080 (HTTP), 1337 (gRPC)
|
||||||
EXPOSE 8080 1337
|
EXPOSE 8080 1337
|
||||||
|
|||||||
31
README.md
31
README.md
@@ -1,36 +1,5 @@
|
|||||||
# Go Cart Actor
|
# Go Cart Actor
|
||||||
|
|
||||||
## Migration Notes (Ring-based Ownership Transition)
|
|
||||||
|
|
||||||
This release removes the legacy ConfirmOwner ownership negotiation RPC in favor of deterministic ownership via the consistent hashing ring.
|
|
||||||
|
|
||||||
Summary of changes:
|
|
||||||
- ConfirmOwner RPC removed from the ControlPlane service.
|
|
||||||
- OwnerChangeRequest message removed (was only used by ConfirmOwner).
|
|
||||||
- OwnerChangeAck retained solely as the response type for the Closing RPC.
|
|
||||||
- SyncedPool now relies exclusively on the ring for ownership (no quorum negotiation).
|
|
||||||
- Remote proxy creation includes a bounded readiness retry to reduce first-call failures.
|
|
||||||
- New Prometheus ring metrics:
|
|
||||||
- cart_ring_epoch
|
|
||||||
- cart_ring_hosts
|
|
||||||
- cart_ring_vnodes
|
|
||||||
- cart_ring_host_share{host}
|
|
||||||
- cart_ring_lookup_local_total
|
|
||||||
- cart_ring_lookup_remote_total
|
|
||||||
|
|
||||||
Action required for consumers:
|
|
||||||
1. Regenerate protobuf code after pulling (requires protoc-gen-go and protoc-gen-go-grpc installed).
|
|
||||||
2. Remove any client code or automation invoking ConfirmOwner (calls will now return UNIMPLEMENTED if using stale generated stubs).
|
|
||||||
3. Update monitoring/alerts that referenced ConfirmOwner or ownership quorum failures—use ring metrics instead.
|
|
||||||
4. If you previously interpreted “ownership flapping” via ConfirmOwner logs, now check for:
|
|
||||||
- Rapid changes in ring epoch (cart_ring_epoch)
|
|
||||||
- Host churn (cart_ring_hosts)
|
|
||||||
- Imbalance in vnode distribution (cart_ring_host_share)
|
|
||||||
|
|
||||||
No data migration is necessary; cart IDs and grain state are unaffected.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
A distributed cart management system using the actor model pattern.
|
A distributed cart management system using the actor model pattern.
|
||||||
|
|
||||||
## Prerequisites
|
## Prerequisites
|
||||||
|
|||||||
207
cmd/backoffice/fileserver.go
Normal file
207
cmd/backoffice/fileserver.go
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"encoding/json"
|
||||||
|
"errors"
|
||||||
|
"fmt"
|
||||||
|
"io/fs"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"sort"
|
||||||
|
"strconv"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/actor"
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
|
)
|
||||||
|
|
||||||
|
type FileServer struct {
|
||||||
|
// Define fields here
|
||||||
|
dataDir string
|
||||||
|
storage actor.LogStorage[cart.CartGrain]
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewFileServer(dataDir string, storage actor.LogStorage[cart.CartGrain]) *FileServer {
|
||||||
|
return &FileServer{
|
||||||
|
dataDir: dataDir,
|
||||||
|
storage: storage,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func isValidId(id string) (uint64, bool) {
|
||||||
|
if nr, err := strconv.ParseUint(id, 10, 64); err == nil {
|
||||||
|
return nr, true
|
||||||
|
}
|
||||||
|
if nr, ok := cart.ParseCartId(id); ok {
|
||||||
|
return uint64(nr), true
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
func isValidFileId(name string) (uint64, bool) {
|
||||||
|
|
||||||
|
parts := strings.Split(name, ".")
|
||||||
|
if len(parts) > 1 && parts[1] == "events" {
|
||||||
|
idStr := parts[0]
|
||||||
|
|
||||||
|
return isValidId(idStr)
|
||||||
|
}
|
||||||
|
return 0, false
|
||||||
|
}
|
||||||
|
|
||||||
|
// func AccessTime(info os.FileInfo) (time.Time, bool) {
|
||||||
|
// switch stat := info.Sys().(type) {
|
||||||
|
// case *syscall.Stat_t:
|
||||||
|
// // Linux: Atim; macOS/BSD: Atimespec
|
||||||
|
// // Use reflection or build tags if naming differs.
|
||||||
|
// // Linux:
|
||||||
|
// if stat.Atim.Sec != 0 || stat.Atim.Nsec != 0 {
|
||||||
|
// return time.Unix(int64(stat.Atim.Sec), int64(stat.Atim.Nsec)), true
|
||||||
|
// }
|
||||||
|
// // macOS/BSD example (uncomment if needed):
|
||||||
|
// //return time.Unix(int64(stat.Atimespec.Sec), int64(stat.Atimespec.Nsec)), true
|
||||||
|
// }
|
||||||
|
// return time.Time{}, false
|
||||||
|
// }
|
||||||
|
|
||||||
|
func appendFileInfo(info fs.FileInfo, out *CartFileInfo) *CartFileInfo {
|
||||||
|
//sys := info.Sys()
|
||||||
|
//fmt.Printf("sys type %T", sys)
|
||||||
|
out.Size = info.Size()
|
||||||
|
out.Modified = info.ModTime()
|
||||||
|
//out.Accessed, _ = AccessTime(info)
|
||||||
|
return out
|
||||||
|
}
|
||||||
|
|
||||||
|
// var cartFileRe = regexp.MustCompile(`^(\d+)\.events\.log$`)
|
||||||
|
|
||||||
|
func listCartFiles(dir string) ([]*CartFileInfo, error) {
|
||||||
|
entries, err := os.ReadDir(dir)
|
||||||
|
if err != nil {
|
||||||
|
if errors.Is(err, os.ErrNotExist) {
|
||||||
|
return []*CartFileInfo{}, nil
|
||||||
|
}
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
out := make([]*CartFileInfo, 0)
|
||||||
|
for _, e := range entries {
|
||||||
|
if e.IsDir() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
id, valid := isValidFileId(e.Name())
|
||||||
|
if !valid {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := e.Info()
|
||||||
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
info.Sys()
|
||||||
|
out = append(out, appendFileInfo(info, &CartFileInfo{
|
||||||
|
ID: fmt.Sprintf("%d", id),
|
||||||
|
CartId: cart.CartId(id),
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
return out, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func readRawLogLines(path string) ([]json.RawMessage, error) {
|
||||||
|
fh, err := os.Open(path)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
defer fh.Close()
|
||||||
|
lines := make([]json.RawMessage, 0, 64)
|
||||||
|
s := bufio.NewScanner(fh)
|
||||||
|
// increase buffer to handle larger JSON lines
|
||||||
|
buf := make([]byte, 0, 1024*1024)
|
||||||
|
s.Buffer(buf, 1024*1024)
|
||||||
|
for s.Scan() {
|
||||||
|
line := s.Bytes()
|
||||||
|
if line == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
lines = append(lines, line)
|
||||||
|
}
|
||||||
|
if err := s.Err(); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return lines, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeJSON(w http.ResponseWriter, status int, v any) {
|
||||||
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
w.Header().Set("Cache-Control", "no-cache")
|
||||||
|
w.WriteHeader(status)
|
||||||
|
_ = json.NewEncoder(w).Encode(v)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs *FileServer) CartsHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
list, err := listCartFiles(fs.dataDir)
|
||||||
|
if err != nil {
|
||||||
|
writeJSON(w, http.StatusInternalServerError, map[string]string{"error": err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// sort by modified desc
|
||||||
|
sort.Slice(list, func(i, j int) bool { return list[i].Modified.After(list[j].Modified) })
|
||||||
|
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"count": len(list),
|
||||||
|
"carts": list,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
type JsonError struct {
|
||||||
|
Error string `json:"error"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (fs *FileServer) CartHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
|
idStr := r.PathValue("id")
|
||||||
|
if idStr == "" {
|
||||||
|
writeJSON(w, http.StatusBadRequest, JsonError{Error: "missing id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
id, ok := isValidId(idStr)
|
||||||
|
if !ok {
|
||||||
|
writeJSON(w, http.StatusBadRequest, JsonError{Error: "invalid id"})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// reconstruct state from event log if present
|
||||||
|
grain := cart.NewCartGrain(id, time.Now())
|
||||||
|
|
||||||
|
err := fs.storage.LoadEvents(id, grain)
|
||||||
|
if err != nil {
|
||||||
|
writeJSON(w, http.StatusInternalServerError, JsonError{Error: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
path := filepath.Join(fs.dataDir, fmt.Sprintf("%d.events.log", id))
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if err != nil && errors.Is(err, os.ErrNotExist) {
|
||||||
|
writeJSON(w, http.StatusNotFound, JsonError{Error: "cart not found"})
|
||||||
|
return
|
||||||
|
} else if err != nil {
|
||||||
|
writeJSON(w, http.StatusInternalServerError, JsonError{Error: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
lines, err := readRawLogLines(path)
|
||||||
|
if err != nil {
|
||||||
|
writeJSON(w, http.StatusInternalServerError, JsonError{Error: err.Error()})
|
||||||
|
return
|
||||||
|
}
|
||||||
|
writeJSON(w, http.StatusOK, map[string]any{
|
||||||
|
"id": id,
|
||||||
|
"cartId": cart.CartId(id).String(),
|
||||||
|
"state": grain,
|
||||||
|
"mutations": lines,
|
||||||
|
"meta": map[string]any{
|
||||||
|
"size": info.Size(),
|
||||||
|
"modified": info.ModTime(),
|
||||||
|
"path": path,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
}
|
||||||
89
cmd/backoffice/fileserver_test.go
Normal file
89
cmd/backoffice/fileserver_test.go
Normal file
@@ -0,0 +1,89 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"math/rand"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
|
)
|
||||||
|
|
||||||
|
// TestAppendFileInfoRandomProjectFile picks a random existing .go source file in the
|
||||||
|
// repository (from a small curated list to keep the test hermetic) and verifies
|
||||||
|
// that appendFileInfo populates Size, Modified and System without mutating the
|
||||||
|
// identity fields (ID, CartId). The randomness is only to satisfy the requirement
|
||||||
|
// of using "a random project file"; the test behavior is deterministic enough for
|
||||||
|
// CI because all chosen files are expected to exist.
|
||||||
|
func TestAppendFileInfoRandomProjectFile(t *testing.T) {
|
||||||
|
candidates := []string{
|
||||||
|
filepath.FromSlash("../../pkg/cart/cart_id.go"),
|
||||||
|
filepath.FromSlash("../../pkg/actor/grain.go"),
|
||||||
|
filepath.FromSlash("../../cmd/cart/main.go"),
|
||||||
|
}
|
||||||
|
// Pick one at random.
|
||||||
|
rand.Seed(time.Now().UnixNano())
|
||||||
|
path := candidates[rand.Intn(len(candidates))]
|
||||||
|
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("stat failed for %s: %v", path, err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pre-populate a CartFileInfo with identity fields.
|
||||||
|
origID := "test-id"
|
||||||
|
origCartId := cart.CartId(12345)
|
||||||
|
cf := &CartFileInfo{ID: origID, CartId: origCartId}
|
||||||
|
|
||||||
|
// Call function under test.
|
||||||
|
got := appendFileInfo(info, cf)
|
||||||
|
|
||||||
|
if got != cf {
|
||||||
|
t.Fatalf("appendFileInfo should return the same pointer instance")
|
||||||
|
}
|
||||||
|
|
||||||
|
if cf.ID != origID {
|
||||||
|
t.Fatalf("ID mutated: expected %q got %q", origID, cf.ID)
|
||||||
|
}
|
||||||
|
if cf.CartId != origCartId {
|
||||||
|
t.Fatalf("CartId mutated: expected %v got %v", origCartId, cf.CartId)
|
||||||
|
}
|
||||||
|
|
||||||
|
if cf.Size != info.Size() {
|
||||||
|
t.Fatalf("Size mismatch: expected %d got %d", info.Size(), cf.Size)
|
||||||
|
}
|
||||||
|
|
||||||
|
mod := info.ModTime()
|
||||||
|
// Allow small clock skew / coarse timestamp truncation.
|
||||||
|
if cf.Modified.Before(mod.Add(-2*time.Second)) || cf.Modified.After(mod.Add(2*time.Second)) {
|
||||||
|
t.Fatalf("Modified not within expected range: want ~%v got %v", mod, cf.Modified)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// TestAppendFileInfoTempFile creates a temporary file to ensure Size and Modified
|
||||||
|
// are updated for a freshly written file with known content length.
|
||||||
|
func TestAppendFileInfoTempFile(t *testing.T) {
|
||||||
|
dir := t.TempDir()
|
||||||
|
path := filepath.Join(dir, "temp.events.log")
|
||||||
|
content := []byte("hello world\nanother line\n")
|
||||||
|
if err := os.WriteFile(path, content, 0644); err != nil {
|
||||||
|
t.Fatalf("write temp file failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
info, err := os.Stat(path)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("stat temp file failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
cf := &CartFileInfo{ID: "temp", CartId: cart.CartId(0)}
|
||||||
|
appendFileInfo(info, cf)
|
||||||
|
|
||||||
|
if cf.Size != int64(len(content)) {
|
||||||
|
t.Fatalf("expected Size %d got %d", len(content), cf.Size)
|
||||||
|
}
|
||||||
|
if cf.Modified.IsZero() {
|
||||||
|
t.Fatalf("Modified should be set")
|
||||||
|
}
|
||||||
|
}
|
||||||
248
cmd/backoffice/hub.go
Normal file
248
cmd/backoffice/hub.go
Normal file
@@ -0,0 +1,248 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"bufio"
|
||||||
|
"crypto/sha1"
|
||||||
|
"encoding/base64"
|
||||||
|
"encoding/binary"
|
||||||
|
"io"
|
||||||
|
"net"
|
||||||
|
"net/http"
|
||||||
|
"strings"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
// Hub manages websocket clients and broadcasts messages to them.
|
||||||
|
type Hub struct {
|
||||||
|
register chan *Client
|
||||||
|
unregister chan *Client
|
||||||
|
broadcast chan []byte
|
||||||
|
clients map[*Client]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
// Client represents a single websocket client connection.
|
||||||
|
type Client struct {
|
||||||
|
hub *Hub
|
||||||
|
conn net.Conn
|
||||||
|
send chan []byte
|
||||||
|
}
|
||||||
|
|
||||||
|
// NewHub constructs a new Hub instance.
|
||||||
|
func NewHub() *Hub {
|
||||||
|
return &Hub{
|
||||||
|
register: make(chan *Client),
|
||||||
|
unregister: make(chan *Client),
|
||||||
|
broadcast: make(chan []byte, 1024),
|
||||||
|
clients: make(map[*Client]bool),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Run starts the hub event loop.
|
||||||
|
func (h *Hub) Run() {
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case c := <-h.register:
|
||||||
|
h.clients[c] = true
|
||||||
|
case c := <-h.unregister:
|
||||||
|
if _, ok := h.clients[c]; ok {
|
||||||
|
delete(h.clients, c)
|
||||||
|
close(c.send)
|
||||||
|
_ = c.conn.Close()
|
||||||
|
}
|
||||||
|
case msg := <-h.broadcast:
|
||||||
|
for c := range h.clients {
|
||||||
|
select {
|
||||||
|
case c.send <- msg:
|
||||||
|
default:
|
||||||
|
// Client is slow or dead; drop it.
|
||||||
|
delete(h.clients, c)
|
||||||
|
close(c.send)
|
||||||
|
_ = c.conn.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// computeAccept computes the Sec-WebSocket-Accept header value.
|
||||||
|
func computeAccept(key string) string {
|
||||||
|
const magic = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
||||||
|
h := sha1.New()
|
||||||
|
h.Write([]byte(key + magic))
|
||||||
|
return base64.StdEncoding.EncodeToString(h.Sum(nil))
|
||||||
|
}
|
||||||
|
|
||||||
|
// ServeWS upgrades the HTTP request to a WebSocket connection and registers a client.
|
||||||
|
func (h *Hub) ServeWS(w http.ResponseWriter, r *http.Request) {
|
||||||
|
if !strings.Contains(strings.ToLower(r.Header.Get("Connection")), "upgrade") || strings.ToLower(r.Header.Get("Upgrade")) != "websocket" {
|
||||||
|
http.Error(w, "upgrade required", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
key := r.Header.Get("Sec-WebSocket-Key")
|
||||||
|
if key == "" {
|
||||||
|
http.Error(w, "missing Sec-WebSocket-Key", http.StatusBadRequest)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
accept := computeAccept(key)
|
||||||
|
|
||||||
|
hj, ok := w.(http.Hijacker)
|
||||||
|
if !ok {
|
||||||
|
http.Error(w, "websocket not supported", http.StatusInternalServerError)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
conn, buf, err := hj.Hijack()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write the upgrade response
|
||||||
|
response := "HTTP/1.1 101 Switching Protocols\r\n" +
|
||||||
|
"Upgrade: websocket\r\n" +
|
||||||
|
"Connection: Upgrade\r\n" +
|
||||||
|
"Sec-WebSocket-Accept: " + accept + "\r\n" +
|
||||||
|
"\r\n"
|
||||||
|
if _, err := buf.WriteString(response); err != nil {
|
||||||
|
_ = conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := buf.Flush(); err != nil {
|
||||||
|
_ = conn.Close()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
client := &Client{
|
||||||
|
hub: h,
|
||||||
|
conn: conn,
|
||||||
|
send: make(chan []byte, 256),
|
||||||
|
}
|
||||||
|
h.register <- client
|
||||||
|
go client.writePump()
|
||||||
|
go client.readPump()
|
||||||
|
}
|
||||||
|
|
||||||
|
// writeWSFrame writes a single WebSocket frame to the writer.
|
||||||
|
func writeWSFrame(w io.Writer, opcode byte, payload []byte) error {
|
||||||
|
// FIN set, opcode as provided
|
||||||
|
header := []byte{0x80 | (opcode & 0x0F)}
|
||||||
|
l := len(payload)
|
||||||
|
switch {
|
||||||
|
case l < 126:
|
||||||
|
header = append(header, byte(l))
|
||||||
|
case l <= 65535:
|
||||||
|
ext := make([]byte, 2)
|
||||||
|
binary.BigEndian.PutUint16(ext, uint16(l))
|
||||||
|
header = append(header, 126)
|
||||||
|
header = append(header, ext...)
|
||||||
|
default:
|
||||||
|
ext := make([]byte, 8)
|
||||||
|
binary.BigEndian.PutUint64(ext, uint64(l))
|
||||||
|
header = append(header, 127)
|
||||||
|
header = append(header, ext...)
|
||||||
|
}
|
||||||
|
if _, err := w.Write(header); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
if l > 0 {
|
||||||
|
if _, err := w.Write(payload); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// readPump handles control frames from the client and discards other incoming frames.
|
||||||
|
// This server is broadcast-only to clients.
|
||||||
|
func (c *Client) readPump() {
|
||||||
|
defer func() {
|
||||||
|
c.hub.unregister <- c
|
||||||
|
}()
|
||||||
|
reader := bufio.NewReader(c.conn)
|
||||||
|
for {
|
||||||
|
// Read first two bytes
|
||||||
|
b1, err := reader.ReadByte()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
b2, err := reader.ReadByte()
|
||||||
|
if err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
opcode := b1 & 0x0F
|
||||||
|
masked := (b2 & 0x80) != 0
|
||||||
|
length := int64(b2 & 0x7F)
|
||||||
|
if length == 126 {
|
||||||
|
ext := make([]byte, 2)
|
||||||
|
if _, err := io.ReadFull(reader, ext); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
length = int64(binary.BigEndian.Uint16(ext))
|
||||||
|
} else if length == 127 {
|
||||||
|
ext := make([]byte, 8)
|
||||||
|
if _, err := io.ReadFull(reader, ext); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
length = int64(binary.BigEndian.Uint64(ext))
|
||||||
|
}
|
||||||
|
var maskKey [4]byte
|
||||||
|
if masked {
|
||||||
|
if _, err := io.ReadFull(reader, maskKey[:]); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Handle Ping -> Pong
|
||||||
|
if opcode == 0x9 && length <= 125 {
|
||||||
|
payload := make([]byte, length)
|
||||||
|
if _, err := io.ReadFull(reader, payload); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// Unmask if masked
|
||||||
|
if masked {
|
||||||
|
for i := int64(0); i < length; i++ {
|
||||||
|
payload[i] ^= maskKey[i%4]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_ = writeWSFrame(c.conn, 0xA, payload) // best-effort pong
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close frame
|
||||||
|
if opcode == 0x8 {
|
||||||
|
// Drain payload if any, then exit
|
||||||
|
if _, err := io.CopyN(io.Discard, reader, length); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// For other frames, just discard payload
|
||||||
|
if _, err := io.CopyN(io.Discard, reader, length); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// writePump sends queued messages to the client and pings periodically to keep the connection alive.
|
||||||
|
func (c *Client) writePump() {
|
||||||
|
ticker := time.NewTicker(30 * time.Second)
|
||||||
|
defer func() {
|
||||||
|
ticker.Stop()
|
||||||
|
_ = c.conn.Close()
|
||||||
|
}()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case msg, ok := <-c.send:
|
||||||
|
if !ok {
|
||||||
|
// try to send close frame
|
||||||
|
_ = writeWSFrame(c.conn, 0x8, nil)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if err := writeWSFrame(c.conn, 0x1, msg); err != nil {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
case <-ticker.C:
|
||||||
|
// Send a ping to keep connections alive behind proxies
|
||||||
|
_ = writeWSFrame(c.conn, 0x9, []byte("ping"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,148 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
func main() {
|
import (
|
||||||
// Your code here
|
"context"
|
||||||
|
"errors"
|
||||||
|
"log"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
actor "git.tornberg.me/go-cart-actor/pkg/actor"
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
|
"github.com/matst80/slask-finder/pkg/messaging"
|
||||||
|
amqp "github.com/rabbitmq/amqp091-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type CartFileInfo struct {
|
||||||
|
ID string `json:"id"`
|
||||||
|
CartId cart.CartId `json:"cartId"`
|
||||||
|
Size int64 `json:"size"`
|
||||||
|
Modified time.Time `json:"modified"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func envOrDefault(key, def string) string {
|
||||||
|
if v := os.Getenv(key); v != "" {
|
||||||
|
return v
|
||||||
|
}
|
||||||
|
return def
|
||||||
|
}
|
||||||
|
|
||||||
|
func startMutationConsumer(ctx context.Context, conn *amqp.Connection, hub *Hub) error {
|
||||||
|
ch, err := conn.Channel()
|
||||||
|
if err != nil {
|
||||||
|
_ = conn.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
msgs, err := messaging.DeclareBindAndConsume(ch, "cart", "mutation")
|
||||||
|
if err != nil {
|
||||||
|
_ = ch.Close()
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
defer ch.Close()
|
||||||
|
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-ctx.Done():
|
||||||
|
return
|
||||||
|
case m, ok := <-msgs:
|
||||||
|
if !ok {
|
||||||
|
log.Fatalf("connection closed")
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Log and broadcast to all websocket clients
|
||||||
|
log.Printf("mutation event: %s", string(m.Body))
|
||||||
|
|
||||||
|
if hub != nil {
|
||||||
|
select {
|
||||||
|
case hub.broadcast <- m.Body:
|
||||||
|
default:
|
||||||
|
// if hub queue is full, drop to avoid blocking
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if err := m.Ack(false); err != nil {
|
||||||
|
log.Printf("error acknowledging message: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}()
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
dataDir := envOrDefault("DATA_DIR", "data")
|
||||||
|
addr := envOrDefault("ADDR", ":8080")
|
||||||
|
amqpURL := os.Getenv("AMQP_URL")
|
||||||
|
|
||||||
|
_ = os.MkdirAll(dataDir, 0755)
|
||||||
|
|
||||||
|
reg := cart.NewCartMultationRegistry()
|
||||||
|
diskStorage := actor.NewDiskStorage[cart.CartGrain](dataDir, reg)
|
||||||
|
|
||||||
|
fs := NewFileServer(dataDir, diskStorage)
|
||||||
|
|
||||||
|
hub := NewHub()
|
||||||
|
go hub.Run()
|
||||||
|
|
||||||
|
mux := http.NewServeMux()
|
||||||
|
mux.HandleFunc("GET /carts", fs.CartsHandler)
|
||||||
|
mux.HandleFunc("GET /cart/{id}", fs.CartHandler)
|
||||||
|
mux.HandleFunc("/ws", hub.ServeWS)
|
||||||
|
mux.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("ok"))
|
||||||
|
})
|
||||||
|
mux.HandleFunc("/readyz", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("ok"))
|
||||||
|
})
|
||||||
|
mux.HandleFunc("/livez", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
|
_, _ = w.Write([]byte("ok"))
|
||||||
|
})
|
||||||
|
|
||||||
|
// Global CORS middleware allowing all origins and handling preflight
|
||||||
|
handler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
w.Header().Set("Access-Control-Allow-Origin", "*")
|
||||||
|
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
|
||||||
|
w.Header().Set("Access-Control-Allow-Headers", "Content-Type, Authorization, X-Requested-With")
|
||||||
|
w.Header().Set("Access-Control-Expose-Headers", "*")
|
||||||
|
if r.Method == http.MethodOptions {
|
||||||
|
w.WriteHeader(http.StatusNoContent)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
mux.ServeHTTP(w, r)
|
||||||
|
})
|
||||||
|
|
||||||
|
srv := &http.Server{
|
||||||
|
Addr: addr,
|
||||||
|
Handler: handler,
|
||||||
|
ReadTimeout: 10 * time.Second,
|
||||||
|
WriteTimeout: 30 * time.Second,
|
||||||
|
IdleTimeout: 60 * time.Second,
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx, cancel := context.WithCancel(context.Background())
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
|
if amqpURL != "" {
|
||||||
|
conn, err := amqp.Dial(amqpURL)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("failed to connect to RabbitMQ: %v", err)
|
||||||
|
}
|
||||||
|
if err := startMutationConsumer(ctx, conn, hub); err != nil {
|
||||||
|
log.Printf("AMQP listener disabled: %v", err)
|
||||||
|
} else {
|
||||||
|
log.Printf("AMQP listener connected")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
log.Printf("backoffice HTTP listening on %s (dataDir=%s)", addr, dataDir)
|
||||||
|
if err := srv.ListenAndServe(); err != nil && !errors.Is(err, http.ErrServerClosed) {
|
||||||
|
log.Fatalf("http server error: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// server stopped
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,42 +9,48 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type AmqpOrderHandler struct {
|
type AmqpOrderHandler struct {
|
||||||
Url string
|
conn *amqp.Connection
|
||||||
Connection *amqp.Connection
|
|
||||||
Channel *amqp.Channel
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AmqpOrderHandler) Connect() error {
|
func NewAmqpOrderHandler(conn *amqp.Connection) *AmqpOrderHandler {
|
||||||
conn, err := amqp.Dial(h.Url)
|
return &AmqpOrderHandler{
|
||||||
if err != nil {
|
conn: conn,
|
||||||
return fmt.Errorf("failed to connect to RabbitMQ: %w", err)
|
|
||||||
}
|
}
|
||||||
h.Connection = conn
|
}
|
||||||
|
|
||||||
ch, err := conn.Channel()
|
func (h *AmqpOrderHandler) DefineTopics() error {
|
||||||
|
ch, err := h.conn.Channel()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to open a channel: %w", err)
|
return fmt.Errorf("failed to open a channel: %w", err)
|
||||||
}
|
}
|
||||||
h.Channel = ch
|
defer ch.Close()
|
||||||
|
|
||||||
return nil
|
err = ch.ExchangeDeclare(
|
||||||
}
|
"orders", // name
|
||||||
|
"direct", // type
|
||||||
|
true, // durable
|
||||||
|
false, // auto-deleted
|
||||||
|
false, // internal
|
||||||
|
false, // no-wait
|
||||||
|
nil, // arguments
|
||||||
|
)
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to declare an exchange: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
func (h *AmqpOrderHandler) Close() error {
|
|
||||||
if h.Channel != nil {
|
|
||||||
h.Channel.Close()
|
|
||||||
}
|
|
||||||
if h.Connection != nil {
|
|
||||||
return h.Connection.Close()
|
|
||||||
}
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (h *AmqpOrderHandler) OrderCompleted(body []byte) error {
|
func (h *AmqpOrderHandler) OrderCompleted(body []byte) error {
|
||||||
|
ch, err := h.conn.Channel()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to open a channel: %w", err)
|
||||||
|
}
|
||||||
|
defer ch.Close()
|
||||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|
||||||
err := h.Channel.PublishWithContext(ctx,
|
return ch.PublishWithContext(ctx,
|
||||||
"orders", // exchange
|
"orders", // exchange
|
||||||
"new", // routing key
|
"new", // routing key
|
||||||
false, // mandatory
|
false, // mandatory
|
||||||
@@ -53,9 +59,5 @@ func (h *AmqpOrderHandler) OrderCompleted(body []byte) error {
|
|||||||
ContentType: "application/json",
|
ContentType: "application/json",
|
||||||
Body: body,
|
Body: body,
|
||||||
})
|
})
|
||||||
if err != nil {
|
|
||||||
return fmt.Errorf("failed to publish a message: %w", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,6 +3,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CheckoutMeta carries the external / URL metadata required to build a
|
// CheckoutMeta carries the external / URL metadata required to build a
|
||||||
@@ -33,7 +35,7 @@ type CheckoutMeta struct {
|
|||||||
//
|
//
|
||||||
// If you later need to support different tax rates per line, you can extend
|
// If you later need to support different tax rates per line, you can extend
|
||||||
// CartItem / Delivery to expose that data and propagate it here.
|
// CartItem / Delivery to expose that data and propagate it here.
|
||||||
func BuildCheckoutOrderPayload(grain *CartGrain, meta *CheckoutMeta) ([]byte, *CheckoutOrder, error) {
|
func BuildCheckoutOrderPayload(grain *cart.CartGrain, meta *CheckoutMeta) ([]byte, *CheckoutOrder, error) {
|
||||||
if grain == nil {
|
if grain == nil {
|
||||||
return nil, nil, fmt.Errorf("nil grain")
|
return nil, nil, fmt.Errorf("nil grain")
|
||||||
}
|
}
|
||||||
|
|||||||
154
cmd/cart/main.go
154
cmd/cart/main.go
@@ -13,6 +13,7 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.tornberg.me/go-cart-actor/pkg/actor"
|
"git.tornberg.me/go-cart-actor/pkg/actor"
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
"git.tornberg.me/go-cart-actor/pkg/discovery"
|
"git.tornberg.me/go-cart-actor/pkg/discovery"
|
||||||
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
"git.tornberg.me/go-cart-actor/pkg/proxy"
|
"git.tornberg.me/go-cart-actor/pkg/proxy"
|
||||||
@@ -20,6 +21,7 @@ import (
|
|||||||
"github.com/prometheus/client_golang/prometheus"
|
"github.com/prometheus/client_golang/prometheus"
|
||||||
"github.com/prometheus/client_golang/prometheus/promauto"
|
"github.com/prometheus/client_golang/prometheus/promauto"
|
||||||
"github.com/prometheus/client_golang/prometheus/promhttp"
|
"github.com/prometheus/client_golang/prometheus/promhttp"
|
||||||
|
amqp "github.com/rabbitmq/amqp091-go"
|
||||||
"k8s.io/apimachinery/pkg/watch"
|
"k8s.io/apimachinery/pkg/watch"
|
||||||
"k8s.io/client-go/kubernetes"
|
"k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/client-go/rest"
|
"k8s.io/client-go/rest"
|
||||||
@@ -45,7 +47,7 @@ func init() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
pool *actor.SimpleGrainPool[CartGrain]
|
pool *actor.SimpleGrainPool[cart.CartGrain]
|
||||||
}
|
}
|
||||||
|
|
||||||
var podIp = os.Getenv("POD_IP")
|
var podIp = os.Getenv("POD_IP")
|
||||||
@@ -97,63 +99,24 @@ type MutationContext struct {
|
|||||||
VoucherService voucher.Service
|
VoucherService voucher.Service
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type CartChangeEvent struct {
|
||||||
|
CartId cart.CartId `json:"cartId"`
|
||||||
|
Mutations []actor.ApplyResult `json:"mutations"`
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
controlPlaneConfig := actor.DefaultServerConfig()
|
controlPlaneConfig := actor.DefaultServerConfig()
|
||||||
|
|
||||||
reg := actor.NewMutationRegistry()
|
reg := cart.NewCartMultationRegistry()
|
||||||
reg.RegisterMutations(
|
diskStorage := actor.NewDiskStorage[cart.CartGrain]("data", reg)
|
||||||
actor.NewMutation(AddItem, func() *messages.AddItem {
|
poolConfig := actor.GrainPoolConfig[cart.CartGrain]{
|
||||||
return &messages.AddItem{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(ChangeQuantity, func() *messages.ChangeQuantity {
|
|
||||||
return &messages.ChangeQuantity{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(RemoveItem, func() *messages.RemoveItem {
|
|
||||||
return &messages.RemoveItem{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(InitializeCheckout, func() *messages.InitializeCheckout {
|
|
||||||
return &messages.InitializeCheckout{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(OrderCreated, func() *messages.OrderCreated {
|
|
||||||
return &messages.OrderCreated{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(RemoveDelivery, func() *messages.RemoveDelivery {
|
|
||||||
return &messages.RemoveDelivery{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(SetDelivery, func() *messages.SetDelivery {
|
|
||||||
return &messages.SetDelivery{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(SetPickupPoint, func() *messages.SetPickupPoint {
|
|
||||||
return &messages.SetPickupPoint{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(ClearCart, func() *messages.ClearCartRequest {
|
|
||||||
return &messages.ClearCartRequest{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(AddVoucher, func() *messages.AddVoucher {
|
|
||||||
return &messages.AddVoucher{}
|
|
||||||
}),
|
|
||||||
actor.NewMutation(RemoveVoucher, func() *messages.RemoveVoucher {
|
|
||||||
return &messages.RemoveVoucher{}
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
diskStorage := actor.NewDiskStorage[CartGrain]("data", reg)
|
|
||||||
poolConfig := actor.GrainPoolConfig[CartGrain]{
|
|
||||||
MutationRegistry: reg,
|
MutationRegistry: reg,
|
||||||
Storage: diskStorage,
|
Storage: diskStorage,
|
||||||
Spawn: func(id uint64) (actor.Grain[CartGrain], error) {
|
Spawn: func(id uint64) (actor.Grain[cart.CartGrain], error) {
|
||||||
grainSpawns.Inc()
|
grainSpawns.Inc()
|
||||||
ret := &CartGrain{
|
ret := cart.NewCartGrain(id, time.Now())
|
||||||
lastItemId: 0,
|
|
||||||
lastDeliveryId: 0,
|
|
||||||
Deliveries: []*CartDelivery{},
|
|
||||||
Id: CartId(id),
|
|
||||||
Items: []*CartItem{},
|
|
||||||
TotalPrice: NewPrice(),
|
|
||||||
}
|
|
||||||
// Set baseline lastChange at spawn; replay may update it to last event timestamp.
|
// Set baseline lastChange at spawn; replay may update it to last event timestamp.
|
||||||
ret.lastChange = time.Now()
|
|
||||||
ret.lastAccess = time.Now()
|
|
||||||
|
|
||||||
err := diskStorage.LoadEvents(id, ret)
|
err := diskStorage.LoadEvents(id, ret)
|
||||||
|
|
||||||
@@ -175,13 +138,27 @@ func main() {
|
|||||||
pool: pool,
|
pool: pool,
|
||||||
}
|
}
|
||||||
|
|
||||||
grpcSrv, err := actor.NewControlServer[*CartGrain](controlPlaneConfig, pool)
|
conn, err := amqp.Dial(amqpUrl)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Errorf("failed to connect to RabbitMQ: %w", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
amqpListener := actor.NewAmqpListener(conn, func(id uint64, msg []actor.ApplyResult) (any, error) {
|
||||||
|
return &CartChangeEvent{
|
||||||
|
CartId: cart.CartId(id),
|
||||||
|
Mutations: msg,
|
||||||
|
}, nil
|
||||||
|
})
|
||||||
|
amqpListener.DefineTopics()
|
||||||
|
pool.AddListener(amqpListener)
|
||||||
|
|
||||||
|
grpcSrv, err := actor.NewControlServer[*cart.CartGrain](controlPlaneConfig, pool)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Error starting control plane gRPC server: %v\n", err)
|
log.Fatalf("Error starting control plane gRPC server: %v\n", err)
|
||||||
}
|
}
|
||||||
defer grpcSrv.GracefulStop()
|
defer grpcSrv.GracefulStop()
|
||||||
|
|
||||||
go diskStorage.SaveLoop(10 * time.Second)
|
// go diskStorage.SaveLoop(10 * time.Second)
|
||||||
|
|
||||||
go func(hw discovery.Discovery) {
|
go func(hw discovery.Discovery) {
|
||||||
if hw == nil {
|
if hw == nil {
|
||||||
@@ -211,12 +188,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
}(GetDiscovery())
|
}(GetDiscovery())
|
||||||
|
|
||||||
orderHandler := &AmqpOrderHandler{
|
orderHandler := NewAmqpOrderHandler(conn)
|
||||||
Url: amqpUrl,
|
orderHandler.DefineTopics()
|
||||||
}
|
|
||||||
klarnaClient := NewKlarnaClient(KlarnaPlaygroundUrl, os.Getenv("KLARNA_API_USERNAME"), os.Getenv("KLARNA_API_PASSWORD"))
|
klarnaClient := NewKlarnaClient(KlarnaPlaygroundUrl, os.Getenv("KLARNA_API_USERNAME"), os.Getenv("KLARNA_API_PASSWORD"))
|
||||||
|
|
||||||
syncedServer := NewPoolServer(pool, fmt.Sprintf("%s, %s", name, podIp), klarnaClient)
|
syncedServer := NewPoolServer(pool, fmt.Sprintf("%s, %s", name, podIp), klarnaClient)
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
mux.Handle("/cart/", http.StripPrefix("/cart", syncedServer.Serve()))
|
mux.Handle("/cart/", http.StripPrefix("/cart", syncedServer.Serve()))
|
||||||
// only for local
|
// only for local
|
||||||
@@ -256,61 +233,14 @@ func main() {
|
|||||||
w.Write([]byte("ok"))
|
w.Write([]byte("ok"))
|
||||||
})
|
})
|
||||||
|
|
||||||
mux.HandleFunc("/checkout", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/checkout", syncedServer.CheckoutHandler(func(order *CheckoutOrder, w http.ResponseWriter) error {
|
||||||
orderId := r.URL.Query().Get("order_id")
|
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
||||||
order := &CheckoutOrder{}
|
w.Header().Set("Permissions-Policy", "payment=(self \"https://js.stripe.com\" \"https://m.stripe.network\" \"https://js.playground.kustom.co\")")
|
||||||
|
w.WriteHeader(http.StatusOK)
|
||||||
if orderId == "" {
|
_, err := fmt.Fprintf(w, tpl, order.HTMLSnippet)
|
||||||
cookie, err := r.Cookie("cartid")
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if cookie.Value == "" {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
w.Write([]byte("no cart id to checkout is empty"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
parsed, ok := ParseCartId(cookie.Value)
|
|
||||||
if !ok {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
w.Write([]byte("invalid cart id format"))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
cartId := parsed
|
|
||||||
syncedServer.ProxyHandler(func(w http.ResponseWriter, r *http.Request, cartId CartId) error {
|
|
||||||
order, err = syncedServer.CreateOrUpdateCheckout(r.Host, cartId)
|
|
||||||
if err != nil {
|
|
||||||
return err
|
return err
|
||||||
}
|
}))
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
||||||
w.Header().Set("Permissions-Policy", "payment=(self \"https://js.stripe.com\" \"https://m.stripe.network\" \"https://js.playground.kustom.co\")")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
fmt.Fprintf(w, tpl, order.HTMLSnippet)
|
|
||||||
return nil
|
|
||||||
})(cartId, w, r)
|
|
||||||
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusInternalServerError)
|
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
}
|
|
||||||
|
|
||||||
// v2: Apply now returns *CartGrain; order creation handled inside grain (no payload to unmarshal)
|
|
||||||
} else {
|
|
||||||
order, err = klarnaClient.GetOrder(orderId)
|
|
||||||
if err != nil {
|
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
|
||||||
w.Write([]byte(err.Error()))
|
|
||||||
return
|
|
||||||
}
|
|
||||||
w.Header().Set("Content-Type", "text/html; charset=utf-8")
|
|
||||||
w.Header().Set("Permissions-Policy", "payment=(self \"https://js.stripe.com\" \"https://m.stripe.network\" \"https://js.playground.kustom.co\")")
|
|
||||||
w.WriteHeader(http.StatusOK)
|
|
||||||
fmt.Fprintf(w, tpl, order.HTMLSnippet)
|
|
||||||
}
|
|
||||||
|
|
||||||
})
|
|
||||||
mux.HandleFunc("/confirmation/{order_id}", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/confirmation/{order_id}", func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
orderId := r.PathValue("order_id")
|
orderId := r.PathValue("order_id")
|
||||||
@@ -433,7 +363,7 @@ func triggerOrderCompleted(syncedServer *PoolServer, order *CheckoutOrder) error
|
|||||||
OrderId: order.ID,
|
OrderId: order.ID,
|
||||||
Status: order.Status,
|
Status: order.Status,
|
||||||
}
|
}
|
||||||
cid, ok := ParseCartId(order.MerchantReference1)
|
cid, ok := cart.ParseCartId(order.MerchantReference1)
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("invalid cart id in order reference: %s", order.MerchantReference1)
|
return fmt.Errorf("invalid cart id in order reference: %s", order.MerchantReference1)
|
||||||
}
|
}
|
||||||
@@ -447,11 +377,7 @@ func confirmOrder(order *CheckoutOrder, orderHandler *AmqpOrderHandler) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
err = orderHandler.Connect()
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
defer orderHandler.Close()
|
|
||||||
err = orderHandler.OrderCompleted(orderToSend)
|
err = orderHandler.OrderCompleted(orderToSend)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -11,18 +11,19 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"git.tornberg.me/go-cart-actor/pkg/actor"
|
"git.tornberg.me/go-cart-actor/pkg/actor"
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
"git.tornberg.me/go-cart-actor/pkg/voucher"
|
"git.tornberg.me/go-cart-actor/pkg/voucher"
|
||||||
"github.com/gogo/protobuf/proto"
|
"github.com/gogo/protobuf/proto"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PoolServer struct {
|
type PoolServer struct {
|
||||||
actor.GrainPool[*CartGrain]
|
actor.GrainPool[*cart.CartGrain]
|
||||||
pod_name string
|
pod_name string
|
||||||
klarnaClient *KlarnaClient
|
klarnaClient *KlarnaClient
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPoolServer(pool actor.GrainPool[*CartGrain], pod_name string, klarnaClient *KlarnaClient) *PoolServer {
|
func NewPoolServer(pool actor.GrainPool[*cart.CartGrain], pod_name string, klarnaClient *KlarnaClient) *PoolServer {
|
||||||
return &PoolServer{
|
return &PoolServer{
|
||||||
GrainPool: pool,
|
GrainPool: pool,
|
||||||
pod_name: pod_name,
|
pod_name: pod_name,
|
||||||
@@ -30,11 +31,11 @@ func NewPoolServer(pool actor.GrainPool[*CartGrain], pod_name string, klarnaClie
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) ApplyLocal(id CartId, mutation ...proto.Message) (*actor.MutationResult[*CartGrain], error) {
|
func (s *PoolServer) ApplyLocal(id cart.CartId, mutation ...proto.Message) (*actor.MutationResult[*cart.CartGrain], error) {
|
||||||
return s.Apply(uint64(id), mutation...)
|
return s.Apply(uint64(id), mutation...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) GetCartHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) GetCartHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
grain, err := s.Get(uint64(id))
|
grain, err := s.Get(uint64(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -43,7 +44,7 @@ func (s *PoolServer) GetCartHandler(w http.ResponseWriter, r *http.Request, id C
|
|||||||
return s.WriteResult(w, grain)
|
return s.WriteResult(w, grain)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) AddSkuToCartHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) AddSkuToCartHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
sku := r.PathValue("sku")
|
sku := r.PathValue("sku")
|
||||||
msg, err := GetItemAddMessage(sku, 1, getCountryFromHost(r.Host), nil)
|
msg, err := GetItemAddMessage(sku, 1, getCountryFromHost(r.Host), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -73,7 +74,7 @@ func (s *PoolServer) WriteResult(w http.ResponseWriter, result any) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) DeleteItemHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) DeleteItemHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
|
|
||||||
itemIdString := r.PathValue("itemId")
|
itemIdString := r.PathValue("itemId")
|
||||||
itemId, err := strconv.ParseInt(itemIdString, 10, 64)
|
itemId, err := strconv.ParseInt(itemIdString, 10, 64)
|
||||||
@@ -93,7 +94,7 @@ type SetDeliveryRequest struct {
|
|||||||
PickupPoint *messages.PickupPoint `json:"pickupPoint,omitempty"`
|
PickupPoint *messages.PickupPoint `json:"pickupPoint,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) SetDeliveryHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) SetDeliveryHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
|
|
||||||
delivery := SetDeliveryRequest{}
|
delivery := SetDeliveryRequest{}
|
||||||
err := json.NewDecoder(r.Body).Decode(&delivery)
|
err := json.NewDecoder(r.Body).Decode(&delivery)
|
||||||
@@ -111,7 +112,7 @@ func (s *PoolServer) SetDeliveryHandler(w http.ResponseWriter, r *http.Request,
|
|||||||
return s.WriteResult(w, data)
|
return s.WriteResult(w, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) SetPickupPointHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) SetPickupPointHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
|
|
||||||
deliveryIdString := r.PathValue("deliveryId")
|
deliveryIdString := r.PathValue("deliveryId")
|
||||||
deliveryId, err := strconv.ParseInt(deliveryIdString, 10, 64)
|
deliveryId, err := strconv.ParseInt(deliveryIdString, 10, 64)
|
||||||
@@ -138,7 +139,7 @@ func (s *PoolServer) SetPickupPointHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
return s.WriteResult(w, reply)
|
return s.WriteResult(w, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) RemoveDeliveryHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) RemoveDeliveryHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
|
|
||||||
deliveryIdString := r.PathValue("deliveryId")
|
deliveryIdString := r.PathValue("deliveryId")
|
||||||
deliveryId, err := strconv.Atoi(deliveryIdString)
|
deliveryId, err := strconv.Atoi(deliveryIdString)
|
||||||
@@ -152,7 +153,7 @@ func (s *PoolServer) RemoveDeliveryHandler(w http.ResponseWriter, r *http.Reques
|
|||||||
return s.WriteResult(w, reply)
|
return s.WriteResult(w, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) QuantityChangeHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) QuantityChangeHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
changeQuantity := messages.ChangeQuantity{}
|
changeQuantity := messages.ChangeQuantity{}
|
||||||
err := json.NewDecoder(r.Body).Decode(&changeQuantity)
|
err := json.NewDecoder(r.Body).Decode(&changeQuantity)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -197,7 +198,7 @@ func getMultipleAddMessages(items []Item, country string) []proto.Message {
|
|||||||
return msgs
|
return msgs
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) SetCartItemsHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) SetCartItemsHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
setCartItems := SetCartItems{}
|
setCartItems := SetCartItems{}
|
||||||
err := json.NewDecoder(r.Body).Decode(&setCartItems)
|
err := json.NewDecoder(r.Body).Decode(&setCartItems)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -215,7 +216,7 @@ func (s *PoolServer) SetCartItemsHandler(w http.ResponseWriter, r *http.Request,
|
|||||||
return s.WriteResult(w, reply)
|
return s.WriteResult(w, reply)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) AddMultipleItemHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) AddMultipleItemHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
setCartItems := SetCartItems{}
|
setCartItems := SetCartItems{}
|
||||||
err := json.NewDecoder(r.Body).Decode(&setCartItems)
|
err := json.NewDecoder(r.Body).Decode(&setCartItems)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -236,7 +237,7 @@ type AddRequest struct {
|
|||||||
StoreId *string `json:"storeId"`
|
StoreId *string `json:"storeId"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) AddSkuRequestHandler(w http.ResponseWriter, r *http.Request, id CartId) error {
|
func (s *PoolServer) AddSkuRequestHandler(w http.ResponseWriter, r *http.Request, id cart.CartId) error {
|
||||||
addRequest := AddRequest{Quantity: 1}
|
addRequest := AddRequest{Quantity: 1}
|
||||||
err := json.NewDecoder(r.Body).Decode(&addRequest)
|
err := json.NewDecoder(r.Body).Decode(&addRequest)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -287,7 +288,7 @@ func getLocale(country string) string {
|
|||||||
return "sv-se"
|
return "sv-se"
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) CreateOrUpdateCheckout(host string, id CartId) (*CheckoutOrder, error) {
|
func (s *PoolServer) CreateOrUpdateCheckout(host string, id cart.CartId) (*CheckoutOrder, error) {
|
||||||
country := getCountryFromHost(host)
|
country := getCountryFromHost(host)
|
||||||
meta := &CheckoutMeta{
|
meta := &CheckoutMeta{
|
||||||
Terms: fmt.Sprintf("https://%s/terms", host),
|
Terms: fmt.Sprintf("https://%s/terms", host),
|
||||||
@@ -319,7 +320,7 @@ func (s *PoolServer) CreateOrUpdateCheckout(host string, id CartId) (*CheckoutOr
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) ApplyCheckoutStarted(klarnaOrder *CheckoutOrder, id CartId) (*actor.MutationResult[*CartGrain], error) {
|
func (s *PoolServer) ApplyCheckoutStarted(klarnaOrder *CheckoutOrder, id cart.CartId) (*actor.MutationResult[*cart.CartGrain], error) {
|
||||||
// Persist initialization state via mutation (best-effort)
|
// Persist initialization state via mutation (best-effort)
|
||||||
return s.ApplyLocal(id, &messages.InitializeCheckout{
|
return s.ApplyLocal(id, &messages.InitializeCheckout{
|
||||||
OrderId: klarnaOrder.ID,
|
OrderId: klarnaOrder.ID,
|
||||||
@@ -341,12 +342,12 @@ func (s *PoolServer) ApplyCheckoutStarted(klarnaOrder *CheckoutOrder, id CartId)
|
|||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
|
|
||||||
func CookieCartIdHandler(fn func(cartId CartId, w http.ResponseWriter, r *http.Request) error) func(w http.ResponseWriter, r *http.Request) {
|
func CookieCartIdHandler(fn func(cartId cart.CartId, w http.ResponseWriter, r *http.Request) error) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var id CartId
|
var id cart.CartId
|
||||||
cookie, err := r.Cookie("cartid")
|
cookie, err := r.Cookie("cartid")
|
||||||
if err != nil || cookie.Value == "" {
|
if err != nil || cookie.Value == "" {
|
||||||
id = MustNewCartId()
|
id = cart.MustNewCartId()
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "cartid",
|
Name: "cartid",
|
||||||
Value: id.String(),
|
Value: id.String(),
|
||||||
@@ -358,9 +359,9 @@ func CookieCartIdHandler(fn func(cartId CartId, w http.ResponseWriter, r *http.R
|
|||||||
})
|
})
|
||||||
w.Header().Set("Set-Cart-Id", id.String())
|
w.Header().Set("Set-Cart-Id", id.String())
|
||||||
} else {
|
} else {
|
||||||
parsed, ok := ParseCartId(cookie.Value)
|
parsed, ok := cart.ParseCartId(cookie.Value)
|
||||||
if !ok {
|
if !ok {
|
||||||
id = MustNewCartId()
|
id = cart.MustNewCartId()
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "cartid",
|
Name: "cartid",
|
||||||
Value: id.String(),
|
Value: id.String(),
|
||||||
@@ -388,7 +389,7 @@ func CookieCartIdHandler(fn func(cartId CartId, w http.ResponseWriter, r *http.R
|
|||||||
|
|
||||||
// Removed leftover legacy block after CookieCartIdHandler (obsolete code referencing cid/legacy)
|
// Removed leftover legacy block after CookieCartIdHandler (obsolete code referencing cid/legacy)
|
||||||
|
|
||||||
func (s *PoolServer) RemoveCartCookie(w http.ResponseWriter, r *http.Request, cartId CartId) error {
|
func (s *PoolServer) RemoveCartCookie(w http.ResponseWriter, r *http.Request, cartId cart.CartId) error {
|
||||||
// Clear cart cookie (breaking change: do not issue a new legacy id here)
|
// Clear cart cookie (breaking change: do not issue a new legacy id here)
|
||||||
http.SetCookie(w, &http.Cookie{
|
http.SetCookie(w, &http.Cookie{
|
||||||
Name: "cartid",
|
Name: "cartid",
|
||||||
@@ -403,17 +404,17 @@ func (s *PoolServer) RemoveCartCookie(w http.ResponseWriter, r *http.Request, ca
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CartIdHandler(fn func(cartId CartId, w http.ResponseWriter, r *http.Request) error) func(w http.ResponseWriter, r *http.Request) {
|
func CartIdHandler(fn func(cartId cart.CartId, w http.ResponseWriter, r *http.Request) error) func(w http.ResponseWriter, r *http.Request) {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
var id CartId
|
var id cart.CartId
|
||||||
raw := r.PathValue("id")
|
raw := r.PathValue("id")
|
||||||
// If no id supplied, generate a new one
|
// If no id supplied, generate a new one
|
||||||
if raw == "" {
|
if raw == "" {
|
||||||
id := MustNewCartId()
|
id := cart.MustNewCartId()
|
||||||
w.Header().Set("Set-Cart-Id", id.String())
|
w.Header().Set("Set-Cart-Id", id.String())
|
||||||
} else {
|
} else {
|
||||||
// Parse base62 cart id
|
// Parse base62 cart id
|
||||||
if parsedId, ok := ParseCartId(raw); !ok {
|
if parsedId, ok := cart.ParseCartId(raw); !ok {
|
||||||
w.WriteHeader(http.StatusBadRequest)
|
w.WriteHeader(http.StatusBadRequest)
|
||||||
w.Write([]byte("cart id is invalid"))
|
w.Write([]byte("cart id is invalid"))
|
||||||
return
|
return
|
||||||
@@ -431,8 +432,8 @@ func CartIdHandler(fn func(cartId CartId, w http.ResponseWriter, r *http.Request
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) ProxyHandler(fn func(w http.ResponseWriter, r *http.Request, cartId CartId) error) func(cartId CartId, w http.ResponseWriter, r *http.Request) error {
|
func (s *PoolServer) ProxyHandler(fn func(w http.ResponseWriter, r *http.Request, cartId cart.CartId) error) func(cartId cart.CartId, w http.ResponseWriter, r *http.Request) error {
|
||||||
return func(cartId CartId, w http.ResponseWriter, r *http.Request) error {
|
return func(cartId cart.CartId, w http.ResponseWriter, r *http.Request) error {
|
||||||
if ownerHost, ok := s.OwnerHost(uint64(cartId)); ok {
|
if ownerHost, ok := s.OwnerHost(uint64(cartId)); ok {
|
||||||
handled, err := ownerHost.Proxy(uint64(cartId), w, r)
|
handled, err := ownerHost.Proxy(uint64(cartId), w, r)
|
||||||
if err == nil && handled {
|
if err == nil && handled {
|
||||||
@@ -449,7 +450,7 @@ type AddVoucherRequest struct {
|
|||||||
VoucherCode string `json:"code"`
|
VoucherCode string `json:"code"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) AddVoucherHandler(w http.ResponseWriter, r *http.Request, cartId CartId) error {
|
func (s *PoolServer) AddVoucherHandler(w http.ResponseWriter, r *http.Request, cartId cart.CartId) error {
|
||||||
data := &AddVoucherRequest{}
|
data := &AddVoucherRequest{}
|
||||||
json.NewDecoder(r.Body).Decode(data)
|
json.NewDecoder(r.Body).Decode(data)
|
||||||
v := voucher.Service{}
|
v := voucher.Service{}
|
||||||
@@ -469,7 +470,44 @@ func (s *PoolServer) AddVoucherHandler(w http.ResponseWriter, r *http.Request, c
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *PoolServer) RemoveVoucherHandler(w http.ResponseWriter, r *http.Request, cartId CartId) error {
|
func (s *PoolServer) SubscriptionDetailsHandler(w http.ResponseWriter, r *http.Request, cartId cart.CartId) error {
|
||||||
|
data := &messages.UpsertSubscriptionDetails{}
|
||||||
|
err := json.NewDecoder(r.Body).Decode(data)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
reply, err := s.ApplyLocal(cartId, data)
|
||||||
|
if err != nil {
|
||||||
|
w.WriteHeader(http.StatusInternalServerError)
|
||||||
|
w.Write([]byte(err.Error()))
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.WriteResult(w, reply)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PoolServer) CheckoutHandler(fn func(order *CheckoutOrder, w http.ResponseWriter) error) func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
return CookieCartIdHandler(s.ProxyHandler(func(w http.ResponseWriter, r *http.Request, cartId cart.CartId) error {
|
||||||
|
orderId := r.URL.Query().Get("order_id")
|
||||||
|
if orderId == "" {
|
||||||
|
order, err := s.CreateOrUpdateCheckout(r.Host, cartId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
s.ApplyCheckoutStarted(order, cartId)
|
||||||
|
return fn(order, w)
|
||||||
|
}
|
||||||
|
order, err := s.klarnaClient.GetOrder(orderId)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fn(order, w)
|
||||||
|
}))
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s *PoolServer) RemoveVoucherHandler(w http.ResponseWriter, r *http.Request, cartId cart.CartId) error {
|
||||||
|
|
||||||
idStr := r.PathValue("voucherId")
|
idStr := r.PathValue("voucherId")
|
||||||
id, err := strconv.ParseInt(idStr, 10, 64)
|
id, err := strconv.ParseInt(idStr, 10, 64)
|
||||||
@@ -510,6 +548,7 @@ func (s *PoolServer) Serve() *http.ServeMux {
|
|||||||
mux.HandleFunc("DELETE /delivery/{deliveryId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveDeliveryHandler)))
|
mux.HandleFunc("DELETE /delivery/{deliveryId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveDeliveryHandler)))
|
||||||
mux.HandleFunc("PUT /delivery/{deliveryId}/pickupPoint", CookieCartIdHandler(s.ProxyHandler(s.SetPickupPointHandler)))
|
mux.HandleFunc("PUT /delivery/{deliveryId}/pickupPoint", CookieCartIdHandler(s.ProxyHandler(s.SetPickupPointHandler)))
|
||||||
mux.HandleFunc("PUT /voucher", CookieCartIdHandler(s.ProxyHandler(s.AddVoucherHandler)))
|
mux.HandleFunc("PUT /voucher", CookieCartIdHandler(s.ProxyHandler(s.AddVoucherHandler)))
|
||||||
|
mux.HandleFunc("PUT /subscription-details", CookieCartIdHandler(s.ProxyHandler(s.SubscriptionDetailsHandler)))
|
||||||
mux.HandleFunc("DELETE /voucher/{voucherId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveVoucherHandler)))
|
mux.HandleFunc("DELETE /voucher/{voucherId}", CookieCartIdHandler(s.ProxyHandler(s.RemoveVoucherHandler)))
|
||||||
|
|
||||||
//mux.HandleFunc("GET /checkout", CookieCartIdHandler(s.ProxyHandler(s.HandleCheckout)))
|
//mux.HandleFunc("GET /checkout", CookieCartIdHandler(s.ProxyHandler(s.HandleCheckout)))
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/cart"
|
||||||
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
"github.com/matst80/slask-finder/pkg/index"
|
"github.com/matst80/slask-finder/pkg/index"
|
||||||
)
|
)
|
||||||
@@ -42,31 +43,41 @@ func GetItemAddMessage(sku string, qty int, country string, storeId *string) (*m
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return ToItemAddMessage(item, storeId, qty, country), nil
|
return ToItemAddMessage(item, storeId, qty, country)
|
||||||
}
|
}
|
||||||
|
|
||||||
func ToItemAddMessage(item *index.DataItem, storeId *string, qty int, country string) *messages.AddItem {
|
func ToItemAddMessage(item *index.DataItem, storeId *string, qty int, country string) (*messages.AddItem, error) {
|
||||||
orgPrice, _ := getInt(item.GetNumberFieldValue(5)) // getInt(item.Fields[5])
|
orgPrice, _ := getInt(item.GetNumberFieldValue(5)) // getInt(item.Fields[5])
|
||||||
|
|
||||||
price, err := getInt(item.GetNumberFieldValue(4)) //Fields[4]
|
price, err := getInt(item.GetNumberFieldValue(4)) //Fields[4]
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
stock := StockStatus(0)
|
stock := cart.StockStatus(0)
|
||||||
centralStockValue, ok := item.GetStringFieldValue(3)
|
centralStockValue, ok := item.GetStringFieldValue(3)
|
||||||
if storeId == nil {
|
if storeId == nil {
|
||||||
if ok {
|
if ok {
|
||||||
|
if !item.Buyable {
|
||||||
|
return nil, fmt.Errorf("item not available")
|
||||||
|
}
|
||||||
pureNumber := strings.Replace(centralStockValue, "+", "", -1)
|
pureNumber := strings.Replace(centralStockValue, "+", "", -1)
|
||||||
if centralStock, err := strconv.ParseInt(pureNumber, 10, 64); err == nil {
|
if centralStock, err := strconv.ParseInt(pureNumber, 10, 64); err == nil {
|
||||||
stock = StockStatus(centralStock)
|
stock = cart.StockStatus(centralStock)
|
||||||
|
}
|
||||||
|
if stock == cart.StockStatus(0) && item.SaleStatus == "TBD" {
|
||||||
|
return nil, fmt.Errorf("no items available")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
if !item.BuyableInStore {
|
||||||
|
return nil, fmt.Errorf("item not available in store")
|
||||||
|
}
|
||||||
storeStock, ok := item.Stock.GetStock()[*storeId]
|
storeStock, ok := item.Stock.GetStock()[*storeId]
|
||||||
if ok {
|
if ok {
|
||||||
stock = StockStatus(storeStock)
|
stock = cart.StockStatus(storeStock)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
articleType, _ := item.GetStringFieldValue(1) //.Fields[1].(string)
|
articleType, _ := item.GetStringFieldValue(1) //.Fields[1].(string)
|
||||||
@@ -108,7 +119,8 @@ func ToItemAddMessage(item *index.DataItem, storeId *string, qty int, country st
|
|||||||
Country: country,
|
Country: country,
|
||||||
Outlet: outlet,
|
Outlet: outlet,
|
||||||
StoreId: storeId,
|
StoreId: storeId,
|
||||||
}
|
SaleStatus: item.SaleStatus,
|
||||||
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getTax(articleType string) int32 {
|
func getTax(articleType string) int32 {
|
||||||
@@ -119,3 +131,10 @@ func getTax(articleType string) int32 {
|
|||||||
return 2500
|
return 2500
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getInt(data float64, ok bool) (int, error) {
|
||||||
|
if !ok {
|
||||||
|
return 0, fmt.Errorf("invalid type")
|
||||||
|
}
|
||||||
|
return int(data), nil
|
||||||
|
}
|
||||||
|
|||||||
BIN
data/1.prot
BIN
data/1.prot
Binary file not shown.
BIN
data/4.prot
BIN
data/4.prot
Binary file not shown.
BIN
data/5.prot
BIN
data/5.prot
Binary file not shown.
BIN
data/state.gob
BIN
data/state.gob
Binary file not shown.
Binary file not shown.
@@ -9,6 +9,94 @@ type: Opaque
|
|||||||
---
|
---
|
||||||
apiVersion: apps/v1
|
apiVersion: apps/v1
|
||||||
kind: Deployment
|
kind: Deployment
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cart-backoffice
|
||||||
|
arch: amd64
|
||||||
|
name: cart-backoffice-x86
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
selector:
|
||||||
|
matchLabels:
|
||||||
|
app: cart-backoffice
|
||||||
|
arch: amd64
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
app: cart-backoffice
|
||||||
|
arch: amd64
|
||||||
|
spec:
|
||||||
|
affinity:
|
||||||
|
nodeAffinity:
|
||||||
|
requiredDuringSchedulingIgnoredDuringExecution:
|
||||||
|
nodeSelectorTerms:
|
||||||
|
- matchExpressions:
|
||||||
|
- key: kubernetes.io/arch
|
||||||
|
operator: NotIn
|
||||||
|
values:
|
||||||
|
- arm64
|
||||||
|
volumes:
|
||||||
|
- name: data
|
||||||
|
nfs:
|
||||||
|
path: /i-data/7a8af061/nfs/cart-actor
|
||||||
|
server: 10.10.1.10
|
||||||
|
imagePullSecrets:
|
||||||
|
- name: regcred
|
||||||
|
serviceAccountName: default
|
||||||
|
containers:
|
||||||
|
- image: registry.knatofs.se/go-cart-actor-amd64:latest
|
||||||
|
name: cart-actor-amd64
|
||||||
|
imagePullPolicy: Always
|
||||||
|
command: ["/go-cart-backoffice"]
|
||||||
|
lifecycle:
|
||||||
|
preStop:
|
||||||
|
exec:
|
||||||
|
command: ["sleep", "15"]
|
||||||
|
ports:
|
||||||
|
- containerPort: 8080
|
||||||
|
name: web
|
||||||
|
livenessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /livez
|
||||||
|
port: web
|
||||||
|
failureThreshold: 1
|
||||||
|
periodSeconds: 10
|
||||||
|
readinessProbe:
|
||||||
|
httpGet:
|
||||||
|
path: /readyz
|
||||||
|
port: web
|
||||||
|
failureThreshold: 2
|
||||||
|
initialDelaySeconds: 2
|
||||||
|
periodSeconds: 10
|
||||||
|
volumeMounts:
|
||||||
|
- mountPath: "/data"
|
||||||
|
name: data
|
||||||
|
resources:
|
||||||
|
limits:
|
||||||
|
memory: "768Mi"
|
||||||
|
requests:
|
||||||
|
memory: "70Mi"
|
||||||
|
cpu: "1200m"
|
||||||
|
env:
|
||||||
|
- name: TZ
|
||||||
|
value: "Europe/Stockholm"
|
||||||
|
- name: KLARNA_API_USERNAME
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: klarna-api-credentials
|
||||||
|
key: username
|
||||||
|
- name: KLARNA_API_PASSWORD
|
||||||
|
valueFrom:
|
||||||
|
secretKeyRef:
|
||||||
|
name: klarna-api-credentials
|
||||||
|
key: password
|
||||||
|
- name: AMQP_URL
|
||||||
|
value: "amqp://admin:12bananer@rabbitmq.dev:5672/"
|
||||||
|
# - name: BASE_URL
|
||||||
|
# value: "https://s10n-no.tornberg.me"
|
||||||
|
---
|
||||||
|
apiVersion: apps/v1
|
||||||
|
kind: Deployment
|
||||||
metadata:
|
metadata:
|
||||||
labels:
|
labels:
|
||||||
app: cart-actor
|
app: cart-actor
|
||||||
@@ -222,6 +310,17 @@ spec:
|
|||||||
- name: web
|
- name: web
|
||||||
port: 8080
|
port: 8080
|
||||||
---
|
---
|
||||||
|
kind: Service
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: cart-backoffice
|
||||||
|
spec:
|
||||||
|
selector:
|
||||||
|
app: cart-backoffice
|
||||||
|
ports:
|
||||||
|
- name: web
|
||||||
|
port: 8080
|
||||||
|
---
|
||||||
apiVersion: networking.k8s.io/v1
|
apiVersion: networking.k8s.io/v1
|
||||||
kind: Ingress
|
kind: Ingress
|
||||||
metadata:
|
metadata:
|
||||||
@@ -250,3 +349,27 @@ spec:
|
|||||||
name: cart-actor
|
name: cart-actor
|
||||||
port:
|
port:
|
||||||
number: 8080
|
number: 8080
|
||||||
|
---
|
||||||
|
apiVersion: networking.k8s.io/v1
|
||||||
|
kind: Ingress
|
||||||
|
metadata:
|
||||||
|
name: cart-backend-ingress
|
||||||
|
annotations:
|
||||||
|
cert-manager.io/cluster-issuer: letsencrypt-prod
|
||||||
|
spec:
|
||||||
|
ingressClassName: nginx
|
||||||
|
tls:
|
||||||
|
- hosts:
|
||||||
|
- slask-cart.tornberg.me
|
||||||
|
secretName: cart-backoffice-actor-tls-secret
|
||||||
|
rules:
|
||||||
|
- host: slask-cart.tornberg.me
|
||||||
|
http:
|
||||||
|
paths:
|
||||||
|
- path: /
|
||||||
|
pathType: Prefix
|
||||||
|
backend:
|
||||||
|
service:
|
||||||
|
name: cart-backoffice
|
||||||
|
port:
|
||||||
|
number: 8080
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ type DiskStorage[V any] struct {
|
|||||||
|
|
||||||
type LogStorage[V any] interface {
|
type LogStorage[V any] interface {
|
||||||
LoadEvents(id uint64, grain Grain[V]) error
|
LoadEvents(id uint64, grain Grain[V]) error
|
||||||
AppendEvent(id uint64, msg ...proto.Message) error
|
AppendMutations(id uint64, msg ...proto.Message) error
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDiskStorage[V any](path string, registry MutationRegistry) *DiskStorage[V] {
|
func NewDiskStorage[V any](path string, registry MutationRegistry) *DiskStorage[V] {
|
||||||
@@ -108,7 +108,7 @@ func (s *DiskStorage[V]) Close() {
|
|||||||
close(s.done)
|
close(s.done)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *DiskStorage[V]) AppendEvent(id uint64, msg ...proto.Message) error {
|
func (s *DiskStorage[V]) AppendMutations(id uint64, msg ...proto.Message) error {
|
||||||
if s.queue != nil {
|
if s.queue != nil {
|
||||||
queue := make([]QueueEvent, 0)
|
queue := make([]QueueEvent, 0)
|
||||||
data, found := s.queue.Load(id)
|
data, found := s.queue.Load(id)
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import (
|
|||||||
// It delegates to a grain pool and cluster operations to a synced pool.
|
// It delegates to a grain pool and cluster operations to a synced pool.
|
||||||
type ControlServer[V any] struct {
|
type ControlServer[V any] struct {
|
||||||
messages.UnimplementedControlPlaneServer
|
messages.UnimplementedControlPlaneServer
|
||||||
|
|
||||||
pool GrainPool[V]
|
pool GrainPool[V]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
47
pkg/actor/log_listerner.go
Normal file
47
pkg/actor/log_listerner.go
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
package actor
|
||||||
|
|
||||||
|
import (
|
||||||
|
"log"
|
||||||
|
|
||||||
|
"github.com/matst80/slask-finder/pkg/messaging"
|
||||||
|
amqp "github.com/rabbitmq/amqp091-go"
|
||||||
|
)
|
||||||
|
|
||||||
|
type LogListener interface {
|
||||||
|
AppendMutations(id uint64, msg ...ApplyResult)
|
||||||
|
}
|
||||||
|
|
||||||
|
type AmqpListener struct {
|
||||||
|
conn *amqp.Connection
|
||||||
|
transformer func(id uint64, msg []ApplyResult) (any, error)
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAmqpListener(conn *amqp.Connection, transformer func(id uint64, msg []ApplyResult) (any, error)) *AmqpListener {
|
||||||
|
return &AmqpListener{
|
||||||
|
conn: conn,
|
||||||
|
transformer: transformer,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AmqpListener) DefineTopics() {
|
||||||
|
ch, err := l.conn.Channel()
|
||||||
|
if err != nil {
|
||||||
|
log.Fatalf("Failed to open a channel: %v", err)
|
||||||
|
}
|
||||||
|
defer ch.Close()
|
||||||
|
if err := messaging.DefineTopic(ch, "cart", "mutation"); err != nil {
|
||||||
|
log.Fatalf("Failed to declare topic mutation: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (l *AmqpListener) AppendMutations(id uint64, msg ...ApplyResult) {
|
||||||
|
data, err := l.transformer(id, msg)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to transform mutation event: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
err = messaging.SendChange(l.conn, "cart", "mutation", data)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("Failed to send mutation event: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -171,11 +171,21 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) ([]ApplyR
|
|||||||
if grain == nil {
|
if grain == nil {
|
||||||
return results, fmt.Errorf("nil grain")
|
return results, fmt.Errorf("nil grain")
|
||||||
}
|
}
|
||||||
|
// Nil slice of mutations still treated as an error (call contract violation).
|
||||||
if msg == nil {
|
if msg == nil {
|
||||||
return results, fmt.Errorf("nil mutation message")
|
return results, fmt.Errorf("nil mutation message")
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, m := range msg {
|
for _, m := range msg {
|
||||||
|
// Ignore nil mutation elements (untyped or typed nil pointers) silently; they carry no data.
|
||||||
|
if m == nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
// Typed nil: interface holds concrete proto message type whose pointer value is nil.
|
||||||
|
rv := reflect.ValueOf(m)
|
||||||
|
if rv.Kind() == reflect.Ptr && rv.IsNil() {
|
||||||
|
continue
|
||||||
|
}
|
||||||
rt := indirectType(reflect.TypeOf(m))
|
rt := indirectType(reflect.TypeOf(m))
|
||||||
r.mutationRegistryMu.RLock()
|
r.mutationRegistryMu.RLock()
|
||||||
entry, ok := r.mutationRegistry[rt]
|
entry, ok := r.mutationRegistry[rt]
|
||||||
@@ -188,10 +198,6 @@ func (r *ProtoMutationRegistry) Apply(grain any, msg ...proto.Message) ([]ApplyR
|
|||||||
results = append(results, ApplyResult{Error: err, Type: rt.Name(), Mutation: m})
|
results = append(results, ApplyResult{Error: err, Type: rt.Name(), Mutation: m})
|
||||||
}
|
}
|
||||||
|
|
||||||
// if entry.updateTotals {
|
|
||||||
// grain.UpdateTotals()
|
|
||||||
// }
|
|
||||||
|
|
||||||
return results, nil
|
return results, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ type SimpleGrainPool[V any] struct {
|
|||||||
mutationRegistry MutationRegistry
|
mutationRegistry MutationRegistry
|
||||||
spawn func(id uint64) (Grain[V], error)
|
spawn func(id uint64) (Grain[V], error)
|
||||||
spawnHost func(host string) (Host, error)
|
spawnHost func(host string) (Host, error)
|
||||||
|
listeners []LogListener
|
||||||
storage LogStorage[V]
|
storage LogStorage[V]
|
||||||
ttl time.Duration
|
ttl time.Duration
|
||||||
poolSize int
|
poolSize int
|
||||||
@@ -66,6 +67,19 @@ func NewSimpleGrainPool[V any](config GrainPoolConfig[V]) (*SimpleGrainPool[V],
|
|||||||
return p, nil
|
return p, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (p *SimpleGrainPool[V]) AddListener(listener LogListener) {
|
||||||
|
p.listeners = append(p.listeners, listener)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *SimpleGrainPool[V]) RemoveListener(listener LogListener) {
|
||||||
|
for i, l := range p.listeners {
|
||||||
|
if l == listener {
|
||||||
|
p.listeners = append(p.listeners[:i], p.listeners[i+1:]...)
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (p *SimpleGrainPool[V]) purge() {
|
func (p *SimpleGrainPool[V]) purge() {
|
||||||
purgeLimit := time.Now().Add(-p.ttl)
|
purgeLimit := time.Now().Add(-p.ttl)
|
||||||
purgedIds := make([]uint64, 0, len(p.grains))
|
purgedIds := make([]uint64, 0, len(p.grains))
|
||||||
@@ -383,11 +397,14 @@ func (p *SimpleGrainPool[V]) Apply(id uint64, mutation ...proto.Message) (*Mutat
|
|||||||
}
|
}
|
||||||
if p.storage != nil {
|
if p.storage != nil {
|
||||||
go func() {
|
go func() {
|
||||||
if err := p.storage.AppendEvent(id, mutation...); err != nil {
|
if err := p.storage.AppendMutations(id, mutation...); err != nil {
|
||||||
log.Printf("failed to store mutation for grain %d: %v", id, err)
|
log.Printf("failed to store mutation for grain %d: %v", id, err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}
|
}
|
||||||
|
for _, listener := range p.listeners {
|
||||||
|
go listener.AppendMutations(id, mutations...)
|
||||||
|
}
|
||||||
result, err := grain.GetCurrentState()
|
result, err := grain.GetCurrentState()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
|
||||||
"slices"
|
"slices"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
@@ -33,7 +32,7 @@ type ItemMeta struct {
|
|||||||
type CartItem struct {
|
type CartItem struct {
|
||||||
Id uint32 `json:"id"`
|
Id uint32 `json:"id"`
|
||||||
ItemId uint32 `json:"itemId,omitempty"`
|
ItemId uint32 `json:"itemId,omitempty"`
|
||||||
ParentId uint32 `json:"parentId,omitempty"`
|
ParentId *uint32 `json:"parentId,omitempty"`
|
||||||
Sku string `json:"sku"`
|
Sku string `json:"sku"`
|
||||||
Price Price `json:"price"`
|
Price Price `json:"price"`
|
||||||
TotalPrice Price `json:"totalPrice"`
|
TotalPrice Price `json:"totalPrice"`
|
||||||
@@ -45,6 +44,7 @@ type CartItem struct {
|
|||||||
ArticleType string `json:"type,omitempty"`
|
ArticleType string `json:"type,omitempty"`
|
||||||
StoreId *string `json:"storeId,omitempty"`
|
StoreId *string `json:"storeId,omitempty"`
|
||||||
Meta *ItemMeta `json:"meta,omitempty"`
|
Meta *ItemMeta `json:"meta,omitempty"`
|
||||||
|
SaleStatus string `json:"saleStatus"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type CartDelivery struct {
|
type CartDelivery struct {
|
||||||
@@ -62,6 +62,13 @@ type CartNotification struct {
|
|||||||
Content string `json:"content"`
|
Content string `json:"content"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type SubscriptionDetails struct {
|
||||||
|
Id string `json:"id"`
|
||||||
|
OfferingCode string `json:"offeringCode,omitempty"`
|
||||||
|
SigningType string `json:"signingType,omitempty"`
|
||||||
|
Meta json.RawMessage `json:"data,omitempty"`
|
||||||
|
}
|
||||||
|
|
||||||
type CartGrain struct {
|
type CartGrain struct {
|
||||||
mu sync.RWMutex
|
mu sync.RWMutex
|
||||||
lastItemId uint32
|
lastItemId uint32
|
||||||
@@ -81,6 +88,7 @@ type CartGrain struct {
|
|||||||
PaymentStatus string `json:"paymentStatus,omitempty"`
|
PaymentStatus string `json:"paymentStatus,omitempty"`
|
||||||
Vouchers []*Voucher `json:"vouchers,omitempty"`
|
Vouchers []*Voucher `json:"vouchers,omitempty"`
|
||||||
Notifications []CartNotification `json:"cartNotification,omitempty"`
|
Notifications []CartNotification `json:"cartNotification,omitempty"`
|
||||||
|
SubscriptionDetails map[string]*SubscriptionDetails `json:"subscriptionDetails,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Voucher struct {
|
type Voucher struct {
|
||||||
@@ -138,6 +146,23 @@ func (v *Voucher) AppliesTo(cart *CartGrain) ([]*CartItem, bool) {
|
|||||||
return cart.Items, true
|
return cart.Items, true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func NewCartGrain(id uint64, ts time.Time) *CartGrain {
|
||||||
|
return &CartGrain{
|
||||||
|
lastItemId: 0,
|
||||||
|
lastDeliveryId: 0,
|
||||||
|
lastVoucherId: 0,
|
||||||
|
lastAccess: ts,
|
||||||
|
lastChange: ts,
|
||||||
|
TotalDiscount: NewPrice(),
|
||||||
|
Vouchers: []*Voucher{},
|
||||||
|
Deliveries: []*CartDelivery{},
|
||||||
|
Id: CartId(id),
|
||||||
|
Items: []*CartItem{},
|
||||||
|
TotalPrice: NewPrice(),
|
||||||
|
SubscriptionDetails: make(map[string]*SubscriptionDetails),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func (c *CartGrain) GetId() uint64 {
|
func (c *CartGrain) GetId() uint64 {
|
||||||
return uint64(c.Id)
|
return uint64(c.Id)
|
||||||
}
|
}
|
||||||
@@ -155,22 +180,6 @@ func (c *CartGrain) GetCurrentState() (*CartGrain, error) {
|
|||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getInt(data float64, ok bool) (int, error) {
|
|
||||||
if !ok {
|
|
||||||
return 0, fmt.Errorf("invalid type")
|
|
||||||
}
|
|
||||||
return int(data), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// func (c *CartGrain) AddItem(sku string, qty int, country string, storeId *string) (*CartGrain, error) {
|
|
||||||
// cartItem, err := getItemData(sku, qty, country)
|
|
||||||
// if err != nil {
|
|
||||||
// return nil, err
|
|
||||||
// }
|
|
||||||
// cartItem.StoreId = storeId
|
|
||||||
// return c.Apply(cartItem, false)
|
|
||||||
// }
|
|
||||||
|
|
||||||
func (c *CartGrain) GetState() ([]byte, error) {
|
func (c *CartGrain) GetState() ([]byte, error) {
|
||||||
return json.Marshal(c)
|
return json.Marshal(c)
|
||||||
}
|
}
|
||||||
@@ -260,6 +269,10 @@ func (c *CartGrain) UpdateTotals() {
|
|||||||
for _, voucher := range c.Vouchers {
|
for _, voucher := range c.Vouchers {
|
||||||
if _, ok := voucher.AppliesTo(c); ok {
|
if _, ok := voucher.AppliesTo(c); ok {
|
||||||
value := NewPriceFromIncVat(voucher.Value, 25)
|
value := NewPriceFromIncVat(voucher.Value, 25)
|
||||||
|
if c.TotalPrice.IncVat <= value.IncVat {
|
||||||
|
// don't apply discounts to more than the total price
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
c.TotalDiscount.Add(*value)
|
c.TotalDiscount.Add(*value)
|
||||||
c.TotalPrice.Subtract(*value)
|
c.TotalPrice.Subtract(*value)
|
||||||
51
pkg/cart/cart-mutation-helper.go
Normal file
51
pkg/cart/cart-mutation-helper.go
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
package cart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/actor"
|
||||||
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
|
)
|
||||||
|
|
||||||
|
func NewCartMultationRegistry() actor.MutationRegistry {
|
||||||
|
|
||||||
|
reg := actor.NewMutationRegistry()
|
||||||
|
reg.RegisterMutations(
|
||||||
|
actor.NewMutation(AddItem, func() *messages.AddItem {
|
||||||
|
return &messages.AddItem{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(ChangeQuantity, func() *messages.ChangeQuantity {
|
||||||
|
return &messages.ChangeQuantity{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(RemoveItem, func() *messages.RemoveItem {
|
||||||
|
return &messages.RemoveItem{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(InitializeCheckout, func() *messages.InitializeCheckout {
|
||||||
|
return &messages.InitializeCheckout{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(OrderCreated, func() *messages.OrderCreated {
|
||||||
|
return &messages.OrderCreated{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(RemoveDelivery, func() *messages.RemoveDelivery {
|
||||||
|
return &messages.RemoveDelivery{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(SetDelivery, func() *messages.SetDelivery {
|
||||||
|
return &messages.SetDelivery{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(SetPickupPoint, func() *messages.SetPickupPoint {
|
||||||
|
return &messages.SetPickupPoint{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(ClearCart, func() *messages.ClearCartRequest {
|
||||||
|
return &messages.ClearCartRequest{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(AddVoucher, func() *messages.AddVoucher {
|
||||||
|
return &messages.AddVoucher{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(RemoveVoucher, func() *messages.RemoveVoucher {
|
||||||
|
return &messages.RemoveVoucher{}
|
||||||
|
}),
|
||||||
|
actor.NewMutation(UpsertSubscriptionDetails, func() *messages.UpsertSubscriptionDetails {
|
||||||
|
return &messages.UpsertSubscriptionDetails{}
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
return reg
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"testing"
|
"testing"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/rand"
|
"crypto/rand"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -28,14 +28,23 @@ func AddItem(g *CartGrain, m *messages.AddItem) error {
|
|||||||
return fmt.Errorf("AddItem: invalid quantity %d", m.Quantity)
|
return fmt.Errorf("AddItem: invalid quantity %d", m.Quantity)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Fast path: merge with existing item having same SKU
|
// Merge with any existing item having same SKU and matching StoreId (including both nil).
|
||||||
if existing, found := g.FindItemWithSku(m.Sku); found {
|
for _, existing := range g.Items {
|
||||||
if existing.StoreId == m.StoreId {
|
if existing.Sku != m.Sku {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
sameStore := (existing.StoreId == nil && m.StoreId == nil) ||
|
||||||
|
(existing.StoreId != nil && m.StoreId != nil && *existing.StoreId == *m.StoreId)
|
||||||
|
if !sameStore {
|
||||||
|
continue
|
||||||
|
}
|
||||||
existing.Quantity += int(m.Quantity)
|
existing.Quantity += int(m.Quantity)
|
||||||
existing.Stock = StockStatus(m.Stock)
|
existing.Stock = StockStatus(m.Stock)
|
||||||
|
// If existing had nil store but new has one, adopt it.
|
||||||
|
if existing.StoreId == nil && m.StoreId != nil {
|
||||||
existing.StoreId = m.StoreId
|
existing.StoreId = m.StoreId
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
g.mu.Lock()
|
g.mu.Lock()
|
||||||
@@ -67,6 +76,8 @@ func AddItem(g *CartGrain, m *messages.AddItem) error {
|
|||||||
SellerId: m.SellerId,
|
SellerId: m.SellerId,
|
||||||
SellerName: m.SellerName,
|
SellerName: m.SellerName,
|
||||||
},
|
},
|
||||||
|
SaleStatus: m.SaleStatus,
|
||||||
|
ParentId: m.ParentId,
|
||||||
|
|
||||||
Price: *pricePerItem,
|
Price: *pricePerItem,
|
||||||
TotalPrice: *MultiplyPrice(*pricePerItem, int64(m.Quantity)),
|
TotalPrice: *MultiplyPrice(*pricePerItem, int64(m.Quantity)),
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"slices"
|
"slices"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
520
pkg/cart/mutation_test.go
Normal file
520
pkg/cart/mutation_test.go
Normal file
@@ -0,0 +1,520 @@
|
|||||||
|
package cart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"reflect"
|
||||||
|
"slices"
|
||||||
|
"strings"
|
||||||
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/gogo/protobuf/proto"
|
||||||
|
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||||
|
|
||||||
|
"git.tornberg.me/go-cart-actor/pkg/actor"
|
||||||
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
|
)
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
// Helper constructors
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
func newTestGrain() *CartGrain {
|
||||||
|
return NewCartGrain(123, time.Now())
|
||||||
|
}
|
||||||
|
|
||||||
|
func newRegistry() actor.MutationRegistry {
|
||||||
|
return NewCartMultationRegistry()
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgAddItem(sku string, price int64, qty int32, storePtr *string) *messages.AddItem {
|
||||||
|
return &messages.AddItem{
|
||||||
|
Sku: sku,
|
||||||
|
Price: price,
|
||||||
|
Quantity: qty,
|
||||||
|
// Tax left 0 -> handler uses default 25%
|
||||||
|
StoreId: storePtr,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgChangeQty(id uint32, qty int32) *messages.ChangeQuantity {
|
||||||
|
return &messages.ChangeQuantity{Id: id, Quantity: qty}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgRemoveItem(id uint32) *messages.RemoveItem {
|
||||||
|
return &messages.RemoveItem{Id: id}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgSetDelivery(provider string, items ...uint32) *messages.SetDelivery {
|
||||||
|
uitems := make([]uint32, len(items))
|
||||||
|
copy(uitems, items)
|
||||||
|
return &messages.SetDelivery{Provider: provider, Items: uitems}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgSetPickupPoint(deliveryId uint32, id string) *messages.SetPickupPoint {
|
||||||
|
return &messages.SetPickupPoint{
|
||||||
|
DeliveryId: deliveryId,
|
||||||
|
Id: id,
|
||||||
|
Name: ptr("Pickup"),
|
||||||
|
Address: ptr("Street 1"),
|
||||||
|
City: ptr("Town"),
|
||||||
|
Zip: ptr("12345"),
|
||||||
|
Country: ptr("SE"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgClearCart() *messages.ClearCartRequest {
|
||||||
|
return &messages.ClearCartRequest{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgAddVoucher(code string, value int64, rules ...*messages.VoucherRule) *messages.AddVoucher {
|
||||||
|
return &messages.AddVoucher{Code: code, Value: value, VoucherRules: rules}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgRemoveVoucher(id uint32) *messages.RemoveVoucher {
|
||||||
|
return &messages.RemoveVoucher{Id: id}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgInitializeCheckout(orderId, status string, inProgress bool) *messages.InitializeCheckout {
|
||||||
|
return &messages.InitializeCheckout{OrderId: orderId, Status: status, PaymentInProgress: inProgress}
|
||||||
|
}
|
||||||
|
|
||||||
|
func msgOrderCreated(orderId, status string) *messages.OrderCreated {
|
||||||
|
return &messages.OrderCreated{OrderId: orderId, Status: status}
|
||||||
|
}
|
||||||
|
|
||||||
|
func ptr[T any](v T) *T { return &v }
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
// Apply helpers
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
func applyOne(t *testing.T, reg actor.MutationRegistry, g *CartGrain, msg proto.Message) actor.ApplyResult {
|
||||||
|
t.Helper()
|
||||||
|
results, err := reg.Apply(g, msg)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected registry-level error applying %T: %v", msg, err)
|
||||||
|
}
|
||||||
|
if len(results) != 1 {
|
||||||
|
t.Fatalf("expected exactly one ApplyResult, got %d", len(results))
|
||||||
|
}
|
||||||
|
return results[0]
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expect success (nil error inside ApplyResult).
|
||||||
|
func applyOK(t *testing.T, reg actor.MutationRegistry, g *CartGrain, msg proto.Message) {
|
||||||
|
t.Helper()
|
||||||
|
res := applyOne(t, reg, g, msg)
|
||||||
|
if res.Error != nil {
|
||||||
|
t.Fatalf("expected mutation %s (%T) to succeed, got error: %v", res.Type, msg, res.Error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Expect an error matching substring.
|
||||||
|
func applyErrorContains(t *testing.T, reg actor.MutationRegistry, g *CartGrain, msg proto.Message, substr string) {
|
||||||
|
t.Helper()
|
||||||
|
res := applyOne(t, reg, g, msg)
|
||||||
|
if res.Error == nil {
|
||||||
|
t.Fatalf("expected error applying %T, got nil", msg)
|
||||||
|
}
|
||||||
|
if substr != "" && !strings.Contains(res.Error.Error(), substr) {
|
||||||
|
t.Fatalf("error mismatch, want substring %q got %q", substr, res.Error.Error())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----------------------
|
||||||
|
// Tests
|
||||||
|
// ----------------------
|
||||||
|
|
||||||
|
func TestMutationRegistryCoverage(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
|
||||||
|
expected := []string{
|
||||||
|
"AddItem",
|
||||||
|
"ChangeQuantity",
|
||||||
|
"RemoveItem",
|
||||||
|
"InitializeCheckout",
|
||||||
|
"OrderCreated",
|
||||||
|
"RemoveDelivery",
|
||||||
|
"SetDelivery",
|
||||||
|
"SetPickupPoint",
|
||||||
|
"ClearCartRequest",
|
||||||
|
"AddVoucher",
|
||||||
|
"RemoveVoucher",
|
||||||
|
"UpsertSubscriptionDetails",
|
||||||
|
}
|
||||||
|
|
||||||
|
names := reg.(*actor.ProtoMutationRegistry).RegisteredMutations()
|
||||||
|
for _, want := range expected {
|
||||||
|
if !slices.Contains(names, want) {
|
||||||
|
t.Fatalf("registry missing mutation %s; got %v", want, names)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create() by name returns correct concrete type.
|
||||||
|
for _, name := range expected {
|
||||||
|
msg, ok := reg.Create(name)
|
||||||
|
if !ok {
|
||||||
|
t.Fatalf("Create failed for %s", name)
|
||||||
|
}
|
||||||
|
rt := reflect.TypeOf(msg)
|
||||||
|
if rt.Kind() == reflect.Ptr {
|
||||||
|
rt = rt.Elem()
|
||||||
|
}
|
||||||
|
if rt.Name() != name {
|
||||||
|
t.Fatalf("Create(%s) returned wrong type %s", name, rt.Name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Unregistered create
|
||||||
|
if m, ok := reg.Create("DoesNotExist"); ok || m != nil {
|
||||||
|
t.Fatalf("Create should fail for unknown; got (%T,%v)", m, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
// GetTypeName sanity
|
||||||
|
add := &messages.AddItem{}
|
||||||
|
nm, ok := reg.GetTypeName(add)
|
||||||
|
if !ok || nm != "AddItem" {
|
||||||
|
t.Fatalf("GetTypeName failed for AddItem, got (%q,%v)", nm, ok)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Apply unregistered message -> result should contain ErrMutationNotRegistered, no top-level error
|
||||||
|
results, err := reg.Apply(newTestGrain(), &messages.Noop{})
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("unexpected top-level error applying unregistered mutation: %v", err)
|
||||||
|
}
|
||||||
|
if len(results) != 1 || results[0].Error == nil || results[0].Error != actor.ErrMutationNotRegistered {
|
||||||
|
t.Fatalf("expected ApplyResult with ErrMutationNotRegistered, got %#v", results)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestAddItemAndMerging(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
// Merge scenario (same SKU + same store pointer)
|
||||||
|
add1 := msgAddItem("SKU-1", 1000, 2, nil)
|
||||||
|
applyOK(t, reg, g, add1)
|
||||||
|
|
||||||
|
if len(g.Items) != 1 || g.Items[0].Quantity != 2 {
|
||||||
|
t.Fatalf("expected first item added; items=%d qty=%d", len(g.Items), g.Items[0].Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgAddItem("SKU-1", 1000, 3, nil)) // should merge
|
||||||
|
if len(g.Items) != 1 || g.Items[0].Quantity != 5 {
|
||||||
|
t.Fatalf("expected merge quantity=5 items=%d qty=%d", len(g.Items), g.Items[0].Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Different store pointer -> new line
|
||||||
|
store := "S1"
|
||||||
|
applyOK(t, reg, g, msgAddItem("SKU-1", 1000, 1, &store))
|
||||||
|
if len(g.Items) != 2 {
|
||||||
|
t.Fatalf("expected second line for different store pointer; items=%d", len(g.Items))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same store pointer & SKU -> merge with second line
|
||||||
|
applyOK(t, reg, g, msgAddItem("SKU-1", 1000, 4, &store))
|
||||||
|
if len(g.Items) != 2 || g.Items[1].Quantity != 5 {
|
||||||
|
t.Fatalf("expected merge on second line; items=%d second.qty=%d", len(g.Items), g.Items[1].Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalid quantity
|
||||||
|
applyErrorContains(t, reg, g, msgAddItem("BAD", 1000, 0, nil), "invalid quantity")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestChangeQuantityBehavior(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgAddItem("A", 1500, 2, nil))
|
||||||
|
id := g.Items[0].Id
|
||||||
|
|
||||||
|
// Increase quantity
|
||||||
|
applyOK(t, reg, g, msgChangeQty(id, 5))
|
||||||
|
if g.Items[0].Quantity != 5 {
|
||||||
|
t.Fatalf("quantity not updated expected=5 got=%d", g.Items[0].Quantity)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove item by setting <=0
|
||||||
|
applyOK(t, reg, g, msgChangeQty(id, 0))
|
||||||
|
if len(g.Items) != 0 {
|
||||||
|
t.Fatalf("expected item removed; items=%d", len(g.Items))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Not found
|
||||||
|
applyErrorContains(t, reg, g, msgChangeQty(9999, 1), "not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestRemoveItemBehavior(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgAddItem("X", 1200, 1, nil))
|
||||||
|
id := g.Items[0].Id
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgRemoveItem(id))
|
||||||
|
if len(g.Items) != 0 {
|
||||||
|
t.Fatalf("expected item removed; items=%d", len(g.Items))
|
||||||
|
}
|
||||||
|
|
||||||
|
applyErrorContains(t, reg, g, msgRemoveItem(id), "not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestDeliveryMutations(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgAddItem("D1", 1000, 1, nil))
|
||||||
|
applyOK(t, reg, g, msgAddItem("D2", 2000, 1, nil))
|
||||||
|
i1 := g.Items[0].Id
|
||||||
|
|
||||||
|
// Explicit items
|
||||||
|
applyOK(t, reg, g, msgSetDelivery("POSTNORD", i1))
|
||||||
|
if len(g.Deliveries) != 1 || len(g.Deliveries[0].Items) != 1 || g.Deliveries[0].Items[0] != i1 {
|
||||||
|
t.Fatalf("delivery not created as expected: %+v", g.Deliveries)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempt to attach an already-delivered item
|
||||||
|
applyErrorContains(t, reg, g, msgSetDelivery("POSTNORD", i1), "already has a delivery")
|
||||||
|
|
||||||
|
// Attach remaining item via empty list (auto include items without delivery)
|
||||||
|
applyOK(t, reg, g, msgSetDelivery("DHL"))
|
||||||
|
if len(g.Deliveries) != 2 {
|
||||||
|
t.Fatalf("expected second delivery; deliveries=%d", len(g.Deliveries))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Non-existent item
|
||||||
|
applyErrorContains(t, reg, g, msgSetDelivery("UPS", 99999), "not found")
|
||||||
|
|
||||||
|
// No eligible items left
|
||||||
|
applyErrorContains(t, reg, g, msgSetDelivery("UPS"), "no eligible items")
|
||||||
|
|
||||||
|
// Set pickup point on first delivery
|
||||||
|
did := g.Deliveries[0].Id
|
||||||
|
applyOK(t, reg, g, msgSetPickupPoint(did, "PP1"))
|
||||||
|
if g.Deliveries[0].PickupPoint == nil || g.Deliveries[0].PickupPoint.Id != "PP1" {
|
||||||
|
t.Fatalf("pickup point not set correctly: %+v", g.Deliveries[0].PickupPoint)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Bad delivery id
|
||||||
|
applyErrorContains(t, reg, g, msgSetPickupPoint(9999, "PPX"), "delivery id")
|
||||||
|
|
||||||
|
// Remove delivery
|
||||||
|
applyOK(t, reg, g, &messages.RemoveDelivery{Id: did})
|
||||||
|
if len(g.Deliveries) != 1 || g.Deliveries[0].Id == did {
|
||||||
|
t.Fatalf("expected first delivery removed, remaining: %+v", g.Deliveries)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove delivery not found
|
||||||
|
applyErrorContains(t, reg, g, &messages.RemoveDelivery{Id: did}, "not found")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestClearCart(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgAddItem("X", 1000, 2, nil))
|
||||||
|
applyOK(t, reg, g, msgSetDelivery("P", g.Items[0].Id))
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgClearCart())
|
||||||
|
|
||||||
|
if len(g.Items) != 0 || len(g.Deliveries) != 0 {
|
||||||
|
t.Fatalf("expected cart cleared; items=%d deliveries=%d", len(g.Items), len(g.Deliveries))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestVoucherMutations(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgAddItem("VOUCH", 10000, 1, nil))
|
||||||
|
applyOK(t, reg, g, msgAddVoucher("PROMO", 5000))
|
||||||
|
|
||||||
|
if len(g.Vouchers) != 1 {
|
||||||
|
t.Fatalf("voucher not stored")
|
||||||
|
}
|
||||||
|
if g.TotalDiscount.IncVat != 5000 {
|
||||||
|
t.Fatalf("expected discount 5000 got %d", g.TotalDiscount.IncVat)
|
||||||
|
}
|
||||||
|
if g.TotalPrice.IncVat != 5000 {
|
||||||
|
t.Fatalf("expected total price 5000 got %d", g.TotalPrice.IncVat)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Duplicate voucher code
|
||||||
|
applyErrorContains(t, reg, g, msgAddVoucher("PROMO", 1000), "already applied")
|
||||||
|
|
||||||
|
// Add a large voucher (should not apply because value > total price)
|
||||||
|
applyOK(t, reg, g, msgAddVoucher("BIG", 100000))
|
||||||
|
if len(g.Vouchers) != 2 {
|
||||||
|
t.Fatalf("expected second voucher stored")
|
||||||
|
}
|
||||||
|
if g.TotalDiscount.IncVat != 5000 || g.TotalPrice.IncVat != 5000 {
|
||||||
|
t.Fatalf("large voucher incorrectly applied discount=%d total=%d",
|
||||||
|
g.TotalDiscount.IncVat, g.TotalPrice.IncVat)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove existing voucher
|
||||||
|
firstId := g.Vouchers[0].Id
|
||||||
|
applyOK(t, reg, g, msgRemoveVoucher(firstId))
|
||||||
|
|
||||||
|
if slices.ContainsFunc(g.Vouchers, func(v *Voucher) bool { return v.Id == firstId }) {
|
||||||
|
t.Fatalf("voucher id %d not removed", firstId)
|
||||||
|
}
|
||||||
|
// After removing PROMO, BIG remains but is not applied (exceeds price)
|
||||||
|
if g.TotalDiscount.IncVat != 0 || g.TotalPrice.IncVat != 10000 {
|
||||||
|
t.Fatalf("totals incorrect after removal discount=%d total=%d",
|
||||||
|
g.TotalDiscount.IncVat, g.TotalPrice.IncVat)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove not applied
|
||||||
|
applyErrorContains(t, reg, g, msgRemoveVoucher(firstId), "not applied")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestCheckoutMutations(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgInitializeCheckout("ORD-1", "PENDING", true))
|
||||||
|
if g.OrderReference != "ORD-1" || g.PaymentStatus != "PENDING" || !g.PaymentInProgress {
|
||||||
|
t.Fatalf("initialize checkout failed: ref=%s status=%s inProgress=%v",
|
||||||
|
g.OrderReference, g.PaymentStatus, g.PaymentInProgress)
|
||||||
|
}
|
||||||
|
|
||||||
|
applyOK(t, reg, g, msgOrderCreated("ORD-1", "COMPLETED"))
|
||||||
|
if g.OrderReference != "ORD-1" || g.PaymentStatus != "COMPLETED" || g.PaymentInProgress {
|
||||||
|
t.Fatalf("order created mutation failed: ref=%s status=%s inProgress=%v",
|
||||||
|
g.OrderReference, g.PaymentStatus, g.PaymentInProgress)
|
||||||
|
}
|
||||||
|
|
||||||
|
applyErrorContains(t, reg, g, msgInitializeCheckout("", "X", true), "missing orderId")
|
||||||
|
applyErrorContains(t, reg, g, msgOrderCreated("", "X"), "missing orderId")
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestSubscriptionDetailsMutation(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
// Upsert new (Id == nil)
|
||||||
|
msgNew := &messages.UpsertSubscriptionDetails{
|
||||||
|
OfferingCode: "OFF1",
|
||||||
|
SigningType: "TYPE1",
|
||||||
|
}
|
||||||
|
applyOK(t, reg, g, msgNew)
|
||||||
|
if len(g.SubscriptionDetails) != 1 {
|
||||||
|
t.Fatalf("expected one subscription detail; got=%d", len(g.SubscriptionDetails))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture created id
|
||||||
|
var createdId string
|
||||||
|
for k := range g.SubscriptionDetails {
|
||||||
|
createdId = k
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update existing
|
||||||
|
msgUpdate := &messages.UpsertSubscriptionDetails{
|
||||||
|
Id: &createdId,
|
||||||
|
OfferingCode: "OFF2",
|
||||||
|
SigningType: "TYPE2",
|
||||||
|
}
|
||||||
|
applyOK(t, reg, g, msgUpdate)
|
||||||
|
if g.SubscriptionDetails[createdId].OfferingCode != "OFF2" ||
|
||||||
|
g.SubscriptionDetails[createdId].SigningType != "TYPE2" {
|
||||||
|
t.Fatalf("subscription details not updated: %+v", g.SubscriptionDetails[createdId])
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update non-existent
|
||||||
|
badId := "NON_EXISTENT"
|
||||||
|
applyErrorContains(t, reg, g, &messages.UpsertSubscriptionDetails{Id: &badId}, "not found")
|
||||||
|
|
||||||
|
// Nil mutation should be ignored and produce zero results.
|
||||||
|
resultsNil, errNil := reg.Apply(g, (*messages.UpsertSubscriptionDetails)(nil))
|
||||||
|
if errNil != nil {
|
||||||
|
t.Fatalf("unexpected error for nil mutation element: %v", errNil)
|
||||||
|
}
|
||||||
|
if len(resultsNil) != 0 {
|
||||||
|
t.Fatalf("expected zero results for nil mutation, got %d", len(resultsNil))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ensure registry Apply handles nil grain and nil message defensive errors consistently.
|
||||||
|
func TestRegistryDefensiveErrors(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
// Nil grain
|
||||||
|
results, err := reg.Apply(nil, &messages.AddItem{})
|
||||||
|
if err == nil {
|
||||||
|
t.Fatalf("expected error for nil grain")
|
||||||
|
}
|
||||||
|
if len(results) != 0 {
|
||||||
|
t.Fatalf("expected no results for nil grain")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Nil message slice
|
||||||
|
results, _ = reg.Apply(g, nil)
|
||||||
|
|
||||||
|
if len(results) != 0 {
|
||||||
|
t.Fatalf("expected no results when message slice nil")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
func TestSubscriptionDetailsJSONValidation(t *testing.T) {
|
||||||
|
reg := newRegistry()
|
||||||
|
g := newTestGrain()
|
||||||
|
|
||||||
|
// Valid JSON on create
|
||||||
|
validCreate := &messages.UpsertSubscriptionDetails{
|
||||||
|
OfferingCode: "OFFJSON",
|
||||||
|
SigningType: "TYPEJSON",
|
||||||
|
Data: &anypb.Any{Value: []byte(`{"ok":true}`)},
|
||||||
|
}
|
||||||
|
applyOK(t, reg, g, validCreate)
|
||||||
|
if len(g.SubscriptionDetails) != 1 {
|
||||||
|
t.Fatalf("expected one subscription detail after valid create, got %d", len(g.SubscriptionDetails))
|
||||||
|
}
|
||||||
|
var id string
|
||||||
|
for k := range g.SubscriptionDetails {
|
||||||
|
id = k
|
||||||
|
}
|
||||||
|
if string(g.SubscriptionDetails[id].Meta) != `{"ok":true}` {
|
||||||
|
t.Fatalf("expected meta stored as valid json, got %s", string(g.SubscriptionDetails[id].Meta))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update with valid JSON replaces meta
|
||||||
|
updateValid := &messages.UpsertSubscriptionDetails{
|
||||||
|
Id: &id,
|
||||||
|
Data: &anypb.Any{Value: []byte(`{"changed":123}`)},
|
||||||
|
}
|
||||||
|
applyOK(t, reg, g, updateValid)
|
||||||
|
if string(g.SubscriptionDetails[id].Meta) != `{"changed":123}` {
|
||||||
|
t.Fatalf("expected meta updated to new json, got %s", string(g.SubscriptionDetails[id].Meta))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalid JSON on create
|
||||||
|
invalidCreate := &messages.UpsertSubscriptionDetails{
|
||||||
|
OfferingCode: "BAD",
|
||||||
|
Data: &anypb.Any{Value: []byte(`{"broken":}`)},
|
||||||
|
}
|
||||||
|
res := applyOne(t, reg, g, invalidCreate)
|
||||||
|
if res.Error == nil || !strings.Contains(res.Error.Error(), "invalid json") {
|
||||||
|
t.Fatalf("expected invalid json error on create, got %v", res.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Invalid JSON on update
|
||||||
|
badUpdate := &messages.UpsertSubscriptionDetails{
|
||||||
|
Id: &id,
|
||||||
|
Data: &anypb.Any{Value: []byte(`{oops`)},
|
||||||
|
}
|
||||||
|
res2 := applyOne(t, reg, g, badUpdate)
|
||||||
|
if res2.Error == nil || !strings.Contains(res2.Error.Error(), "invalid json") {
|
||||||
|
t.Fatalf("expected invalid json error on update, got %v", res2.Error)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty Data.Value should not overwrite existing meta
|
||||||
|
emptyUpdate := &messages.UpsertSubscriptionDetails{
|
||||||
|
Id: &id,
|
||||||
|
Data: &anypb.Any{Value: []byte{}},
|
||||||
|
}
|
||||||
|
applyOK(t, reg, g, emptyUpdate)
|
||||||
|
if string(g.SubscriptionDetails[id].Meta) != `{"changed":123}` {
|
||||||
|
t.Fatalf("empty update should not change meta, got %s", string(g.SubscriptionDetails[id].Meta))
|
||||||
|
}
|
||||||
|
}
|
||||||
57
pkg/cart/mutation_upsert_subscriptiondetails.go
Normal file
57
pkg/cart/mutation_upsert_subscriptiondetails.go
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
package cart
|
||||||
|
|
||||||
|
import (
|
||||||
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
messages "git.tornberg.me/go-cart-actor/pkg/messages"
|
||||||
|
)
|
||||||
|
|
||||||
|
func UpsertSubscriptionDetails(g *CartGrain, m *messages.UpsertSubscriptionDetails) error {
|
||||||
|
if m == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create new subscription details when Id is nil.
|
||||||
|
if m.Id == nil {
|
||||||
|
// Validate JSON if provided.
|
||||||
|
var meta json.RawMessage
|
||||||
|
if m.Data != nil && len(m.Data.Value) > 0 {
|
||||||
|
if !json.Valid(m.Data.Value) {
|
||||||
|
return fmt.Errorf("subscription details invalid json")
|
||||||
|
}
|
||||||
|
meta = json.RawMessage(m.Data.Value)
|
||||||
|
}
|
||||||
|
|
||||||
|
id := MustNewCartId().String()
|
||||||
|
g.SubscriptionDetails[id] = &SubscriptionDetails{
|
||||||
|
Id: id,
|
||||||
|
OfferingCode: m.OfferingCode,
|
||||||
|
SigningType: m.SigningType,
|
||||||
|
Meta: meta,
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update existing entry.
|
||||||
|
existing, ok := g.SubscriptionDetails[*m.Id]
|
||||||
|
if !ok {
|
||||||
|
return fmt.Errorf("subscription details not found")
|
||||||
|
}
|
||||||
|
if m.OfferingCode != "" {
|
||||||
|
existing.OfferingCode = m.OfferingCode
|
||||||
|
}
|
||||||
|
if m.SigningType != "" {
|
||||||
|
existing.SigningType = m.SigningType
|
||||||
|
}
|
||||||
|
if m.Data != nil {
|
||||||
|
// Only validate & assign if there is content; empty -> leave as-is.
|
||||||
|
if len(m.Data.Value) > 0 {
|
||||||
|
if !json.Valid(m.Data.Value) {
|
||||||
|
return fmt.Errorf("subscription details invalid json")
|
||||||
|
}
|
||||||
|
existing.Meta = m.Data.Value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package main
|
package cart
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
@@ -33,14 +33,14 @@ func TestPriceMarshalJSON(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestNewPriceFromIncVat(t *testing.T) {
|
func TestNewPriceFromIncVat(t *testing.T) {
|
||||||
p := NewPriceFromIncVat(1000, 0.25)
|
p := NewPriceFromIncVat(1250, 25)
|
||||||
if p.IncVat != 1000 {
|
if p.IncVat != 1250 {
|
||||||
t.Fatalf("expected IncVat %d got %d", 1000, p.IncVat)
|
t.Fatalf("expected IncVat %d got %d", 1250, p.IncVat)
|
||||||
}
|
}
|
||||||
if p.VatRates[25] != 250 {
|
if p.VatRates[25] != 250 {
|
||||||
t.Fatalf("expected VAT 25 rate %d got %d", 250, p.VatRates[25])
|
t.Fatalf("expected VAT 25 rate %d got %d", 250, p.VatRates[25])
|
||||||
}
|
}
|
||||||
if p.ValueExVat() != 750 {
|
if p.ValueExVat() != 1000 {
|
||||||
t.Fatalf("expected exVat %d got %d", 750, p.ValueExVat())
|
t.Fatalf("expected exVat %d got %d", 750, p.ValueExVat())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,7 @@ package messages
|
|||||||
import (
|
import (
|
||||||
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
|
||||||
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
|
||||||
|
anypb "google.golang.org/protobuf/types/known/anypb"
|
||||||
reflect "reflect"
|
reflect "reflect"
|
||||||
sync "sync"
|
sync "sync"
|
||||||
unsafe "unsafe"
|
unsafe "unsafe"
|
||||||
@@ -79,6 +80,7 @@ type AddItem struct {
|
|||||||
SellerId string `protobuf:"bytes,19,opt,name=sellerId,proto3" json:"sellerId,omitempty"`
|
SellerId string `protobuf:"bytes,19,opt,name=sellerId,proto3" json:"sellerId,omitempty"`
|
||||||
SellerName string `protobuf:"bytes,20,opt,name=sellerName,proto3" json:"sellerName,omitempty"`
|
SellerName string `protobuf:"bytes,20,opt,name=sellerName,proto3" json:"sellerName,omitempty"`
|
||||||
Country string `protobuf:"bytes,21,opt,name=country,proto3" json:"country,omitempty"`
|
Country string `protobuf:"bytes,21,opt,name=country,proto3" json:"country,omitempty"`
|
||||||
|
SaleStatus string `protobuf:"bytes,24,opt,name=saleStatus,proto3" json:"saleStatus,omitempty"`
|
||||||
Outlet *string `protobuf:"bytes,12,opt,name=outlet,proto3,oneof" json:"outlet,omitempty"`
|
Outlet *string `protobuf:"bytes,12,opt,name=outlet,proto3,oneof" json:"outlet,omitempty"`
|
||||||
StoreId *string `protobuf:"bytes,22,opt,name=storeId,proto3,oneof" json:"storeId,omitempty"`
|
StoreId *string `protobuf:"bytes,22,opt,name=storeId,proto3,oneof" json:"storeId,omitempty"`
|
||||||
ParentId *uint32 `protobuf:"varint,23,opt,name=parentId,proto3,oneof" json:"parentId,omitempty"`
|
ParentId *uint32 `protobuf:"varint,23,opt,name=parentId,proto3,oneof" json:"parentId,omitempty"`
|
||||||
@@ -256,6 +258,13 @@ func (x *AddItem) GetCountry() string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (x *AddItem) GetSaleStatus() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.SaleStatus
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
func (x *AddItem) GetOutlet() string {
|
func (x *AddItem) GetOutlet() string {
|
||||||
if x != nil && x.Outlet != nil {
|
if x != nil && x.Outlet != nil {
|
||||||
return *x.Outlet
|
return *x.Outlet
|
||||||
@@ -1089,152 +1098,234 @@ func (x *RemoveVoucher) GetId() uint32 {
|
|||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type UpsertSubscriptionDetails struct {
|
||||||
|
state protoimpl.MessageState `protogen:"open.v1"`
|
||||||
|
Id *string `protobuf:"bytes,1,opt,name=id,proto3,oneof" json:"id,omitempty"`
|
||||||
|
OfferingCode string `protobuf:"bytes,2,opt,name=offeringCode,proto3" json:"offeringCode,omitempty"`
|
||||||
|
SigningType string `protobuf:"bytes,3,opt,name=signingType,proto3" json:"signingType,omitempty"`
|
||||||
|
Data *anypb.Any `protobuf:"bytes,4,opt,name=data,proto3" json:"data,omitempty"`
|
||||||
|
unknownFields protoimpl.UnknownFields
|
||||||
|
sizeCache protoimpl.SizeCache
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) Reset() {
|
||||||
|
*x = UpsertSubscriptionDetails{}
|
||||||
|
mi := &file_messages_proto_msgTypes[15]
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) String() string {
|
||||||
|
return protoimpl.X.MessageStringOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (*UpsertSubscriptionDetails) ProtoMessage() {}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) ProtoReflect() protoreflect.Message {
|
||||||
|
mi := &file_messages_proto_msgTypes[15]
|
||||||
|
if x != nil {
|
||||||
|
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||||
|
if ms.LoadMessageInfo() == nil {
|
||||||
|
ms.StoreMessageInfo(mi)
|
||||||
|
}
|
||||||
|
return ms
|
||||||
|
}
|
||||||
|
return mi.MessageOf(x)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Deprecated: Use UpsertSubscriptionDetails.ProtoReflect.Descriptor instead.
|
||||||
|
func (*UpsertSubscriptionDetails) Descriptor() ([]byte, []int) {
|
||||||
|
return file_messages_proto_rawDescGZIP(), []int{15}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) GetId() string {
|
||||||
|
if x != nil && x.Id != nil {
|
||||||
|
return *x.Id
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) GetOfferingCode() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.OfferingCode
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) GetSigningType() string {
|
||||||
|
if x != nil {
|
||||||
|
return x.SigningType
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
|
func (x *UpsertSubscriptionDetails) GetData() *anypb.Any {
|
||||||
|
if x != nil {
|
||||||
|
return x.Data
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
var File_messages_proto protoreflect.FileDescriptor
|
var File_messages_proto protoreflect.FileDescriptor
|
||||||
|
|
||||||
var file_messages_proto_rawDesc = string([]byte{
|
var file_messages_proto_rawDesc = string([]byte{
|
||||||
0x0a, 0x0e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
0x0a, 0x0e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
0x12, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x22, 0x12, 0x0a, 0x10, 0x43, 0x6c,
|
0x12, 0x08, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x1a, 0x19, 0x67, 0x6f, 0x6f, 0x67,
|
||||||
0x65, 0x61, 0x72, 0x43, 0x61, 0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x97,
|
0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x61, 0x6e, 0x79, 0x2e,
|
||||||
0x05, 0x0a, 0x07, 0x41, 0x64, 0x64, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x74,
|
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x12, 0x0a, 0x10, 0x43, 0x6c, 0x65, 0x61, 0x72, 0x43, 0x61,
|
||||||
0x65, 0x6d, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x74, 0x65,
|
0x72, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0xb7, 0x05, 0x0a, 0x07, 0x41, 0x64,
|
||||||
0x6d, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18,
|
0x64, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x74, 0x65, 0x6d, 0x5f, 0x69, 0x64,
|
||||||
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x06, 0x69, 0x74, 0x65, 0x6d, 0x49, 0x64, 0x12, 0x1a,
|
||||||
0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05,
|
0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05,
|
||||||
0x70, 0x72, 0x69, 0x63, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x72, 0x67, 0x50, 0x72, 0x69, 0x63,
|
0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72,
|
||||||
0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x6f, 0x72, 0x67, 0x50, 0x72, 0x69, 0x63,
|
0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65,
|
||||||
0x65, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x6b, 0x75, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03,
|
0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x72, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x09, 0x20, 0x01,
|
||||||
0x73, 0x6b, 0x75, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28,
|
0x28, 0x03, 0x52, 0x08, 0x6f, 0x72, 0x67, 0x50, 0x72, 0x69, 0x63, 0x65, 0x12, 0x10, 0x0a, 0x03,
|
||||||
0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65,
|
0x73, 0x6b, 0x75, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x73, 0x6b, 0x75, 0x12, 0x12,
|
||||||
0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a,
|
0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61,
|
||||||
0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74,
|
0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28,
|
||||||
0x6f, 0x63, 0x6b, 0x12, 0x10, 0x0a, 0x03, 0x74, 0x61, 0x78, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05,
|
0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x6f, 0x63,
|
||||||
0x52, 0x03, 0x74, 0x61, 0x78, 0x12, 0x14, 0x0a, 0x05, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x18, 0x0d,
|
0x6b, 0x18, 0x07, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x73, 0x74, 0x6f, 0x63, 0x6b, 0x12, 0x10,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63,
|
0x0a, 0x03, 0x74, 0x61, 0x78, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x74, 0x61, 0x78,
|
||||||
0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63,
|
0x12, 0x14, 0x0a, 0x05, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67,
|
0x05, 0x62, 0x72, 0x61, 0x6e, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f,
|
||||||
0x6f, 0x72, 0x79, 0x32, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65,
|
0x72, 0x79, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f,
|
||||||
0x67, 0x6f, 0x72, 0x79, 0x32, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72,
|
0x72, 0x79, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x32, 0x18,
|
||||||
0x79, 0x33, 0x18, 0x10, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f,
|
0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x32,
|
||||||
0x72, 0x79, 0x33, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x34,
|
0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x33, 0x18, 0x10, 0x20,
|
||||||
0x18, 0x11, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79,
|
0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x33, 0x12, 0x1c,
|
||||||
0x34, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x35, 0x18, 0x12,
|
0x0a, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x34, 0x18, 0x11, 0x20, 0x01, 0x28,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x35, 0x12,
|
0x09, 0x52, 0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x34, 0x12, 0x1c, 0x0a, 0x09,
|
||||||
0x1e, 0x0a, 0x0a, 0x64, 0x69, 0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x18, 0x0a, 0x20,
|
0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x35, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x0a, 0x64, 0x69, 0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x12,
|
0x09, 0x63, 0x61, 0x74, 0x65, 0x67, 0x6f, 0x72, 0x79, 0x35, 0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x69,
|
||||||
0x20, 0x0a, 0x0b, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0b,
|
0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x54, 0x79, 0x70,
|
0x64, 0x69, 0x73, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x65, 0x72, 0x12, 0x20, 0x0a, 0x0b, 0x61, 0x72,
|
||||||
0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x18, 0x13, 0x20,
|
0x74, 0x69, 0x63, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a,
|
0x0b, 0x61, 0x72, 0x74, 0x69, 0x63, 0x6c, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08,
|
||||||
0x0a, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28,
|
0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08,
|
||||||
0x09, 0x52, 0x0a, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a,
|
0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x65, 0x6c, 0x6c,
|
||||||
0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07,
|
0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x65,
|
||||||
0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x1b, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x6c, 0x65,
|
0x6c, 0x6c, 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e,
|
||||||
0x74, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x6c, 0x65,
|
0x74, 0x72, 0x79, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74,
|
||||||
0x74, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18,
|
0x72, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x73, 0x61, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73,
|
||||||
0x16, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64,
|
0x18, 0x18, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x61, 0x6c, 0x65, 0x53, 0x74, 0x61, 0x74,
|
||||||
0x88, 0x01, 0x01, 0x12, 0x1f, 0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18,
|
0x75, 0x73, 0x12, 0x1b, 0x0a, 0x06, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x18, 0x0c, 0x20, 0x01,
|
||||||
0x17, 0x20, 0x01, 0x28, 0x0d, 0x48, 0x02, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49,
|
0x28, 0x09, 0x48, 0x00, 0x52, 0x06, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x88, 0x01, 0x01, 0x12,
|
||||||
0x64, 0x88, 0x01, 0x01, 0x42, 0x09, 0x0a, 0x07, 0x5f, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x42,
|
0x1d, 0x0a, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x18, 0x16, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x0a, 0x0a, 0x08, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x42, 0x0b, 0x0a, 0x09, 0x5f,
|
0x48, 0x01, 0x52, 0x07, 0x73, 0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x88, 0x01, 0x01, 0x12, 0x1f,
|
||||||
0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x1c, 0x0a, 0x0a, 0x52, 0x65, 0x6d, 0x6f,
|
0x0a, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x18, 0x17, 0x20, 0x01, 0x28, 0x0d,
|
||||||
0x76, 0x65, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01,
|
0x48, 0x02, 0x52, 0x08, 0x70, 0x61, 0x72, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x88, 0x01, 0x01, 0x42,
|
||||||
0x28, 0x0d, 0x52, 0x02, 0x49, 0x64, 0x22, 0x3c, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65,
|
0x09, 0x0a, 0x07, 0x5f, 0x6f, 0x75, 0x74, 0x6c, 0x65, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x73,
|
||||||
0x51, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01,
|
0x74, 0x6f, 0x72, 0x65, 0x49, 0x64, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x70, 0x61, 0x72, 0x65, 0x6e,
|
||||||
0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e,
|
0x74, 0x49, 0x64, 0x22, 0x1c, 0x0a, 0x0a, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x49, 0x74, 0x65,
|
||||||
0x74, 0x69, 0x74, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e,
|
0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x49,
|
||||||
0x74, 0x69, 0x74, 0x79, 0x22, 0x86, 0x02, 0x0a, 0x0b, 0x53, 0x65, 0x74, 0x44, 0x65, 0x6c, 0x69,
|
0x64, 0x22, 0x3c, 0x0a, 0x0e, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x51, 0x75, 0x61, 0x6e, 0x74,
|
||||||
0x76, 0x65, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
|
0x69, 0x74, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||||
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72,
|
0x02, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x18,
|
||||||
0x12, 0x14, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x52,
|
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x22,
|
||||||
0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x12, 0x3c, 0x0a, 0x0b, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70,
|
0x86, 0x02, 0x0a, 0x0b, 0x53, 0x65, 0x74, 0x44, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x12,
|
||||||
0x50, 0x6f, 0x69, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65,
|
0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28,
|
||||||
0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69,
|
0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x69,
|
||||||
0x6e, 0x74, 0x48, 0x00, 0x52, 0x0b, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e,
|
0x74, 0x65, 0x6d, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0d, 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d,
|
||||||
0x74, 0x88, 0x01, 0x01, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18,
|
0x73, 0x12, 0x3c, 0x0a, 0x0b, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74,
|
||||||
0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10,
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65,
|
||||||
0x0a, 0x03, 0x7a, 0x69, 0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x7a, 0x69, 0x70,
|
0x73, 0x2e, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x48, 0x00, 0x52,
|
||||||
0x12, 0x1d, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28,
|
0x0b, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x88, 0x01, 0x01, 0x12,
|
||||||
0x09, 0x48, 0x01, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x12,
|
0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x17, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52,
|
0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x7a, 0x69, 0x70,
|
||||||
0x04, 0x63, 0x69, 0x74, 0x79, 0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x70, 0x69, 0x63,
|
0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x7a, 0x69, 0x70, 0x12, 0x1d, 0x0a, 0x07, 0x61,
|
||||||
0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64, 0x64,
|
0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07,
|
||||||
0x72, 0x65, 0x73, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, 0x22, 0xf9, 0x01,
|
0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x69,
|
||||||
0x0a, 0x0e, 0x53, 0x65, 0x74, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74,
|
0x74, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79,
|
||||||
0x12, 0x1e, 0x0a, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x49, 0x64, 0x18, 0x01,
|
0x88, 0x01, 0x01, 0x42, 0x0e, 0x0a, 0x0c, 0x5f, 0x70, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f,
|
||||||
0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x49, 0x64,
|
0x69, 0x6e, 0x74, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42,
|
||||||
0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64,
|
0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, 0x22, 0xf9, 0x01, 0x0a, 0x0e, 0x53, 0x65, 0x74,
|
||||||
0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00,
|
0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x64,
|
||||||
0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x61, 0x64, 0x64,
|
0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
|
||||||
0x72, 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07, 0x61, 0x64,
|
0x0a, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x49, 0x64, 0x12, 0x0e, 0x0a, 0x02, 0x69,
|
||||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79,
|
0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, 0x6e,
|
||||||
0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x88, 0x01,
|
0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d,
|
||||||
0x01, 0x12, 0x15, 0x0a, 0x03, 0x7a, 0x69, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x03,
|
0x65, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18,
|
||||||
0x52, 0x03, 0x7a, 0x69, 0x70, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e,
|
0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
|
||||||
0x74, 0x72, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x48, 0x04, 0x52, 0x07, 0x63, 0x6f, 0x75,
|
0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, 0x18, 0x05, 0x20, 0x01, 0x28,
|
||||||
0x6e, 0x74, 0x72, 0x79, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65,
|
0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x88, 0x01, 0x01, 0x12, 0x15, 0x0a, 0x03,
|
||||||
0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0x07, 0x0a, 0x05,
|
0x7a, 0x69, 0x70, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x03, 0x52, 0x03, 0x7a, 0x69, 0x70,
|
||||||
0x5f, 0x63, 0x69, 0x74, 0x79, 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x7a, 0x69, 0x70, 0x42, 0x0a, 0x0a,
|
0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x07,
|
||||||
0x08, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x22, 0xd6, 0x01, 0x0a, 0x0b, 0x50, 0x69,
|
0x20, 0x01, 0x28, 0x09, 0x48, 0x04, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x88,
|
||||||
0x63, 0x6b, 0x75, 0x70, 0x50, 0x6f, 0x69, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18,
|
0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x5f,
|
||||||
0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, 0x6d,
|
0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79,
|
||||||
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x88,
|
0x42, 0x06, 0x0a, 0x04, 0x5f, 0x7a, 0x69, 0x70, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x63, 0x6f, 0x75,
|
||||||
0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20,
|
0x6e, 0x74, 0x72, 0x79, 0x22, 0xd6, 0x01, 0x0a, 0x0b, 0x50, 0x69, 0x63, 0x6b, 0x75, 0x70, 0x50,
|
||||||
0x01, 0x28, 0x09, 0x48, 0x01, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01,
|
0x6f, 0x69, 0x6e, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
|
||||||
0x01, 0x12, 0x17, 0x0a, 0x04, 0x63, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48,
|
0x52, 0x02, 0x69, 0x64, 0x12, 0x17, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01,
|
||||||
0x02, 0x52, 0x04, 0x63, 0x69, 0x74, 0x79, 0x88, 0x01, 0x01, 0x12, 0x15, 0x0a, 0x03, 0x7a, 0x69,
|
0x28, 0x09, 0x48, 0x00, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a,
|
||||||
0x70, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x48, 0x03, 0x52, 0x03, 0x7a, 0x69, 0x70, 0x88, 0x01,
|
0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x48, 0x01,
|
||||||
0x01, 0x12, 0x1d, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01,
|
0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x88, 0x01, 0x01, 0x12, 0x17, 0x0a, 0x04,
|
||||||
0x28, 0x09, 0x48, 0x04, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x88, 0x01, 0x01,
|
0x63, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x48, 0x02, 0x52, 0x04, 0x63, 0x69,
|
||||||
0x42, 0x07, 0x0a, 0x05, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64,
|
0x74, 0x79, 0x88, 0x01, 0x01, 0x12, 0x15, 0x0a, 0x03, 0x7a, 0x69, 0x70, 0x18, 0x05, 0x20, 0x01,
|
||||||
0x64, 0x72, 0x65, 0x73, 0x73, 0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, 0x42, 0x06,
|
0x28, 0x09, 0x48, 0x03, 0x52, 0x03, 0x7a, 0x69, 0x70, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x07,
|
||||||
0x0a, 0x04, 0x5f, 0x7a, 0x69, 0x70, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74,
|
0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x48, 0x04, 0x52,
|
||||||
0x72, 0x79, 0x22, 0x20, 0x0a, 0x0e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x44, 0x65, 0x6c, 0x69,
|
0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x88, 0x01, 0x01, 0x42, 0x07, 0x0a, 0x05, 0x5f,
|
||||||
0x76, 0x65, 0x72, 0x79, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d,
|
0x6e, 0x61, 0x6d, 0x65, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73,
|
||||||
0x52, 0x02, 0x69, 0x64, 0x22, 0xb9, 0x01, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43,
|
0x42, 0x07, 0x0a, 0x05, 0x5f, 0x63, 0x69, 0x74, 0x79, 0x42, 0x06, 0x0a, 0x04, 0x5f, 0x7a, 0x69,
|
||||||
0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05,
|
0x70, 0x42, 0x0a, 0x0a, 0x08, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x22, 0x20, 0x0a,
|
||||||
0x74, 0x65, 0x72, 0x6d, 0x73, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x65, 0x72,
|
0x0e, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x44, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x12,
|
||||||
0x6d, 0x73, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x18, 0x02,
|
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x22,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x12, 0x22,
|
0xb9, 0x01, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x6f,
|
||||||
0x0a, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03,
|
0x75, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x65, 0x72, 0x6d, 0x73,
|
||||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x65, 0x72, 0x6d, 0x73, 0x12, 0x1a, 0x0a,
|
||||||
0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x70, 0x75, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09,
|
0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x52, 0x04, 0x70, 0x75, 0x73, 0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61,
|
0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x6f, 0x6e,
|
||||||
0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69,
|
0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52,
|
||||||
0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72,
|
0x0c, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a,
|
||||||
0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79,
|
0x04, 0x70, 0x75, 0x73, 0x68, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x70, 0x75, 0x73,
|
||||||
0x22, 0x40, 0x0a, 0x0c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64,
|
0x68, 0x12, 0x1e, 0x0a, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18,
|
||||||
0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x76, 0x61, 0x6c, 0x69, 0x64, 0x61, 0x74, 0x69, 0x6f,
|
||||||
0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74,
|
0x6e, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01,
|
||||||
0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74,
|
0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x72, 0x79, 0x22, 0x40, 0x0a, 0x0c, 0x4f,
|
||||||
0x75, 0x73, 0x22, 0x06, 0x0a, 0x04, 0x4e, 0x6f, 0x6f, 0x70, 0x22, 0x74, 0x0a, 0x12, 0x49, 0x6e,
|
0x72, 0x64, 0x65, 0x72, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x6f,
|
||||||
0x69, 0x74, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74,
|
0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72,
|
||||||
0x12, 0x18, 0x0a, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28,
|
0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18,
|
||||||
0x09, 0x52, 0x07, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74,
|
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x22, 0x06, 0x0a,
|
||||||
0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74,
|
0x04, 0x4e, 0x6f, 0x6f, 0x70, 0x22, 0x74, 0x0a, 0x12, 0x49, 0x6e, 0x69, 0x74, 0x69, 0x61, 0x6c,
|
||||||
0x75, 0x73, 0x12, 0x2c, 0x0a, 0x11, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x50,
|
0x69, 0x7a, 0x65, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x6f, 0x75, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x6f,
|
||||||
0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x70,
|
0x72, 0x64, 0x65, 0x72, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x72,
|
||||||
0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73,
|
0x64, 0x65, 0x72, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18,
|
||||||
0x22, 0x79, 0x0a, 0x0b, 0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x12,
|
0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2c, 0x0a,
|
||||||
0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74,
|
0x11, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x49, 0x6e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65,
|
||||||
0x79, 0x70, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69,
|
0x73, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e,
|
||||||
0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69,
|
0x74, 0x49, 0x6e, 0x50, 0x72, 0x6f, 0x67, 0x72, 0x65, 0x73, 0x73, 0x22, 0x79, 0x0a, 0x0b, 0x56,
|
||||||
0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69,
|
0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79,
|
||||||
0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74,
|
0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x20,
|
||||||
0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20,
|
0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20,
|
||||||
0x01, 0x28, 0x09, 0x52, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x71, 0x0a, 0x0a, 0x41,
|
0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e,
|
||||||
0x64, 0x64, 0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64,
|
0x12, 0x1c, 0x0a, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20,
|
||||||
0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a,
|
0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x16,
|
||||||
0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61,
|
0x0a, 0x06, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06,
|
||||||
0x6c, 0x75, 0x65, 0x12, 0x39, 0x0a, 0x0c, 0x76, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75,
|
0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x71, 0x0a, 0x0a, 0x41, 0x64, 0x64, 0x56, 0x6f, 0x75,
|
||||||
0x6c, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65, 0x73, 0x73,
|
0x63, 0x68, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x01, 0x20, 0x01,
|
||||||
0x61, 0x67, 0x65, 0x73, 0x2e, 0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65,
|
0x28, 0x09, 0x52, 0x04, 0x63, 0x6f, 0x64, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
|
||||||
0x52, 0x0c, 0x76, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x22, 0x1f,
|
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x39,
|
||||||
0x0a, 0x0d, 0x52, 0x65, 0x6d, 0x6f, 0x76, 0x65, 0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x12,
|
0x0a, 0x0c, 0x76, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x18, 0x03,
|
||||||
0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x42,
|
0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x2e,
|
||||||
0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x2e, 0x74, 0x6f, 0x72, 0x6e, 0x62, 0x65, 0x72, 0x67, 0x2e,
|
0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x52, 0x0c, 0x76, 0x6f, 0x75,
|
||||||
0x6d, 0x65, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x61, 0x72, 0x74, 0x2d, 0x61, 0x63, 0x74, 0x6f, 0x72,
|
0x63, 0x68, 0x65, 0x72, 0x52, 0x75, 0x6c, 0x65, 0x73, 0x22, 0x1f, 0x0a, 0x0d, 0x52, 0x65, 0x6d,
|
||||||
0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x73, 0x62,
|
0x6f, 0x76, 0x65, 0x56, 0x6f, 0x75, 0x63, 0x68, 0x65, 0x72, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64,
|
||||||
0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x22, 0xa7, 0x01, 0x0a, 0x19, 0x55,
|
||||||
|
0x70, 0x73, 0x65, 0x72, 0x74, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f,
|
||||||
|
0x6e, 0x44, 0x65, 0x74, 0x61, 0x69, 0x6c, 0x73, 0x12, 0x13, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
|
||||||
|
0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x02, 0x69, 0x64, 0x88, 0x01, 0x01, 0x12, 0x22, 0x0a,
|
||||||
|
0x0c, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20,
|
||||||
|
0x01, 0x28, 0x09, 0x52, 0x0c, 0x6f, 0x66, 0x66, 0x65, 0x72, 0x69, 0x6e, 0x67, 0x43, 0x6f, 0x64,
|
||||||
|
0x65, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x54, 0x79, 0x70, 0x65,
|
||||||
|
0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x54,
|
||||||
|
0x79, 0x70, 0x65, 0x12, 0x28, 0x0a, 0x04, 0x64, 0x61, 0x74, 0x61, 0x18, 0x04, 0x20, 0x01, 0x28,
|
||||||
|
0x0b, 0x32, 0x14, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||||
|
0x62, 0x75, 0x66, 0x2e, 0x41, 0x6e, 0x79, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x42, 0x05, 0x0a,
|
||||||
|
0x03, 0x5f, 0x69, 0x64, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x2e, 0x74, 0x6f, 0x72, 0x6e,
|
||||||
|
0x62, 0x65, 0x72, 0x67, 0x2e, 0x6d, 0x65, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x61, 0x72, 0x74, 0x2d,
|
||||||
|
0x61, 0x63, 0x74, 0x6f, 0x72, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x3b, 0x6d, 0x65, 0x73, 0x73,
|
||||||
|
0x61, 0x67, 0x65, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||||
})
|
})
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@@ -1249,7 +1340,7 @@ func file_messages_proto_rawDescGZIP() []byte {
|
|||||||
return file_messages_proto_rawDescData
|
return file_messages_proto_rawDescData
|
||||||
}
|
}
|
||||||
|
|
||||||
var file_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 15)
|
var file_messages_proto_msgTypes = make([]protoimpl.MessageInfo, 16)
|
||||||
var file_messages_proto_goTypes = []any{
|
var file_messages_proto_goTypes = []any{
|
||||||
(*ClearCartRequest)(nil), // 0: messages.ClearCartRequest
|
(*ClearCartRequest)(nil), // 0: messages.ClearCartRequest
|
||||||
(*AddItem)(nil), // 1: messages.AddItem
|
(*AddItem)(nil), // 1: messages.AddItem
|
||||||
@@ -1266,15 +1357,18 @@ var file_messages_proto_goTypes = []any{
|
|||||||
(*VoucherRule)(nil), // 12: messages.VoucherRule
|
(*VoucherRule)(nil), // 12: messages.VoucherRule
|
||||||
(*AddVoucher)(nil), // 13: messages.AddVoucher
|
(*AddVoucher)(nil), // 13: messages.AddVoucher
|
||||||
(*RemoveVoucher)(nil), // 14: messages.RemoveVoucher
|
(*RemoveVoucher)(nil), // 14: messages.RemoveVoucher
|
||||||
|
(*UpsertSubscriptionDetails)(nil), // 15: messages.UpsertSubscriptionDetails
|
||||||
|
(*anypb.Any)(nil), // 16: google.protobuf.Any
|
||||||
}
|
}
|
||||||
var file_messages_proto_depIdxs = []int32{
|
var file_messages_proto_depIdxs = []int32{
|
||||||
6, // 0: messages.SetDelivery.pickupPoint:type_name -> messages.PickupPoint
|
6, // 0: messages.SetDelivery.pickupPoint:type_name -> messages.PickupPoint
|
||||||
12, // 1: messages.AddVoucher.voucherRules:type_name -> messages.VoucherRule
|
12, // 1: messages.AddVoucher.voucherRules:type_name -> messages.VoucherRule
|
||||||
2, // [2:2] is the sub-list for method output_type
|
16, // 2: messages.UpsertSubscriptionDetails.data:type_name -> google.protobuf.Any
|
||||||
2, // [2:2] is the sub-list for method input_type
|
3, // [3:3] is the sub-list for method output_type
|
||||||
2, // [2:2] is the sub-list for extension type_name
|
3, // [3:3] is the sub-list for method input_type
|
||||||
2, // [2:2] is the sub-list for extension extendee
|
3, // [3:3] is the sub-list for extension type_name
|
||||||
0, // [0:2] is the sub-list for field type_name
|
3, // [3:3] is the sub-list for extension extendee
|
||||||
|
0, // [0:3] is the sub-list for field type_name
|
||||||
}
|
}
|
||||||
|
|
||||||
func init() { file_messages_proto_init() }
|
func init() { file_messages_proto_init() }
|
||||||
@@ -1286,13 +1380,14 @@ func file_messages_proto_init() {
|
|||||||
file_messages_proto_msgTypes[4].OneofWrappers = []any{}
|
file_messages_proto_msgTypes[4].OneofWrappers = []any{}
|
||||||
file_messages_proto_msgTypes[5].OneofWrappers = []any{}
|
file_messages_proto_msgTypes[5].OneofWrappers = []any{}
|
||||||
file_messages_proto_msgTypes[6].OneofWrappers = []any{}
|
file_messages_proto_msgTypes[6].OneofWrappers = []any{}
|
||||||
|
file_messages_proto_msgTypes[15].OneofWrappers = []any{}
|
||||||
type x struct{}
|
type x struct{}
|
||||||
out := protoimpl.TypeBuilder{
|
out := protoimpl.TypeBuilder{
|
||||||
File: protoimpl.DescBuilder{
|
File: protoimpl.DescBuilder{
|
||||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||||
RawDescriptor: unsafe.Slice(unsafe.StringData(file_messages_proto_rawDesc), len(file_messages_proto_rawDesc)),
|
RawDescriptor: unsafe.Slice(unsafe.StringData(file_messages_proto_rawDesc), len(file_messages_proto_rawDesc)),
|
||||||
NumEnums: 0,
|
NumEnums: 0,
|
||||||
NumMessages: 15,
|
NumMessages: 16,
|
||||||
NumExtensions: 0,
|
NumExtensions: 0,
|
||||||
NumServices: 0,
|
NumServices: 0,
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -21,7 +21,6 @@ type Voucher struct {
|
|||||||
|
|
||||||
type Service struct {
|
type Service struct {
|
||||||
// Add fields here
|
// Add fields here
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ErrInvalidCode = errors.New("invalid vouchercode")
|
var ErrInvalidCode = errors.New("invalid vouchercode")
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ syntax = "proto3";
|
|||||||
package messages;
|
package messages;
|
||||||
option go_package = "git.tornberg.me/go-cart-actor/proto;messages";
|
option go_package = "git.tornberg.me/go-cart-actor/proto;messages";
|
||||||
|
|
||||||
|
import "google/protobuf/any.proto";
|
||||||
|
|
||||||
message ClearCartRequest {
|
message ClearCartRequest {
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -27,6 +29,7 @@ message AddItem {
|
|||||||
string sellerId = 19;
|
string sellerId = 19;
|
||||||
string sellerName = 20;
|
string sellerName = 20;
|
||||||
string country = 21;
|
string country = 21;
|
||||||
|
string saleStatus = 24;
|
||||||
optional string outlet = 12;
|
optional string outlet = 12;
|
||||||
optional string storeId = 22;
|
optional string storeId = 22;
|
||||||
optional uint32 parentId = 23;
|
optional uint32 parentId = 23;
|
||||||
@@ -114,3 +117,12 @@ message AddVoucher {
|
|||||||
message RemoveVoucher {
|
message RemoveVoucher {
|
||||||
uint32 id = 1;
|
uint32 id = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
message UpsertSubscriptionDetails {
|
||||||
|
|
||||||
|
optional string id = 1;
|
||||||
|
string offeringCode = 2;
|
||||||
|
string signingType = 3;
|
||||||
|
google.protobuf.Any data = 4;
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user