diff --git a/client.http b/client.http index 6092021..f8a592a 100644 --- a/client.http +++ b/client.http @@ -10,4 +10,26 @@ content-type: application/json ### GET {{host}}/v1/fulfillment-orders HTTP/1.1 -content-type: application/json \ No newline at end of file +content-type: application/json + +### +POST {{host}}/v1/api/orders HTTP/1.1 +content-type: application/json + +{ + "commandType": 0, + "orderSource": 0, + "location": 0, + "loyaltyMemberId": "3fa85f64-5717-4562-b3fc-2c963f66afa6", + "baristaItems": [ + { + "itemType": {{$randomInt 0 5}} + } + ], + "kitchenItems": [ + { + "itemType": {{$randomInt 6 9}} + } + ], + "timestamp": "2022-07-04T11:38:00.210Z" +} \ No newline at end of file diff --git a/cmd/barista/event/consumer.go b/cmd/barista/event/consumer.go index 6e7f4b3..d7bd323 100644 --- a/cmd/barista/event/consumer.go +++ b/cmd/barista/event/consumer.go @@ -95,10 +95,11 @@ func (c *Consumer) Listen(topics []string) error { var payload Payload _ = json.Unmarshal(d.Body, &payload) + messageType := d.Type go func() { - switch payload.Name { - case "drink_made": + switch messageType { + case "barista.ordered": fmt.Println(payload) default: fmt.Println("default") diff --git a/docker-compose.yaml b/docker-compose.yaml index 27281d5..927bfd0 100755 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -23,66 +23,66 @@ services: networks: - coffeeshop-network - proxy: - build: - context: . - dockerfile: ./docker/Dockerfile-proxy - image: go-coffeeshop-proxy - environment: - APP_NAME: 'proxy-service in docker' - GRPC_PRODUCT_HOST: 'product' - GRPC_PRODUCT_PORT: 5001 - GRPC_COUNTER_HOST: 'counter' - GRPC_COUNTER_PORT: 5002 - ports: - - 5000:5000 - depends_on: - - product - - counter - networks: - - coffeeshop-network + # proxy: + # build: + # context: . + # dockerfile: ./docker/Dockerfile-proxy + # image: go-coffeeshop-proxy + # environment: + # APP_NAME: 'proxy-service in docker' + # GRPC_PRODUCT_HOST: 'product' + # GRPC_PRODUCT_PORT: 5001 + # GRPC_COUNTER_HOST: 'counter' + # GRPC_COUNTER_PORT: 5002 + # ports: + # - 5000:5000 + # depends_on: + # - product + # - counter + # networks: + # - coffeeshop-network - product: - build: - context: . - dockerfile: ./docker/Dockerfile-product - image: go-coffeeshop-product - environment: - APP_NAME: 'product-service in docker' - ports: - - 5001:5001 - networks: - - coffeeshop-network + # product: + # build: + # context: . + # dockerfile: ./docker/Dockerfile-product + # image: go-coffeeshop-product + # environment: + # APP_NAME: 'product-service in docker' + # ports: + # - 5001:5001 + # networks: + # - coffeeshop-network - counter: - build: - context: . - dockerfile: ./docker/Dockerfile-counter - image: go-coffeeshop-counter - environment: - APP_NAME: 'counter-service in docker' - RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ - ports: - - 5002:5002 - depends_on: - - postgres - - rabbitmq - networks: - - coffeeshop-network + # counter: + # build: + # context: . + # dockerfile: ./docker/Dockerfile-counter + # image: go-coffeeshop-counter + # environment: + # APP_NAME: 'counter-service in docker' + # RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ + # ports: + # - 5002:5002 + # depends_on: + # - postgres + # - rabbitmq + # networks: + # - coffeeshop-network - barista: - build: - context: . - dockerfile: ./docker/Dockerfile-barista - image: go-coffeeshop-barista - environment: - APP_NAME: 'barista-service in docker' - RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ - depends_on: - - postgres - - rabbitmq - networks: - - coffeeshop-network + # barista: + # build: + # context: . + # dockerfile: ./docker/Dockerfile-barista + # image: go-coffeeshop-barista + # environment: + # APP_NAME: 'barista-service in docker' + # RABBITMQ_URL: amqp://guest:guest@rabbitmq:5672/ + # depends_on: + # - postgres + # - rabbitmq + # networks: + # - coffeeshop-network networks: coffeeshop-network: \ No newline at end of file diff --git a/docker/Dockerfile-dev b/docker/Dockerfile-dev index 8bd84b9..63d26eb 100755 --- a/docker/Dockerfile-dev +++ b/docker/Dockerfile-dev @@ -15,11 +15,14 @@ RUN LATEST_COMPOSE_VERSION=$(curl -sSL "https://api.github.com/repos/docker/comp && curl -sSL "https://github.com/docker/compose/releases/download/${LATEST_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o ~/.docker/cli-plugins/docker-compose \ && chmod +x ~/.docker/cli-plugins/docker-compose -# Substitute BIN for your bin directory. -# Substitute VERSION for the current released version. +# Install Buf RUN BIN="/usr/local/bin" && \ VERSION="1.8.0" && \ curl -sSL \ "https://github.com/bufbuild/buf/releases/download/v${VERSION}/buf-$(uname -s)-$(uname -m)" \ -o "${BIN}/buf" && \ - chmod +x "${BIN}/buf" \ No newline at end of file + chmod +x "${BIN}/buf" + +# Install dbmate +RUN curl -fsSL -o /usr/local/bin/dbmate https://github.com/amacneil/dbmate/releases/latest/download/dbmate-linux-amd64 \ + && chmod +x /usr/local/bin/dbmate \ No newline at end of file diff --git a/go.mod b/go.mod index d19f8fb..f593d5b 100755 --- a/go.mod +++ b/go.mod @@ -4,6 +4,7 @@ go 1.19 require ( github.com/golang/glog v1.0.0 + github.com/google/uuid v1.3.0 github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 github.com/ilyakaznacheev/cleanenv v1.3.0 github.com/rabbitmq/amqp091-go v1.5.0 diff --git a/go.sum b/go.sum index f5b92e9..714a86f 100755 --- a/go.sum +++ b/go.sum @@ -10,6 +10,8 @@ github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0 h1:kr3j8iIMR4ywO/O0rvksXaJvauGGCMg2zAZIiNZ9uIQ= github.com/grpc-ecosystem/grpc-gateway/v2 v2.12.0/go.mod h1:ummNFgdgLhhX7aIiy35vVmQNS0rWXknfPE0qe6fmFXg= github.com/ilyakaznacheev/cleanenv v1.3.0 h1:RapuLclPPUbmdd5Bi5UXScwMEZA6+ZNLU5OW9itPjj0= diff --git a/internal/counter/app/app.go b/internal/counter/app/app.go index 0c435a1..983baf9 100644 --- a/internal/counter/app/app.go +++ b/internal/counter/app/app.go @@ -4,11 +4,14 @@ import ( "context" "encoding/json" "errors" + "fmt" "net" "time" + "github.com/google/uuid" amqp "github.com/rabbitmq/amqp091-go" "github.com/thangchung/go-coffeeshop/cmd/counter/config" + "github.com/thangchung/go-coffeeshop/internal/counter/event" mylogger "github.com/thangchung/go-coffeeshop/pkg/logger" gen "github.com/thangchung/go-coffeeshop/proto/gen" "google.golang.org/grpc" @@ -85,6 +88,43 @@ func (g *CounterServiceServerImpl) GetListOrderFulfillment(ctx context.Context, func (g *CounterServiceServerImpl) PlaceOrder(ctx context.Context, request *gen.PlaceOrderRequest) (*gen.PlaceOrderResponse, error) { g.logger.Info("POST: PlaceOrder") + fmt.Println(request) + + ch, err := g.rabbitConn.Channel() + if err != nil { + panic(err) + } + defer ch.Close() + + eventBytes, err := json.Marshal(event.BaristaOrdered{ + OrderID: uuid.New(), + ItemLineID: uuid.UUID, + }) + if err != nil { + g.logger.LogError(err) + } + + err = ch.PublishWithContext( + ctx, + OrderTopic, + "log.INFO", + false, + false, + amqp.Publishing{ + ContentType: "text/plain", + Type: "barista.ordered", + Body: eventBytes, + }, + ) + + if err != nil { + g.logger.LogError(err) + + return nil, err + } + + g.logger.Info("Sending message: %s -> %s", event, "orders_topic") + res := gen.PlaceOrderResponse{} return &res, nil diff --git a/internal/counter/entity/line_item.go b/internal/counter/entity/line_item.go new file mode 100644 index 0000000..8b98c51 --- /dev/null +++ b/internal/counter/entity/line_item.go @@ -0,0 +1,26 @@ +package entity + +import ( + "github.com/google/uuid" + gen "github.com/thangchung/go-coffeeshop/proto/gen" +) + +type LineItem struct { + ID uuid.UUID + ItemType gen.ItemType + Name string + Price float32 + ItemStatus gen.Status + IsBaristaOrder bool +} + +func NewLineItem(itemType gen.ItemType, name string, price float32, itemStatus gen.Status, isBarista bool) *LineItem { + return &LineItem{ + ID: uuid.New(), + ItemType: itemType, + Name: name, + Price: price, + ItemStatus: itemStatus, + IsBaristaOrder: isBarista, + } +} diff --git a/internal/counter/entity/order.go b/internal/counter/entity/order.go new file mode 100644 index 0000000..7c20eb4 --- /dev/null +++ b/internal/counter/entity/order.go @@ -0,0 +1,44 @@ +package entity + +import ( + "github.com/google/uuid" + gen "github.com/thangchung/go-coffeeshop/proto/gen" +) + +type Order struct { + ID uuid.UUID + OrderSource gen.OrderSource + LoyaltyMemberID uuid.UUID + OrderStatus gen.Status + Location gen.Location + LineItems []LineItem +} + +func NewOrder(orderSource gen.OrderSource, loyaltyMemberID uuid.UUID, orderStatus gen.Status, location gen.Location) *Order { + return &Order{ + ID: uuid.New(), + OrderSource: orderSource, + LoyaltyMemberID: loyaltyMemberID, + OrderStatus: orderStatus, + Location: location, + } +} + +func (o *Order) From(request *gen.PlaceOrderRequest) (*Order, error) { + loyaltyMemberID, err := uuid.Parse(request.LoyaltyMemberId) + if err != nil { + return nil, err + } + + order := NewOrder(request.OrderSource, loyaltyMemberID, gen.Status_IN_PROGRESS, request.Location) + + if len(request.BaristaItems) > 0 { + + } + + if len(request.KitchenItems) > 0 { + + } + + return order, nil +} diff --git a/internal/counter/event/events.go b/internal/counter/event/events.go new file mode 100644 index 0000000..6fbdca5 --- /dev/null +++ b/internal/counter/event/events.go @@ -0,0 +1,40 @@ +package event + +import ( + "time" + + "github.com/google/uuid" + gen "github.com/thangchung/go-coffeeshop/proto/gen" +) + +type BaristaOrdered struct { + OrderID uuid.UUID `json:"orderId"` + ItemLineID uuid.UUID `json:"itemLineId"` + ItemType gen.ItemType `json:"itemType"` +} + +type KitchenOrdered struct { + OrderID uuid.UUID `json:"orderId"` + ItemLineID uuid.UUID `json:"itemLineId"` + ItemType gen.ItemType `json:"itemType"` +} + +type BaristaOrderUpdated struct { + OrderID uuid.UUID `json:"orderId"` + ItemLineID uuid.UUID `json:"itemLineId"` + Name string `json:"name"` + ItemType gen.ItemType `json:"itemType"` + TimeIn time.Time `json:"timeIn"` + MadeBy string `json:"madeBy"` + TimeUp time.Time `json:"timeUp"` +} + +type KitchenOrderUpdated struct { + OrderID uuid.UUID `json:"orderId"` + ItemLineID uuid.UUID `json:"itemLineId"` + Name string `json:"name"` + ItemType gen.ItemType `json:"itemType"` + TimeIn time.Time `json:"timeIn"` + MadeBy string `json:"madeBy"` + TimeUp time.Time `json:"timeUp"` +} diff --git a/internal/product/app/app.go b/internal/product/app/app.go index c1c4513..37c0c32 100644 --- a/internal/product/app/app.go +++ b/internal/product/app/app.go @@ -3,6 +3,8 @@ package app import ( "context" "net" + "reflect" + "strings" "github.com/thangchung/go-coffeeshop/cmd/product/config" mylogger "github.com/thangchung/go-coffeeshop/pkg/logger" @@ -22,55 +24,64 @@ type ProductServiceServerImpl struct { logger *mylogger.Logger } +var ItemTypes = map[string]gen.ItemTypeDto{ + "0": { + Name: "CAPPUCCINO", + Type: 0, + Price: 4.5, + }, + "1": {Name: "COFFEE_BLACK", + Type: 1, + Price: 3, + }, + "2": { + Name: "COFFEE_WITH_ROOM", + Type: 2, + Price: 3, + }, + "3": { + Name: "ESPRESSO", + Type: 3, + Price: 3.5, + }, + "4": { + Name: "ESPRESSO_DOUBLE", + Type: 4, + Price: 4.5, + }, + "5": { + Name: "LATTE", + Type: 5, + Price: 4.5, + }, + "6": { + Name: "CAKEPOP", + Type: 6, + Price: 2.5, + }, + "7": { + Name: "CROISSANT", + Type: 7, + Price: 3.25, + }, + "8": { + Name: "MUFFIN", + Type: 8, + Price: 3, + }, + "9": { + Name: "CROISSANT_CHOCOLATE", + Type: 9, + Price: 3.5, + }, +} + func (g *ProductServiceServerImpl) GetItemTypes(ctx context.Context, request *gen.GetItemTypesRequest) (*gen.GetItemTypesResponse, error) { g.logger.Info("GET: GetItemTypes") - itemTypes := []gen.ItemTypeDto{ - { - Name: "CAPPUCCINO", - Type: 0, - }, - { - Name: "COFFEE_BLACK", - Type: 1, - }, - { - Name: "COFFEE_WITH_ROOM", - Type: 2, - }, - { - Name: "ESPRESSO", - Type: 3, - }, - { - Name: "ESPRESSO_DOUBLE", - Type: 4, - }, - { - Name: "LATTE", - Type: 5, - }, - { - Name: "CAKEPOP", - Type: 6, - }, - { - Name: "CROISSANT", - Type: 7, - }, - { - Name: "MUFFIN", - Type: 8, - }, - { - Name: "CROISSANT_CHOCOLATE", - Type: 9, - }, - } - res := gen.GetItemTypesResponse{} - for _, v := range itemTypes { + for _, v := range ItemTypes { res.ItemTypes = append(res.ItemTypes, &gen.ItemTypeDto{ Name: v.Name, Type: v.Type, @@ -80,6 +91,25 @@ func (g *ProductServiceServerImpl) GetItemTypes(ctx context.Context, request *ge return &res, nil } +func (g *ProductServiceServerImpl) GetItemsByType(ctx context.Context, request *gen.GetItemsByTypeRequest) (*gen.GetItemsByTypeResponse, error) { + g.logger.Info("GET: GetItemsByType") + + res := gen.GetItemsByTypeResponse{} + + itemTypes := strings.Split(request.ItemTypes, ",") + for _, itemType := range itemTypes { + item := ItemTypes[itemType] + if !reflect.DeepEqual(item, gen.ItemTypeDto{}) { + res.Items = append(res.Items, &gen.ItemDto{ + Price: item.Price, + Type: item.Type, + }) + } + } + + return &res, nil +} + func New(log *mylogger.Logger, cfg *config.Config) *App { return &App{ logger: log, diff --git a/proto/gen/product.pb.go b/proto/gen/product.pb.go index 0204ce1..ac10c56 100644 --- a/proto/gen/product.pb.go +++ b/proto/gen/product.pb.go @@ -107,19 +107,169 @@ func (x *GetItemTypesResponse) GetItemTypes() []*ItemTypeDto { return nil } +type GetItemsByTypeRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ItemTypes string `protobuf:"bytes,1,opt,name=item_types,json=itemTypes,proto3" json:"item_types,omitempty"` +} + +func (x *GetItemsByTypeRequest) Reset() { + *x = GetItemsByTypeRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_product_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetItemsByTypeRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetItemsByTypeRequest) ProtoMessage() {} + +func (x *GetItemsByTypeRequest) ProtoReflect() protoreflect.Message { + mi := &file_product_proto_msgTypes[2] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetItemsByTypeRequest.ProtoReflect.Descriptor instead. +func (*GetItemsByTypeRequest) Descriptor() ([]byte, []int) { + return file_product_proto_rawDescGZIP(), []int{2} +} + +func (x *GetItemsByTypeRequest) GetItemTypes() string { + if x != nil { + return x.ItemTypes + } + return "" +} + +type GetItemsByTypeResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Items []*ItemDto `protobuf:"bytes,1,rep,name=items,proto3" json:"items,omitempty"` +} + +func (x *GetItemsByTypeResponse) Reset() { + *x = GetItemsByTypeResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_product_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetItemsByTypeResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetItemsByTypeResponse) ProtoMessage() {} + +func (x *GetItemsByTypeResponse) ProtoReflect() protoreflect.Message { + mi := &file_product_proto_msgTypes[3] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetItemsByTypeResponse.ProtoReflect.Descriptor instead. +func (*GetItemsByTypeResponse) Descriptor() ([]byte, []int) { + return file_product_proto_rawDescGZIP(), []int{3} +} + +func (x *GetItemsByTypeResponse) GetItems() []*ItemDto { + if x != nil { + return x.Items + } + return nil +} + +type ItemDto struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Price float64 `protobuf:"fixed64,1,opt,name=price,proto3" json:"price,omitempty"` + Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` +} + +func (x *ItemDto) Reset() { + *x = ItemDto{} + if protoimpl.UnsafeEnabled { + mi := &file_product_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ItemDto) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ItemDto) ProtoMessage() {} + +func (x *ItemDto) ProtoReflect() protoreflect.Message { + mi := &file_product_proto_msgTypes[4] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use ItemDto.ProtoReflect.Descriptor instead. +func (*ItemDto) Descriptor() ([]byte, []int) { + return file_product_proto_rawDescGZIP(), []int{4} +} + +func (x *ItemDto) GetPrice() float64 { + if x != nil { + return x.Price + } + return 0 +} + +func (x *ItemDto) GetType() int32 { + if x != nil { + return x.Type + } + return 0 +} + type ItemTypeDto struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` + Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` + Type int32 `protobuf:"varint,2,opt,name=type,proto3" json:"type,omitempty"` + Price float64 `protobuf:"fixed64,3,opt,name=price,proto3" json:"price,omitempty"` } func (x *ItemTypeDto) Reset() { *x = ItemTypeDto{} if protoimpl.UnsafeEnabled { - mi := &file_product_proto_msgTypes[2] + mi := &file_product_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -132,7 +282,7 @@ func (x *ItemTypeDto) String() string { func (*ItemTypeDto) ProtoMessage() {} func (x *ItemTypeDto) ProtoReflect() protoreflect.Message { - mi := &file_product_proto_msgTypes[2] + mi := &file_product_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -145,7 +295,7 @@ func (x *ItemTypeDto) ProtoReflect() protoreflect.Message { // Deprecated: Use ItemTypeDto.ProtoReflect.Descriptor instead. func (*ItemTypeDto) Descriptor() ([]byte, []int) { - return file_product_proto_rawDescGZIP(), []int{2} + return file_product_proto_rawDescGZIP(), []int{5} } func (x *ItemTypeDto) GetName() string { @@ -162,6 +312,13 @@ func (x *ItemTypeDto) GetType() int32 { return 0 } +func (x *ItemTypeDto) GetPrice() float64 { + if x != nil { + return x.Price + } + return 0 +} + var File_product_proto protoreflect.FileDescriptor var file_product_proto_rawDesc = []byte{ @@ -181,25 +338,54 @@ var file_product_proto_rawDesc = []byte{ 0x2e, 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x44, 0x74, 0x6f, 0x52, 0x09, 0x69, 0x74, 0x65, - 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x22, 0x35, 0x0a, 0x0b, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, - 0x70, 0x65, 0x44, 0x74, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, - 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x32, 0xeb, 0x01, - 0x0a, 0x0e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x12, 0xd8, 0x01, 0x0a, 0x0c, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, - 0x73, 0x12, 0x33, 0x2e, 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, + 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x22, 0x36, 0x0a, 0x15, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, + 0x6d, 0x73, 0x42, 0x79, 0x54, 0x79, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1d, 0x0a, 0x0a, 0x69, 0x74, 0x65, 0x6d, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x22, 0x57, + 0x0a, 0x16, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x42, 0x79, 0x54, 0x79, 0x70, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x3d, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, + 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, + 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x61, 0x70, 0x69, 0x2e, 0x49, 0x74, 0x65, 0x6d, 0x44, 0x74, 0x6f, + 0x52, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x22, 0x33, 0x0a, 0x07, 0x49, 0x74, 0x65, 0x6d, 0x44, + 0x74, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x01, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x22, 0x4b, 0x0a, 0x0b, + 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x44, 0x74, 0x6f, 0x12, 0x12, 0x0a, 0x04, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, + 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x74, + 0x79, 0x70, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x01, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x32, 0xdf, 0x03, 0x0a, 0x0e, 0x50, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0xd8, 0x01, 0x0a, + 0x0c, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x33, 0x2e, + 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x61, 0x70, 0x69, 0x2e, 0x47, + 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x34, 0x2e, 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, + 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x5d, 0x92, 0x41, 0x40, 0x0a, 0x09, 0x49, + 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x20, 0x69, + 0x74, 0x65, 0x6d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x1a, 0x22, 0x4c, 0x69, 0x73, 0x74, 0x20, + 0x61, 0x6c, 0x6c, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x20, 0x6f, + 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, 0x82, 0xd3, 0xe4, + 0x93, 0x02, 0x14, 0x12, 0x12, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x69, 0x74, 0x65, + 0x6d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x12, 0xf1, 0x01, 0x0a, 0x0e, 0x47, 0x65, 0x74, 0x49, + 0x74, 0x65, 0x6d, 0x73, 0x42, 0x79, 0x54, 0x79, 0x70, 0x65, 0x12, 0x35, 0x2e, 0x67, 0x6f, 0x2e, + 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x49, + 0x74, 0x65, 0x6d, 0x73, 0x42, 0x79, 0x54, 0x79, 0x70, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x36, 0x2e, 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x61, - 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x34, 0x2e, 0x67, 0x6f, 0x2e, 0x63, 0x6f, 0x66, 0x66, - 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2e, 0x70, 0x72, 0x6f, - 0x64, 0x75, 0x63, 0x74, 0x61, 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x54, - 0x79, 0x70, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x5d, 0x92, 0x41, - 0x40, 0x0a, 0x09, 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x0f, 0x4c, 0x69, - 0x73, 0x74, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x20, 0x74, 0x79, 0x70, 0x65, 0x73, 0x1a, 0x22, 0x4c, - 0x69, 0x73, 0x74, 0x20, 0x61, 0x6c, 0x6c, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x20, 0x74, 0x79, 0x70, - 0x65, 0x73, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, - 0x2e, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, 0x12, 0x12, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x70, 0x69, - 0x2f, 0x69, 0x74, 0x65, 0x6d, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x42, 0x2f, 0x5a, 0x2d, 0x67, + 0x70, 0x69, 0x2e, 0x47, 0x65, 0x74, 0x49, 0x74, 0x65, 0x6d, 0x73, 0x42, 0x79, 0x54, 0x79, 0x70, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x70, 0x92, 0x41, 0x42, 0x0a, 0x09, + 0x49, 0x74, 0x65, 0x6d, 0x54, 0x79, 0x70, 0x65, 0x73, 0x12, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x20, + 0x69, 0x74, 0x65, 0x6d, 0x73, 0x20, 0x62, 0x79, 0x20, 0x74, 0x79, 0x70, 0x65, 0x1a, 0x21, 0x4c, + 0x69, 0x73, 0x74, 0x20, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x20, 0x62, 0x79, 0x20, 0x74, 0x79, 0x70, + 0x65, 0x20, 0x6f, 0x6e, 0x20, 0x74, 0x68, 0x65, 0x20, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x2e, + 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x25, 0x12, 0x23, 0x2f, 0x76, 0x31, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x69, 0x74, 0x65, 0x6d, 0x73, 0x2d, 0x62, 0x79, 0x2d, 0x74, 0x79, 0x70, 0x65, 0x73, 0x2f, 0x7b, + 0x69, 0x74, 0x65, 0x6d, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x73, 0x7d, 0x42, 0x2f, 0x5a, 0x2d, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x74, 0x68, 0x61, 0x6e, 0x67, 0x63, 0x68, 0x75, 0x6e, 0x67, 0x2f, 0x67, 0x6f, 0x2d, 0x63, 0x6f, 0x66, 0x66, 0x65, 0x65, 0x73, 0x68, 0x6f, 0x70, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x62, 0x06, 0x70, 0x72, @@ -218,21 +404,27 @@ func file_product_proto_rawDescGZIP() []byte { return file_product_proto_rawDescData } -var file_product_proto_msgTypes = make([]protoimpl.MessageInfo, 3) +var file_product_proto_msgTypes = make([]protoimpl.MessageInfo, 6) var file_product_proto_goTypes = []interface{}{ - (*GetItemTypesRequest)(nil), // 0: go.coffeeshop.proto.productapi.GetItemTypesRequest - (*GetItemTypesResponse)(nil), // 1: go.coffeeshop.proto.productapi.GetItemTypesResponse - (*ItemTypeDto)(nil), // 2: go.coffeeshop.proto.productapi.ItemTypeDto + (*GetItemTypesRequest)(nil), // 0: go.coffeeshop.proto.productapi.GetItemTypesRequest + (*GetItemTypesResponse)(nil), // 1: go.coffeeshop.proto.productapi.GetItemTypesResponse + (*GetItemsByTypeRequest)(nil), // 2: go.coffeeshop.proto.productapi.GetItemsByTypeRequest + (*GetItemsByTypeResponse)(nil), // 3: go.coffeeshop.proto.productapi.GetItemsByTypeResponse + (*ItemDto)(nil), // 4: go.coffeeshop.proto.productapi.ItemDto + (*ItemTypeDto)(nil), // 5: go.coffeeshop.proto.productapi.ItemTypeDto } var file_product_proto_depIdxs = []int32{ - 2, // 0: go.coffeeshop.proto.productapi.GetItemTypesResponse.item_types:type_name -> go.coffeeshop.proto.productapi.ItemTypeDto - 0, // 1: go.coffeeshop.proto.productapi.ProductService.GetItemTypes:input_type -> go.coffeeshop.proto.productapi.GetItemTypesRequest - 1, // 2: go.coffeeshop.proto.productapi.ProductService.GetItemTypes:output_type -> go.coffeeshop.proto.productapi.GetItemTypesResponse - 2, // [2:3] is the sub-list for method output_type - 1, // [1:2] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 5, // 0: go.coffeeshop.proto.productapi.GetItemTypesResponse.item_types:type_name -> go.coffeeshop.proto.productapi.ItemTypeDto + 4, // 1: go.coffeeshop.proto.productapi.GetItemsByTypeResponse.items:type_name -> go.coffeeshop.proto.productapi.ItemDto + 0, // 2: go.coffeeshop.proto.productapi.ProductService.GetItemTypes:input_type -> go.coffeeshop.proto.productapi.GetItemTypesRequest + 2, // 3: go.coffeeshop.proto.productapi.ProductService.GetItemsByType:input_type -> go.coffeeshop.proto.productapi.GetItemsByTypeRequest + 1, // 4: go.coffeeshop.proto.productapi.ProductService.GetItemTypes:output_type -> go.coffeeshop.proto.productapi.GetItemTypesResponse + 3, // 5: go.coffeeshop.proto.productapi.ProductService.GetItemsByType:output_type -> go.coffeeshop.proto.productapi.GetItemsByTypeResponse + 4, // [4:6] is the sub-list for method output_type + 2, // [2:4] is the sub-list for method input_type + 2, // [2:2] is the sub-list for extension type_name + 2, // [2:2] is the sub-list for extension extendee + 0, // [0:2] is the sub-list for field type_name } func init() { file_product_proto_init() } @@ -267,6 +459,42 @@ func file_product_proto_init() { } } file_product_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetItemsByTypeRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_product_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetItemsByTypeResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_product_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ItemDto); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_product_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ItemTypeDto); i { case 0: return &v.state @@ -285,7 +513,7 @@ func file_product_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_product_proto_rawDesc, NumEnums: 0, - NumMessages: 3, + NumMessages: 6, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/gen/product.pb.gw.go b/proto/gen/product.pb.gw.go index ed69b6d..0e6bb28 100644 --- a/proto/gen/product.pb.gw.go +++ b/proto/gen/product.pb.gw.go @@ -49,6 +49,58 @@ func local_request_ProductService_GetItemTypes_0(ctx context.Context, marshaler } +func request_ProductService_GetItemsByType_0(ctx context.Context, marshaler runtime.Marshaler, client ProductServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetItemsByTypeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["item_types"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "item_types") + } + + protoReq.ItemTypes, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "item_types", err) + } + + msg, err := client.GetItemsByType(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_ProductService_GetItemsByType_0(ctx context.Context, marshaler runtime.Marshaler, server ProductServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetItemsByTypeRequest + var metadata runtime.ServerMetadata + + var ( + val string + ok bool + err error + _ = err + ) + + val, ok = pathParams["item_types"] + if !ok { + return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "item_types") + } + + protoReq.ItemTypes, err = runtime.String(val) + if err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "item_types", err) + } + + msg, err := server.GetItemsByType(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterProductServiceHandlerServer registers the http handlers for service ProductService to "mux". // UnaryRPC :call ProductServiceServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -78,6 +130,29 @@ func RegisterProductServiceHandlerServer(ctx context.Context, mux *runtime.Serve }) + mux.Handle("GET", pattern_ProductService_GetItemsByType_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + var stream runtime.ServerTransportStream + ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/go.coffeeshop.proto.productapi.ProductService/GetItemsByType", runtime.WithHTTPPathPattern("/v1/api/items-by-types/{item_types}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_ProductService_GetItemsByType_0(rctx, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_GetItemsByType_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -139,13 +214,37 @@ func RegisterProductServiceHandlerClient(ctx context.Context, mux *runtime.Serve }) + mux.Handle("GET", pattern_ProductService_GetItemsByType_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { + ctx, cancel := context.WithCancel(req.Context()) + defer cancel() + inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) + rctx, err := runtime.AnnotateContext(ctx, mux, req, "/go.coffeeshop.proto.productapi.ProductService/GetItemsByType", runtime.WithHTTPPathPattern("/v1/api/items-by-types/{item_types}")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_ProductService_GetItemsByType_0(rctx, inboundMarshaler, client, req, pathParams) + ctx = runtime.NewServerMetadataContext(ctx, md) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + + forward_ProductService_GetItemsByType_0(ctx, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } var ( pattern_ProductService_GetItemTypes_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"v1", "api", "item-types"}, "")) + + pattern_ProductService_GetItemsByType_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"v1", "api", "items-by-types", "item_types"}, "")) ) var ( forward_ProductService_GetItemTypes_0 = runtime.ForwardResponseMessage + + forward_ProductService_GetItemsByType_0 = runtime.ForwardResponseMessage ) diff --git a/proto/gen/product_grpc.pb.go b/proto/gen/product_grpc.pb.go index be5bfc4..5176cb6 100644 --- a/proto/gen/product_grpc.pb.go +++ b/proto/gen/product_grpc.pb.go @@ -23,6 +23,7 @@ const _ = grpc.SupportPackageIsVersion7 // For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. type ProductServiceClient interface { GetItemTypes(ctx context.Context, in *GetItemTypesRequest, opts ...grpc.CallOption) (*GetItemTypesResponse, error) + GetItemsByType(ctx context.Context, in *GetItemsByTypeRequest, opts ...grpc.CallOption) (*GetItemsByTypeResponse, error) } type productServiceClient struct { @@ -42,11 +43,21 @@ func (c *productServiceClient) GetItemTypes(ctx context.Context, in *GetItemType return out, nil } +func (c *productServiceClient) GetItemsByType(ctx context.Context, in *GetItemsByTypeRequest, opts ...grpc.CallOption) (*GetItemsByTypeResponse, error) { + out := new(GetItemsByTypeResponse) + err := c.cc.Invoke(ctx, "/go.coffeeshop.proto.productapi.ProductService/GetItemsByType", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // ProductServiceServer is the server API for ProductService service. // All implementations should embed UnimplementedProductServiceServer // for forward compatibility type ProductServiceServer interface { GetItemTypes(context.Context, *GetItemTypesRequest) (*GetItemTypesResponse, error) + GetItemsByType(context.Context, *GetItemsByTypeRequest) (*GetItemsByTypeResponse, error) } // UnimplementedProductServiceServer should be embedded to have forward compatible implementations. @@ -56,6 +67,9 @@ type UnimplementedProductServiceServer struct { func (UnimplementedProductServiceServer) GetItemTypes(context.Context, *GetItemTypesRequest) (*GetItemTypesResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method GetItemTypes not implemented") } +func (UnimplementedProductServiceServer) GetItemsByType(context.Context, *GetItemsByTypeRequest) (*GetItemsByTypeResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetItemsByType not implemented") +} // UnsafeProductServiceServer may be embedded to opt out of forward compatibility for this service. // Use of this interface is not recommended, as added methods to ProductServiceServer will @@ -86,6 +100,24 @@ func _ProductService_GetItemTypes_Handler(srv interface{}, ctx context.Context, return interceptor(ctx, in, info, handler) } +func _ProductService_GetItemsByType_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetItemsByTypeRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ProductServiceServer).GetItemsByType(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/go.coffeeshop.proto.productapi.ProductService/GetItemsByType", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ProductServiceServer).GetItemsByType(ctx, req.(*GetItemsByTypeRequest)) + } + return interceptor(ctx, in, info, handler) +} + // ProductService_ServiceDesc is the grpc.ServiceDesc for ProductService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -97,6 +129,10 @@ var ProductService_ServiceDesc = grpc.ServiceDesc{ MethodName: "GetItemTypes", Handler: _ProductService_GetItemTypes_Handler, }, + { + MethodName: "GetItemsByType", + Handler: _ProductService_GetItemsByType_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "product.proto", diff --git a/proto/product.proto b/proto/product.proto index 3ee8db4..807079a 100644 --- a/proto/product.proto +++ b/proto/product.proto @@ -19,6 +19,17 @@ service ProductService { tags: "ItemTypes" }; } + + rpc GetItemsByType(GetItemsByTypeRequest) returns (GetItemsByTypeResponse) { + option (google.api.http) = { + get: "/v1/api/items-by-types/{item_types}" + }; + option (grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation) = { + summary: "List items by type" + description: "List items by type on the server." + tags: "ItemTypes" + }; + } } message GetItemTypesRequest {} @@ -26,7 +37,20 @@ message GetItemTypesResponse { repeated ItemTypeDto item_types = 1; } +message GetItemsByTypeRequest{ + string item_types = 1; +} +message GetItemsByTypeResponse{ + repeated ItemDto items = 1; +} + +message ItemDto { + double price = 1; + int32 type = 2; +} + message ItemTypeDto { string name = 1; int32 type = 2; + double price = 3; } \ No newline at end of file diff --git a/third_party/OpenAPI/product.swagger.json b/third_party/OpenAPI/product.swagger.json index a2f5b3d..a7afd14 100644 --- a/third_party/OpenAPI/product.swagger.json +++ b/third_party/OpenAPI/product.swagger.json @@ -39,6 +39,38 @@ "ItemTypes" ] } + }, + "/v1/api/items-by-types/{itemTypes}": { + "get": { + "summary": "List items by type", + "description": "List items by type on the server.", + "operationId": "ProductService_GetItemsByType", + "responses": { + "200": { + "description": "A successful response.", + "schema": { + "$ref": "#/definitions/productapiGetItemsByTypeResponse" + } + }, + "default": { + "description": "An unexpected error response.", + "schema": { + "$ref": "#/definitions/googlerpcStatus" + } + } + }, + "parameters": [ + { + "name": "itemTypes", + "in": "path", + "required": true, + "type": "string" + } + ], + "tags": [ + "ItemTypes" + ] + } } }, "definitions": { @@ -71,6 +103,30 @@ } } }, + "productapiGetItemsByTypeResponse": { + "type": "object", + "properties": { + "items": { + "type": "array", + "items": { + "$ref": "#/definitions/productapiItemDto" + } + } + } + }, + "productapiItemDto": { + "type": "object", + "properties": { + "price": { + "type": "number", + "format": "double" + }, + "type": { + "type": "integer", + "format": "int32" + } + } + }, "productapiItemTypeDto": { "type": "object", "properties": { @@ -80,6 +136,10 @@ "type": { "type": "integer", "format": "int32" + }, + "price": { + "type": "number", + "format": "double" } } },