syntax = "proto3"; package messages; option go_package = "git.tornberg.me/go-cart-actor/proto;messages"; import "messages.proto"; // ----------------------------------------------------------------------------- // Cart Actor gRPC API (oneof Envelope Variant) // ----------------------------------------------------------------------------- // This version removes the legacy numeric MutationType enum + raw bytes payload // approach and replaces it with a strongly typed oneof envelope. Each concrete // mutation proto is embedded directly, enabling: // * Type-safe routing server-side (simple type switch on the oneof). // * Direct persistence of MutationEnvelope messages (no custom binary header). // * Elimination of the legacy message handler registry. // // NOTE: Regenerate Go code after editing: // protoc --go_out=. --go_opt=paths=source_relative \ // --go-grpc_out=. --go-grpc_opt=paths=source_relative \ // proto/cart_actor.proto proto/messages.proto // ----------------------------------------------------------------------------- // MutationEnvelope carries exactly one mutation plus metadata. // client_timestamp: // - Optional Unix timestamp provided by the client. // - If zero the server MAY overwrite with its local time. message MutationEnvelope { string cart_id = 1; int64 client_timestamp = 2; oneof mutation { AddRequest add_request = 10; AddItem add_item = 11; RemoveItem remove_item = 12; RemoveDelivery remove_delivery = 13; ChangeQuantity change_quantity = 14; SetDelivery set_delivery = 15; SetPickupPoint set_pickup_point = 16; CreateCheckoutOrder create_checkout_order = 17; SetCartRequest set_cart_items = 18; OrderCreated order_completed = 19; } } // MutationReply returns a legacy-style status code plus a JSON payload // holding either the updated cart state (on success) or an error string. message MutationReply { int32 status_code = 1; // Exactly one of state or error will be set. oneof result { CartState state = 2; string error = 3; } } // StateRequest fetches current cart state without mutating. message StateRequest { string cart_id = 1; } // ----------------------------------------------------------------------------- // CartState represents the full cart snapshot returned by state/mutation replies. // Replaces the previous raw JSON payload. // ----------------------------------------------------------------------------- message CartState { string cart_id = 1; repeated CartItemState items = 2; int64 total_price = 3; int64 total_tax = 4; int64 total_discount = 5; repeated DeliveryState deliveries = 6; bool payment_in_progress = 7; string order_reference = 8; string payment_status = 9; } // Lightweight representation of an item in the cart message CartItemState { int64 id = 1; int64 source_item_id = 2; string sku = 3; string name = 4; int64 unit_price = 5; int32 quantity = 6; int64 total_price = 7; int64 total_tax = 8; int64 org_price = 9; int32 tax_rate = 10; int64 total_discount = 11; string brand = 12; string category = 13; string category2 = 14; string category3 = 15; string category4 = 16; string category5 = 17; string image = 18; string article_type = 19; string seller_id = 20; string seller_name = 21; string disclaimer = 22; string outlet = 23; string store_id = 24; int32 stock = 25; } // Delivery / shipping entry message DeliveryState { int64 id = 1; string provider = 2; int64 price = 3; repeated int64 item_ids = 4; PickupPoint pickup_point = 5; } // StateReply mirrors MutationReply for consistency. message StateReply { int32 status_code = 1; oneof result { CartState state = 2; string error = 3; } } // CartActor exposes mutation and state retrieval for remote grains. service CartActor { // Mutate applies a single mutation to a cart, creating the cart lazily if needed. rpc Mutate(MutationEnvelope) returns (MutationReply); // GetState retrieves the cart's current state (JSON). rpc GetState(StateRequest) returns (StateReply); } // ----------------------------------------------------------------------------- // Future Enhancements: // * Replace JSON state payload with a strongly typed CartState proto. // * Add streaming RPC (e.g., WatchState) for live updates. // * Add batch mutations (repeated MutationEnvelope) if performance requires. // * Introduce optimistic concurrency via version fields if external writers appear. // -----------------------------------------------------------------------------