diff --git a/API_GatewayMobile/DataStructures/com.blazc/order_service.pb.go b/API_GatewayMobile/DataStructures/com.blazc/order_service.pb.go new file mode 100644 index 0000000..054fd68 --- /dev/null +++ b/API_GatewayMobile/DataStructures/com.blazc/order_service.pb.go @@ -0,0 +1,883 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v4.25.3 +// source: order_service.proto + +package com_blazc + +import ( + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + reflect "reflect" + sync "sync" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type PaymentType int32 + +const ( + PaymentType_CREDIT_CARD PaymentType = 0 + PaymentType_CASH PaymentType = 2 +) + +// Enum value maps for PaymentType. +var ( + PaymentType_name = map[int32]string{ + 0: "CREDIT_CARD", + 2: "CASH", + } + PaymentType_value = map[string]int32{ + "CREDIT_CARD": 0, + "CASH": 2, + } +) + +func (x PaymentType) Enum() *PaymentType { + p := new(PaymentType) + *p = x + return p +} + +func (x PaymentType) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (PaymentType) Descriptor() protoreflect.EnumDescriptor { + return file_order_service_proto_enumTypes[0].Descriptor() +} + +func (PaymentType) Type() protoreflect.EnumType { + return &file_order_service_proto_enumTypes[0] +} + +func (x PaymentType) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use PaymentType.Descriptor instead. +func (PaymentType) EnumDescriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{0} +} + +type OrderStatus int32 + +const ( + OrderStatus_PENDING OrderStatus = 0 + OrderStatus_PREPARING OrderStatus = 1 + OrderStatus_READY_FOR_PICKUP OrderStatus = 2 + OrderStatus_DELIVERING OrderStatus = 3 + OrderStatus_DELIVERED OrderStatus = 4 + OrderStatus_CANCELLED OrderStatus = 5 +) + +// Enum value maps for OrderStatus. +var ( + OrderStatus_name = map[int32]string{ + 0: "PENDING", + 1: "PREPARING", + 2: "READY_FOR_PICKUP", + 3: "DELIVERING", + 4: "DELIVERED", + 5: "CANCELLED", + } + OrderStatus_value = map[string]int32{ + "PENDING": 0, + "PREPARING": 1, + "READY_FOR_PICKUP": 2, + "DELIVERING": 3, + "DELIVERED": 4, + "CANCELLED": 5, + } +) + +func (x OrderStatus) Enum() *OrderStatus { + p := new(OrderStatus) + *p = x + return p +} + +func (x OrderStatus) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (OrderStatus) Descriptor() protoreflect.EnumDescriptor { + return file_order_service_proto_enumTypes[1].Descriptor() +} + +func (OrderStatus) Type() protoreflect.EnumType { + return &file_order_service_proto_enumTypes[1] +} + +func (x OrderStatus) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use OrderStatus.Descriptor instead. +func (OrderStatus) EnumDescriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{1} +} + +type Empty struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *Empty) Reset() { + *x = Empty{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Empty) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Empty) ProtoMessage() {} + +func (x *Empty) ProtoReflect() protoreflect.Message { + mi := &file_order_service_proto_msgTypes[0] + 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 Empty.ProtoReflect.Descriptor instead. +func (*Empty) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{0} +} + +type Confirmation struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Message string `protobuf:"bytes,2,opt,name=message,proto3" json:"message,omitempty"` + Error string `protobuf:"bytes,3,opt,name=error,proto3" json:"error,omitempty"` +} + +func (x *Confirmation) Reset() { + *x = Confirmation{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Confirmation) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Confirmation) ProtoMessage() {} + +func (x *Confirmation) ProtoReflect() protoreflect.Message { + mi := &file_order_service_proto_msgTypes[1] + 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 Confirmation.ProtoReflect.Descriptor instead. +func (*Confirmation) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{1} +} + +func (x *Confirmation) GetMessage() string { + if x != nil { + return x.Message + } + return "" +} + +func (x *Confirmation) GetError() string { + if x != nil { + return x.Error + } + return "" +} + +type GetOrdersRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetOrdersRequest) Reset() { + *x = GetOrdersRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetOrdersRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetOrdersRequest) ProtoMessage() {} + +func (x *GetOrdersRequest) ProtoReflect() protoreflect.Message { + mi := &file_order_service_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 GetOrdersRequest.ProtoReflect.Descriptor instead. +func (*GetOrdersRequest) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{2} +} + +func (x *GetOrdersRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type GetOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *GetOrderRequest) Reset() { + *x = GetOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetOrderRequest) ProtoMessage() {} + +func (x *GetOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_order_service_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 GetOrderRequest.ProtoReflect.Descriptor instead. +func (*GetOrderRequest) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{3} +} + +func (x *GetOrderRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type DeleteOrderRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` +} + +func (x *DeleteOrderRequest) Reset() { + *x = DeleteOrderRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteOrderRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteOrderRequest) ProtoMessage() {} + +func (x *DeleteOrderRequest) ProtoReflect() protoreflect.Message { + mi := &file_order_service_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 DeleteOrderRequest.ProtoReflect.Descriptor instead. +func (*DeleteOrderRequest) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{4} +} + +func (x *DeleteOrderRequest) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +type Order struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + SellerId string `protobuf:"bytes,2,opt,name=sellerId,proto3" json:"sellerId,omitempty"` + DeliveryPersonId string `protobuf:"bytes,3,opt,name=deliveryPersonId,proto3" json:"deliveryPersonId,omitempty"` + Address string `protobuf:"bytes,4,opt,name=address,proto3" json:"address,omitempty"` + CustomerName string `protobuf:"bytes,5,opt,name=customerName,proto3" json:"customerName,omitempty"` + Items []*OrderItem `protobuf:"bytes,6,rep,name=items,proto3" json:"items,omitempty"` + Status OrderStatus `protobuf:"varint,7,opt,name=status,proto3,enum=com.blazc.OrderStatus" json:"status,omitempty"` + Timestamp int64 `protobuf:"varint,8,opt,name=timestamp,proto3" json:"timestamp,omitempty"` + PaymentType PaymentType `protobuf:"varint,9,opt,name=paymentType,proto3,enum=com.blazc.PaymentType" json:"paymentType,omitempty"` + TotalPrice int32 `protobuf:"varint,10,opt,name=totalPrice,proto3" json:"totalPrice,omitempty"` +} + +func (x *Order) Reset() { + *x = Order{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Order) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Order) ProtoMessage() {} + +func (x *Order) ProtoReflect() protoreflect.Message { + mi := &file_order_service_proto_msgTypes[5] + 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 Order.ProtoReflect.Descriptor instead. +func (*Order) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{5} +} + +func (x *Order) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Order) GetSellerId() string { + if x != nil { + return x.SellerId + } + return "" +} + +func (x *Order) GetDeliveryPersonId() string { + if x != nil { + return x.DeliveryPersonId + } + return "" +} + +func (x *Order) GetAddress() string { + if x != nil { + return x.Address + } + return "" +} + +func (x *Order) GetCustomerName() string { + if x != nil { + return x.CustomerName + } + return "" +} + +func (x *Order) GetItems() []*OrderItem { + if x != nil { + return x.Items + } + return nil +} + +func (x *Order) GetStatus() OrderStatus { + if x != nil { + return x.Status + } + return OrderStatus_PENDING +} + +func (x *Order) GetTimestamp() int64 { + if x != nil { + return x.Timestamp + } + return 0 +} + +func (x *Order) GetPaymentType() PaymentType { + if x != nil { + return x.PaymentType + } + return PaymentType_CREDIT_CARD +} + +func (x *Order) GetTotalPrice() int32 { + if x != nil { + return x.TotalPrice + } + return 0 +} + +type OrderItem struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Product *Product `protobuf:"bytes,2,opt,name=product,proto3" json:"product,omitempty"` + Quantity int32 `protobuf:"varint,3,opt,name=quantity,proto3" json:"quantity,omitempty"` + Price int32 `protobuf:"varint,4,opt,name=price,proto3" json:"price,omitempty"` +} + +func (x *OrderItem) Reset() { + *x = OrderItem{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *OrderItem) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*OrderItem) ProtoMessage() {} + +func (x *OrderItem) ProtoReflect() protoreflect.Message { + mi := &file_order_service_proto_msgTypes[6] + 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 OrderItem.ProtoReflect.Descriptor instead. +func (*OrderItem) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{6} +} + +func (x *OrderItem) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *OrderItem) GetProduct() *Product { + if x != nil { + return x.Product + } + return nil +} + +func (x *OrderItem) GetQuantity() int32 { + if x != nil { + return x.Quantity + } + return 0 +} + +func (x *OrderItem) GetPrice() int32 { + if x != nil { + return x.Price + } + return 0 +} + +type Product struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` + Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` + Price int32 `protobuf:"varint,3,opt,name=price,proto3" json:"price,omitempty"` +} + +func (x *Product) Reset() { + *x = Product{} + if protoimpl.UnsafeEnabled { + mi := &file_order_service_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Product) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Product) ProtoMessage() {} + +func (x *Product) ProtoReflect() protoreflect.Message { + mi := &file_order_service_proto_msgTypes[7] + 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 Product.ProtoReflect.Descriptor instead. +func (*Product) Descriptor() ([]byte, []int) { + return file_order_service_proto_rawDescGZIP(), []int{7} +} + +func (x *Product) GetId() string { + if x != nil { + return x.Id + } + return "" +} + +func (x *Product) GetName() string { + if x != nil { + return x.Name + } + return "" +} + +func (x *Product) GetPrice() int32 { + if x != nil { + return x.Price + } + return 0 +} + +var File_order_service_proto protoreflect.FileDescriptor + +var file_order_service_proto_rawDesc = []byte{ + 0x0a, 0x13, 0x6f, 0x72, 0x64, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x2e, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x09, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, + 0x22, 0x07, 0x0a, 0x05, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x3e, 0x0a, 0x0c, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, + 0x73, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, + 0x61, 0x67, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x65, 0x72, 0x72, 0x6f, 0x72, 0x22, 0x22, 0x0a, 0x10, 0x47, 0x65, 0x74, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, + 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0x21, 0x0a, + 0x0f, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, + 0x22, 0x24, 0x0a, 0x12, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x22, 0xf1, 0x02, 0x0a, 0x05, 0x4f, 0x72, 0x64, 0x65, 0x72, + 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, + 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x49, 0x64, 0x12, 0x2a, 0x0a, 0x10, + 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x49, 0x64, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x64, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, + 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x61, 0x64, 0x64, 0x72, + 0x65, 0x73, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x61, 0x64, 0x64, 0x72, 0x65, + 0x73, 0x73, 0x12, 0x22, 0x0a, 0x0c, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, 0x65, 0x72, 0x4e, 0x61, + 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x75, 0x73, 0x74, 0x6f, 0x6d, + 0x65, 0x72, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2a, 0x0a, 0x05, 0x69, 0x74, 0x65, 0x6d, 0x73, 0x18, + 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x14, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, + 0x63, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x52, 0x05, 0x69, 0x74, 0x65, + 0x6d, 0x73, 0x12, 0x2e, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x0e, 0x32, 0x16, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x03, 0x52, 0x09, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, + 0x12, 0x38, 0x0a, 0x0b, 0x70, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x18, + 0x09, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x16, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, + 0x63, 0x2e, 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x52, 0x0b, 0x70, + 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x74, 0x6f, + 0x74, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, + 0x74, 0x6f, 0x74, 0x61, 0x6c, 0x50, 0x72, 0x69, 0x63, 0x65, 0x22, 0x7b, 0x0a, 0x09, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x49, 0x74, 0x65, 0x6d, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x2c, 0x0a, 0x07, 0x70, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x12, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, + 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x50, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x07, 0x70, 0x72, + 0x6f, 0x64, 0x75, 0x63, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, + 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x71, 0x75, 0x61, 0x6e, 0x74, 0x69, 0x74, + 0x79, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x05, + 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x22, 0x43, 0x0a, 0x07, 0x50, 0x72, 0x6f, 0x64, 0x75, + 0x63, 0x74, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, + 0x69, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x05, 0x70, 0x72, 0x69, 0x63, 0x65, 0x2a, 0x28, 0x0a, 0x0b, + 0x50, 0x61, 0x79, 0x6d, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x0f, 0x0a, 0x0b, 0x43, + 0x52, 0x45, 0x44, 0x49, 0x54, 0x5f, 0x43, 0x41, 0x52, 0x44, 0x10, 0x00, 0x12, 0x08, 0x0a, 0x04, + 0x43, 0x41, 0x53, 0x48, 0x10, 0x02, 0x2a, 0x6d, 0x0a, 0x0b, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x50, 0x45, 0x4e, 0x44, 0x49, 0x4e, 0x47, + 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x50, 0x52, 0x45, 0x50, 0x41, 0x52, 0x49, 0x4e, 0x47, 0x10, + 0x01, 0x12, 0x14, 0x0a, 0x10, 0x52, 0x45, 0x41, 0x44, 0x59, 0x5f, 0x46, 0x4f, 0x52, 0x5f, 0x50, + 0x49, 0x43, 0x4b, 0x55, 0x50, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x44, 0x45, 0x4c, 0x49, 0x56, + 0x45, 0x52, 0x49, 0x4e, 0x47, 0x10, 0x03, 0x12, 0x0d, 0x0a, 0x09, 0x44, 0x45, 0x4c, 0x49, 0x56, + 0x45, 0x52, 0x45, 0x44, 0x10, 0x04, 0x12, 0x0d, 0x0a, 0x09, 0x43, 0x41, 0x4e, 0x43, 0x45, 0x4c, + 0x4c, 0x45, 0x44, 0x10, 0x05, 0x32, 0xda, 0x03, 0x0a, 0x0c, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x3a, 0x0a, 0x0b, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, + 0x63, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x1a, 0x17, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, + 0x61, 0x7a, 0x63, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0x00, 0x12, 0x3a, 0x0a, 0x08, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x1a, + 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4f, 0x72, + 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x63, 0x6f, 0x6d, + 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x00, 0x12, 0x3a, + 0x0a, 0x0b, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x12, 0x10, 0x2e, + 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x1a, + 0x17, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x00, 0x12, 0x46, 0x0a, 0x11, 0x47, 0x65, + 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x42, 0x79, 0x53, 0x65, 0x6c, 0x6c, 0x65, 0x72, 0x12, + 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x63, + 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x00, + 0x30, 0x01, 0x12, 0x4e, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x73, 0x42, + 0x79, 0x44, 0x65, 0x6c, 0x69, 0x76, 0x65, 0x72, 0x79, 0x50, 0x65, 0x72, 0x73, 0x6f, 0x6e, 0x12, + 0x1b, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x47, 0x65, 0x74, 0x4f, + 0x72, 0x64, 0x65, 0x72, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x10, 0x2e, 0x63, + 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x22, 0x00, + 0x30, 0x01, 0x12, 0x47, 0x0a, 0x0b, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, + 0x72, 0x12, 0x1d, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x4f, 0x72, 0x64, 0x65, 0x72, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x17, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x2e, 0x43, 0x6f, 0x6e, + 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x00, 0x12, 0x35, 0x0a, 0x06, 0x48, + 0x65, 0x61, 0x6c, 0x74, 0x68, 0x12, 0x10, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, + 0x63, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x17, 0x2e, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, + 0x61, 0x7a, 0x63, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0x00, 0x42, 0x0b, 0x5a, 0x09, 0x63, 0x6f, 0x6d, 0x2e, 0x62, 0x6c, 0x61, 0x7a, 0x63, 0x62, + 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_order_service_proto_rawDescOnce sync.Once + file_order_service_proto_rawDescData = file_order_service_proto_rawDesc +) + +func file_order_service_proto_rawDescGZIP() []byte { + file_order_service_proto_rawDescOnce.Do(func() { + file_order_service_proto_rawDescData = protoimpl.X.CompressGZIP(file_order_service_proto_rawDescData) + }) + return file_order_service_proto_rawDescData +} + +var file_order_service_proto_enumTypes = make([]protoimpl.EnumInfo, 2) +var file_order_service_proto_msgTypes = make([]protoimpl.MessageInfo, 8) +var file_order_service_proto_goTypes = []interface{}{ + (PaymentType)(0), // 0: com.blazc.PaymentType + (OrderStatus)(0), // 1: com.blazc.OrderStatus + (*Empty)(nil), // 2: com.blazc.Empty + (*Confirmation)(nil), // 3: com.blazc.Confirmation + (*GetOrdersRequest)(nil), // 4: com.blazc.GetOrdersRequest + (*GetOrderRequest)(nil), // 5: com.blazc.GetOrderRequest + (*DeleteOrderRequest)(nil), // 6: com.blazc.DeleteOrderRequest + (*Order)(nil), // 7: com.blazc.Order + (*OrderItem)(nil), // 8: com.blazc.OrderItem + (*Product)(nil), // 9: com.blazc.Product +} +var file_order_service_proto_depIdxs = []int32{ + 8, // 0: com.blazc.Order.items:type_name -> com.blazc.OrderItem + 1, // 1: com.blazc.Order.status:type_name -> com.blazc.OrderStatus + 0, // 2: com.blazc.Order.paymentType:type_name -> com.blazc.PaymentType + 9, // 3: com.blazc.OrderItem.product:type_name -> com.blazc.Product + 7, // 4: com.blazc.OrderService.CreateOrder:input_type -> com.blazc.Order + 5, // 5: com.blazc.OrderService.GetOrder:input_type -> com.blazc.GetOrderRequest + 7, // 6: com.blazc.OrderService.UpdateOrder:input_type -> com.blazc.Order + 4, // 7: com.blazc.OrderService.GetOrdersBySeller:input_type -> com.blazc.GetOrdersRequest + 4, // 8: com.blazc.OrderService.GetOrdersByDeliveryPerson:input_type -> com.blazc.GetOrdersRequest + 6, // 9: com.blazc.OrderService.DeleteOrder:input_type -> com.blazc.DeleteOrderRequest + 2, // 10: com.blazc.OrderService.Health:input_type -> com.blazc.Empty + 3, // 11: com.blazc.OrderService.CreateOrder:output_type -> com.blazc.Confirmation + 7, // 12: com.blazc.OrderService.GetOrder:output_type -> com.blazc.Order + 3, // 13: com.blazc.OrderService.UpdateOrder:output_type -> com.blazc.Confirmation + 7, // 14: com.blazc.OrderService.GetOrdersBySeller:output_type -> com.blazc.Order + 7, // 15: com.blazc.OrderService.GetOrdersByDeliveryPerson:output_type -> com.blazc.Order + 3, // 16: com.blazc.OrderService.DeleteOrder:output_type -> com.blazc.Confirmation + 3, // 17: com.blazc.OrderService.Health:output_type -> com.blazc.Confirmation + 11, // [11:18] is the sub-list for method output_type + 4, // [4:11] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name +} + +func init() { file_order_service_proto_init() } +func file_order_service_proto_init() { + if File_order_service_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_order_service_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Empty); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Confirmation); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetOrdersRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteOrderRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Order); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*OrderItem); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_order_service_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Product); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_order_service_proto_rawDesc, + NumEnums: 2, + NumMessages: 8, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_order_service_proto_goTypes, + DependencyIndexes: file_order_service_proto_depIdxs, + EnumInfos: file_order_service_proto_enumTypes, + MessageInfos: file_order_service_proto_msgTypes, + }.Build() + File_order_service_proto = out.File + file_order_service_proto_rawDesc = nil + file_order_service_proto_goTypes = nil + file_order_service_proto_depIdxs = nil +} diff --git a/API_GatewayMobile/DataStructures/com.blazc/order_service_grpc.pb.go b/API_GatewayMobile/DataStructures/com.blazc/order_service_grpc.pb.go new file mode 100644 index 0000000..824d72c --- /dev/null +++ b/API_GatewayMobile/DataStructures/com.blazc/order_service_grpc.pb.go @@ -0,0 +1,376 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v4.25.3 +// source: order_service.proto + +package com_blazc + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.32.0 or later. +const _ = grpc.SupportPackageIsVersion7 + +// OrderServiceClient is the client API for OrderService service. +// +// 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 OrderServiceClient interface { + CreateOrder(ctx context.Context, in *Order, opts ...grpc.CallOption) (*Confirmation, error) + GetOrder(ctx context.Context, in *GetOrderRequest, opts ...grpc.CallOption) (*Order, error) + UpdateOrder(ctx context.Context, in *Order, opts ...grpc.CallOption) (*Confirmation, error) + GetOrdersBySeller(ctx context.Context, in *GetOrdersRequest, opts ...grpc.CallOption) (OrderService_GetOrdersBySellerClient, error) + GetOrdersByDeliveryPerson(ctx context.Context, in *GetOrdersRequest, opts ...grpc.CallOption) (OrderService_GetOrdersByDeliveryPersonClient, error) + DeleteOrder(ctx context.Context, in *DeleteOrderRequest, opts ...grpc.CallOption) (*Confirmation, error) + Health(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Confirmation, error) +} + +type orderServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewOrderServiceClient(cc grpc.ClientConnInterface) OrderServiceClient { + return &orderServiceClient{cc} +} + +func (c *orderServiceClient) CreateOrder(ctx context.Context, in *Order, opts ...grpc.CallOption) (*Confirmation, error) { + out := new(Confirmation) + err := c.cc.Invoke(ctx, "/com.blazc.OrderService/CreateOrder", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) GetOrder(ctx context.Context, in *GetOrderRequest, opts ...grpc.CallOption) (*Order, error) { + out := new(Order) + err := c.cc.Invoke(ctx, "/com.blazc.OrderService/GetOrder", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) UpdateOrder(ctx context.Context, in *Order, opts ...grpc.CallOption) (*Confirmation, error) { + out := new(Confirmation) + err := c.cc.Invoke(ctx, "/com.blazc.OrderService/UpdateOrder", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) GetOrdersBySeller(ctx context.Context, in *GetOrdersRequest, opts ...grpc.CallOption) (OrderService_GetOrdersBySellerClient, error) { + stream, err := c.cc.NewStream(ctx, &OrderService_ServiceDesc.Streams[0], "/com.blazc.OrderService/GetOrdersBySeller", opts...) + if err != nil { + return nil, err + } + x := &orderServiceGetOrdersBySellerClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type OrderService_GetOrdersBySellerClient interface { + Recv() (*Order, error) + grpc.ClientStream +} + +type orderServiceGetOrdersBySellerClient struct { + grpc.ClientStream +} + +func (x *orderServiceGetOrdersBySellerClient) Recv() (*Order, error) { + m := new(Order) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *orderServiceClient) GetOrdersByDeliveryPerson(ctx context.Context, in *GetOrdersRequest, opts ...grpc.CallOption) (OrderService_GetOrdersByDeliveryPersonClient, error) { + stream, err := c.cc.NewStream(ctx, &OrderService_ServiceDesc.Streams[1], "/com.blazc.OrderService/GetOrdersByDeliveryPerson", opts...) + if err != nil { + return nil, err + } + x := &orderServiceGetOrdersByDeliveryPersonClient{stream} + if err := x.ClientStream.SendMsg(in); err != nil { + return nil, err + } + if err := x.ClientStream.CloseSend(); err != nil { + return nil, err + } + return x, nil +} + +type OrderService_GetOrdersByDeliveryPersonClient interface { + Recv() (*Order, error) + grpc.ClientStream +} + +type orderServiceGetOrdersByDeliveryPersonClient struct { + grpc.ClientStream +} + +func (x *orderServiceGetOrdersByDeliveryPersonClient) Recv() (*Order, error) { + m := new(Order) + if err := x.ClientStream.RecvMsg(m); err != nil { + return nil, err + } + return m, nil +} + +func (c *orderServiceClient) DeleteOrder(ctx context.Context, in *DeleteOrderRequest, opts ...grpc.CallOption) (*Confirmation, error) { + out := new(Confirmation) + err := c.cc.Invoke(ctx, "/com.blazc.OrderService/DeleteOrder", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *orderServiceClient) Health(ctx context.Context, in *Empty, opts ...grpc.CallOption) (*Confirmation, error) { + out := new(Confirmation) + err := c.cc.Invoke(ctx, "/com.blazc.OrderService/Health", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// OrderServiceServer is the server API for OrderService service. +// All implementations must embed UnimplementedOrderServiceServer +// for forward compatibility +type OrderServiceServer interface { + CreateOrder(context.Context, *Order) (*Confirmation, error) + GetOrder(context.Context, *GetOrderRequest) (*Order, error) + UpdateOrder(context.Context, *Order) (*Confirmation, error) + GetOrdersBySeller(*GetOrdersRequest, OrderService_GetOrdersBySellerServer) error + GetOrdersByDeliveryPerson(*GetOrdersRequest, OrderService_GetOrdersByDeliveryPersonServer) error + DeleteOrder(context.Context, *DeleteOrderRequest) (*Confirmation, error) + Health(context.Context, *Empty) (*Confirmation, error) + mustEmbedUnimplementedOrderServiceServer() +} + +// UnimplementedOrderServiceServer must be embedded to have forward compatible implementations. +type UnimplementedOrderServiceServer struct { +} + +func (UnimplementedOrderServiceServer) CreateOrder(context.Context, *Order) (*Confirmation, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateOrder not implemented") +} +func (UnimplementedOrderServiceServer) GetOrder(context.Context, *GetOrderRequest) (*Order, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetOrder not implemented") +} +func (UnimplementedOrderServiceServer) UpdateOrder(context.Context, *Order) (*Confirmation, error) { + return nil, status.Errorf(codes.Unimplemented, "method UpdateOrder not implemented") +} +func (UnimplementedOrderServiceServer) GetOrdersBySeller(*GetOrdersRequest, OrderService_GetOrdersBySellerServer) error { + return status.Errorf(codes.Unimplemented, "method GetOrdersBySeller not implemented") +} +func (UnimplementedOrderServiceServer) GetOrdersByDeliveryPerson(*GetOrdersRequest, OrderService_GetOrdersByDeliveryPersonServer) error { + return status.Errorf(codes.Unimplemented, "method GetOrdersByDeliveryPerson not implemented") +} +func (UnimplementedOrderServiceServer) DeleteOrder(context.Context, *DeleteOrderRequest) (*Confirmation, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeleteOrder not implemented") +} +func (UnimplementedOrderServiceServer) Health(context.Context, *Empty) (*Confirmation, error) { + return nil, status.Errorf(codes.Unimplemented, "method Health not implemented") +} +func (UnimplementedOrderServiceServer) mustEmbedUnimplementedOrderServiceServer() {} + +// UnsafeOrderServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to OrderServiceServer will +// result in compilation errors. +type UnsafeOrderServiceServer interface { + mustEmbedUnimplementedOrderServiceServer() +} + +func RegisterOrderServiceServer(s grpc.ServiceRegistrar, srv OrderServiceServer) { + s.RegisterService(&OrderService_ServiceDesc, srv) +} + +func _OrderService_CreateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Order) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).CreateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.blazc.OrderService/CreateOrder", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).CreateOrder(ctx, req.(*Order)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_GetOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).GetOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.blazc.OrderService/GetOrder", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).GetOrder(ctx, req.(*GetOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_UpdateOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Order) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).UpdateOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.blazc.OrderService/UpdateOrder", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).UpdateOrder(ctx, req.(*Order)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_GetOrdersBySeller_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(GetOrdersRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(OrderServiceServer).GetOrdersBySeller(m, &orderServiceGetOrdersBySellerServer{stream}) +} + +type OrderService_GetOrdersBySellerServer interface { + Send(*Order) error + grpc.ServerStream +} + +type orderServiceGetOrdersBySellerServer struct { + grpc.ServerStream +} + +func (x *orderServiceGetOrdersBySellerServer) Send(m *Order) error { + return x.ServerStream.SendMsg(m) +} + +func _OrderService_GetOrdersByDeliveryPerson_Handler(srv interface{}, stream grpc.ServerStream) error { + m := new(GetOrdersRequest) + if err := stream.RecvMsg(m); err != nil { + return err + } + return srv.(OrderServiceServer).GetOrdersByDeliveryPerson(m, &orderServiceGetOrdersByDeliveryPersonServer{stream}) +} + +type OrderService_GetOrdersByDeliveryPersonServer interface { + Send(*Order) error + grpc.ServerStream +} + +type orderServiceGetOrdersByDeliveryPersonServer struct { + grpc.ServerStream +} + +func (x *orderServiceGetOrdersByDeliveryPersonServer) Send(m *Order) error { + return x.ServerStream.SendMsg(m) +} + +func _OrderService_DeleteOrder_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteOrderRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).DeleteOrder(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.blazc.OrderService/DeleteOrder", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).DeleteOrder(ctx, req.(*DeleteOrderRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _OrderService_Health_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(Empty) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(OrderServiceServer).Health(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/com.blazc.OrderService/Health", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(OrderServiceServer).Health(ctx, req.(*Empty)) + } + return interceptor(ctx, in, info, handler) +} + +// OrderService_ServiceDesc is the grpc.ServiceDesc for OrderService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var OrderService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "com.blazc.OrderService", + HandlerType: (*OrderServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateOrder", + Handler: _OrderService_CreateOrder_Handler, + }, + { + MethodName: "GetOrder", + Handler: _OrderService_GetOrder_Handler, + }, + { + MethodName: "UpdateOrder", + Handler: _OrderService_UpdateOrder_Handler, + }, + { + MethodName: "DeleteOrder", + Handler: _OrderService_DeleteOrder_Handler, + }, + { + MethodName: "Health", + Handler: _OrderService_Health_Handler, + }, + }, + Streams: []grpc.StreamDesc{ + { + StreamName: "GetOrdersBySeller", + Handler: _OrderService_GetOrdersBySeller_Handler, + ServerStreams: true, + }, + { + StreamName: "GetOrdersByDeliveryPerson", + Handler: _OrderService_GetOrdersByDeliveryPerson_Handler, + ServerStreams: true, + }, + }, + Metadata: "order_service.proto", +} diff --git a/API_GatewayMobile/DataStructures/main.go b/API_GatewayMobile/DataStructures/main.go new file mode 100644 index 0000000..8b02098 --- /dev/null +++ b/API_GatewayMobile/DataStructures/main.go @@ -0,0 +1,49 @@ +package DataStructures + +import ( + "go.mongodb.org/mongo-driver/bson/primitive" +) + +type User struct { + Id primitive.ObjectID `json:"id" bson:"_id,omitempty"` + Name string `json:"name" bson:"name"` + Lastname string `json:"lastname" bson:"lastname"` + Email string `json:"email" bson:"email"` + Password string `json:"password" bson:"password"` + Phone string `json:"phone" bson:"phone"` + Role string `json:"role" bson:"role"` +} + +type Restaurant struct { + Id primitive.ObjectID `json:"id" bson:"_id,omitempty"` + Name string `json:"name" bson:"name"` + Address string `json:"address" bson:"address"` + Contact string `json:"contact" bson:"contact"` +} + +type Product struct { + Id primitive.ObjectID `json:"id" bson:"_id,omitempty"` + RestaurantId primitive.ObjectID `json:"restaurantId" bson:"restaurantId"` + Name string `json:"name" bson:"name"` + Price int32 `json:"price" bson:"price"` // in cents +} + +type Order struct { + Id primitive.ObjectID `json:"id" bson:"_id,omitempty"` + SellerId primitive.ObjectID `json:"sellerId" bson:"sellerId"` + DeliveryPersonId primitive.ObjectID `json:"deliveryPersonId" bson:"deliveryPersonId"` + Address string `json:"address" bson:"address"` + CustomerName string `json:"customerName" bson:"customerName"` + OrderItems []OrderItem `json:"items" bson:"items"` + Status string `json:"status" bson:"status"` + Timestamp int64 `json:"timestamp" bson:"timestamp"` + PaymentType string `json:"paymentType" bson:"paymentType"` + TotalPrice int32 `json:"totalPrice" bson:"totalPrice"` // in cents +} + +type OrderItem struct { + Id primitive.ObjectID `json:"id" bson:"_id,omitempty"` + Product Product `json:"product" bson:"product"` + Quantity int32 `json:"quantity" bson:"quantity"` + Price int32 `json:"price" bson:"price"` // in cents +} diff --git a/API_GatewayMobile/DataStructures/order_service.proto b/API_GatewayMobile/DataStructures/order_service.proto new file mode 100644 index 0000000..18cc237 --- /dev/null +++ b/API_GatewayMobile/DataStructures/order_service.proto @@ -0,0 +1,74 @@ +syntax = "proto3"; + +package com.blazc; + +option go_package = "com.blazc"; + +service OrderService { + rpc CreateOrder (Order) returns (Confirmation) {} + rpc GetOrder (GetOrderRequest) returns (Order) {} + rpc UpdateOrder (Order) returns (Confirmation) {} + rpc GetOrdersBySeller (GetOrdersRequest) returns (stream Order) {} + rpc GetOrdersByDeliveryPerson (GetOrdersRequest) returns (stream Order) {} + rpc DeleteOrder (DeleteOrderRequest) returns (Confirmation) {} + rpc Health (Empty) returns (Confirmation) {} +} + +message Empty {} + +message Confirmation { + string message = 2; + string error = 3; +} + +message GetOrdersRequest { + string id = 1; +} + +message GetOrderRequest { + string id = 1; +} + +message DeleteOrderRequest { + string id = 1; +} + +message Order { + string id = 1; + string sellerId = 2; + string deliveryPersonId = 3; + string address = 4; + string customerName = 5; + repeated OrderItem items = 6; + OrderStatus status = 7; + int64 timestamp = 8; + PaymentType paymentType = 9; + int32 totalPrice = 10; +} + +message OrderItem { + string id = 1; + Product product = 2; + int32 quantity = 3; + int32 price = 4; +} + +message Product { + string id = 1; + string name = 2; + int32 price = 3; +} + +enum PaymentType { + CREDIT_CARD = 0; + CASH = 2; +} + +enum OrderStatus { + PENDING = 0; + PREPARING = 1; + READY_FOR_PICKUP = 2; + DELIVERING = 3; + DELIVERED = 4; + CANCELLED = 5; +} \ No newline at end of file diff --git a/API_GatewayMobile/Dockerfile b/API_GatewayMobile/Dockerfile new file mode 100644 index 0000000..9d804a5 --- /dev/null +++ b/API_GatewayMobile/Dockerfile @@ -0,0 +1,15 @@ +FROM golang:alpine as builder + +WORKDIR /app + +COPY . . + +RUN go build -o /build + +FROM alpine:latest + +COPY --from=builder /build /app/build + +EXPOSE 8080 + +CMD [ "/app/build" ] \ No newline at end of file diff --git a/API_GatewayMobile/HTTP_API/Order.go b/API_GatewayMobile/HTTP_API/Order.go new file mode 100644 index 0000000..38b5625 --- /dev/null +++ b/API_GatewayMobile/HTTP_API/Order.go @@ -0,0 +1,72 @@ +package HTTP_API + +import ( + "API_GatewayMobile/DataStructures" + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +func (a *Controller) createOrder(ctx *gin.Context) { + var order DataStructures.Order + err := ctx.BindJSON(&order) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + createdOrder, err := a.logic.CreateOrder(ctx.Request.Context(), order) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, createdOrder) +} + +func (a *Controller) updateOrder(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + confirmation, err := a.logic.UpdateOrder(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, confirmation) +} + +func (a *Controller) deleteOrder(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + confirmation, err := a.logic.DeleteOrder(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, confirmation) +} + +func (a *Controller) getOrdersBySellerId(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + orders, err := a.logic.GetOrdersBySellerId(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, orders) +} diff --git a/API_GatewayMobile/HTTP_API/Product.go b/API_GatewayMobile/HTTP_API/Product.go new file mode 100644 index 0000000..2e42ae5 --- /dev/null +++ b/API_GatewayMobile/HTTP_API/Product.go @@ -0,0 +1,38 @@ +package HTTP_API + +import ( + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +func (a *Controller) getAllProductsByRestaurantId(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + restaurant, err := a.logic.GetAllProductsByRestaurantId(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, restaurant) +} + +func (a *Controller) getProductById(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + product, err := a.logic.GetProductById(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, product) +} diff --git a/API_GatewayMobile/HTTP_API/Restaurant.go b/API_GatewayMobile/HTTP_API/Restaurant.go new file mode 100644 index 0000000..86e4555 --- /dev/null +++ b/API_GatewayMobile/HTTP_API/Restaurant.go @@ -0,0 +1,32 @@ +package HTTP_API + +import ( + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +func (a *Controller) getAllRestaurants(ctx *gin.Context) { + restaurants, err := a.logic.GetAllRestaurants(ctx.Request.Context()) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, restaurants) +} + +func (a *Controller) getRestaurantById(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + restaurant, err := a.logic.GetRestaurantById(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, restaurant) +} diff --git a/API_GatewayMobile/HTTP_API/Routes.go b/API_GatewayMobile/HTTP_API/Routes.go new file mode 100644 index 0000000..a353db4 --- /dev/null +++ b/API_GatewayMobile/HTTP_API/Routes.go @@ -0,0 +1,36 @@ +package HTTP_API + +import "github.com/gin-gonic/gin" + +func (a *Controller) registerRoutes(engine *gin.Engine) { + + api := engine.Group("/api/v1") + api.GET("/", a.Ping) + + a.registerUserRoutes(api.Group("/users")) + a.registerRestaurantRoutes(api.Group("/restaurants")) + a.registerProductRoutes(api.Group("/products")) + a.registerOrderRoutes(api.Group("/orders")) +} + +func (a *Controller) registerUserRoutes(api *gin.RouterGroup) { + api.GET("/", a.getAllUsers) + api.GET("/:id", a.getUserById) +} + +func (a *Controller) registerRestaurantRoutes(api *gin.RouterGroup) { + api.GET("/", a.getAllRestaurants) + api.GET("/:id", a.getRestaurantById) +} + +func (a *Controller) registerProductRoutes(api *gin.RouterGroup) { + api.GET("/restaurant/:id", a.getAllProductsByRestaurantId) + api.GET("/:id", a.getProductById) +} + +func (a *Controller) registerOrderRoutes(api *gin.RouterGroup) { + api.POST("/", a.createOrder) + api.GET("/restaurant/:id", a.getOrdersBySellerId) + api.PUT("/:id", a.updateOrder) + api.DELETE("/:id", a.deleteOrder) +} diff --git a/API_GatewayMobile/HTTP_API/User.go b/API_GatewayMobile/HTTP_API/User.go new file mode 100644 index 0000000..755ef0b --- /dev/null +++ b/API_GatewayMobile/HTTP_API/User.go @@ -0,0 +1,32 @@ +package HTTP_API + +import ( + "github.com/gin-gonic/gin" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +func (a *Controller) getAllUsers(ctx *gin.Context) { + users, err := a.logic.GetAllUsers(ctx.Request.Context()) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, users) +} + +func (a *Controller) getUserById(ctx *gin.Context) { + id, err := primitive.ObjectIDFromHex(ctx.Param("id")) + if err != nil { + ctx.JSON(400, gin.H{"error": err.Error()}) + return + } + + user, err := a.logic.GetUserById(ctx.Request.Context(), id) + if err != nil { + ctx.JSON(500, gin.H{"error": err.Error()}) + return + } + + ctx.JSON(200, user) +} diff --git a/API_GatewayMobile/HTTP_API/main.go b/API_GatewayMobile/HTTP_API/main.go new file mode 100644 index 0000000..e03134b --- /dev/null +++ b/API_GatewayMobile/HTTP_API/main.go @@ -0,0 +1,69 @@ +package HTTP_API + +import ( + "API_GatewayMobile/Logic" + "context" + "fmt" + "github.com/gin-gonic/gin" + "net/http" + "os" + "time" +) + +type Controller struct { + logic *Logic.Controller + done chan bool +} + +func New(logic *Logic.Controller) *Controller { + return &Controller{ + logic: logic, + } +} + +func (a *Controller) Start() { + + engine := gin.Default() + a.registerRoutes(engine) + + a.done = make(chan bool, 0) + + srv := &http.Server{ + Addr: ":8080", + Handler: engine, + ReadTimeout: 20 * time.Second, + WriteTimeout: 30 * time.Second, + } + + go func() { + + <-a.done + + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) + defer cancel() + + srv.SetKeepAlivesEnabled(false) + if err := srv.Shutdown(ctx); err != nil { + fmt.Println(err.Error()) + } + + }() + + go func() { + + if err := srv.ListenAndServe(); err != nil && err != http.ErrServerClosed { + fmt.Println(err.Error()) + } + os.Exit(1) + + }() + +} + +func (a *Controller) Stop() { + a.done <- true +} + +func (a *Controller) Ping(c *gin.Context) { + c.JSON(http.StatusOK, "pong") +} diff --git a/API_GatewayMobile/Logic/Order.go b/API_GatewayMobile/Logic/Order.go new file mode 100644 index 0000000..2c0e187 --- /dev/null +++ b/API_GatewayMobile/Logic/Order.go @@ -0,0 +1,85 @@ +package Logic + +import ( + "API_GatewayMobile/DataStructures" + pb "API_GatewayMobile/DataStructures/com.blazc" + "API_GatewayMobile/pkg/Converter" + "context" + "fmt" + "go.mongodb.org/mongo-driver/bson/primitive" +) + +func (c *Controller) Health(ctx context.Context) (status string, err error) { + confirmation, err := c.grpc.Client.Health(ctx, &pb.Empty{}) + if err != nil { + fmt.Println(err.Error()) + return + } + + status = confirmation.Message + return +} + +func (c *Controller) CreateOrder(ctx context.Context, order DataStructures.Order) (confirmation *pb.Confirmation, err error) { + + orderGrpc := Converter.ConvertOrderToGrpc(order) + + confirmation, err = c.grpc.Client.CreateOrder(ctx, orderGrpc) + if err != nil { + fmt.Println(err.Error()) + return + } + + return +} + +func (c *Controller) UpdateOrder(ctx context.Context, id primitive.ObjectID) (confirmation *pb.Confirmation, err error) { + confirmation, err = c.grpc.Client.UpdateOrder(ctx, &pb.Order{Id: id.Hex()}) + if err != nil { + fmt.Println(err.Error()) + return + } + + return +} + +func (c *Controller) DeleteOrder(ctx context.Context, id primitive.ObjectID) (confirmation *pb.Confirmation, err error) { + confirmation, err = c.grpc.Client.DeleteOrder(ctx, &pb.DeleteOrderRequest{Id: id.Hex()}) + if err != nil { + fmt.Println(err.Error()) + return + } + + return +} + +func (c *Controller) GetOrdersBySellerId(ctx context.Context, id primitive.ObjectID) (orders []DataStructures.Order, err error) { + orderStream, err := c.grpc.Client.GetOrdersBySeller(ctx, &pb.GetOrdersRequest{Id: id.Hex()}) + if err != nil { + fmt.Println(err.Error()) + return + } + + orders = make([]DataStructures.Order, 0) + + fmt.Println("Getting orders") + + for { + orderGrpc, err := orderStream.Recv() + if err != nil { + fmt.Println(err.Error()) + break + } + + order, err := Converter.ConvertOrderFromGrpc(orderGrpc) + if err != nil { + fmt.Println(err.Error()) + continue + } + + fmt.Println(order) + orders = append(orders, order) + } + + return +} diff --git a/API_GatewayMobile/Logic/Product.go b/API_GatewayMobile/Logic/Product.go new file mode 100644 index 0000000..39c3e22 --- /dev/null +++ b/API_GatewayMobile/Logic/Product.go @@ -0,0 +1,60 @@ +package Logic + +import ( + "API_GatewayMobile/DataStructures" + "context" + "encoding/json" + "fmt" + "go.mongodb.org/mongo-driver/bson/primitive" + "net/http" +) + +func (c *Controller) GetAllProductsByRestaurantId(ctx context.Context, id primitive.ObjectID) (products []DataStructures.Product, err error) { + url := fmt.Sprintf("%s/product/restaurant/%s", getEnv("RESTAURANTS_API", "http://localhost:8082"), id.Hex()) + + request, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err.Error()) + return + } + + response, err := c.httpClient.Do(request) + if err != nil { + fmt.Println(err.Error()) + return + } + defer response.Body.Close() + + err = json.NewDecoder(response.Body).Decode(&products) + if err != nil { + fmt.Println(err.Error()) + return nil, err + } + + return +} + +func (c *Controller) GetProductById(ctx context.Context, id primitive.ObjectID) (product DataStructures.Product, err error) { + url := fmt.Sprintf("%s/product/%s", getEnv("RESTAURANTS_API", "http://localhost:8082"), id.Hex()) + + request, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err.Error()) + return + } + + response, err := c.httpClient.Do(request) + if err != nil { + fmt.Println(err.Error()) + return + } + defer response.Body.Close() + + err = json.NewDecoder(response.Body).Decode(&product) + if err != nil { + fmt.Println(err.Error()) + return + } + + return +} diff --git a/API_GatewayMobile/Logic/Restaurant.go b/API_GatewayMobile/Logic/Restaurant.go new file mode 100644 index 0000000..e24ba2a --- /dev/null +++ b/API_GatewayMobile/Logic/Restaurant.go @@ -0,0 +1,62 @@ +package Logic + +import ( + "API_GatewayMobile/DataStructures" + "context" + "encoding/json" + "fmt" + "go.mongodb.org/mongo-driver/bson/primitive" + "net/http" +) + +func (c *Controller) GetAllRestaurants(ctx context.Context) (restaurants []DataStructures.Restaurant, err error) { + url := fmt.Sprintf("%s/restaurant", getEnv("RESTAURANTS_API", "http://localhost:8082")) + + request, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err.Error()) + return + } + + response, err := c.httpClient.Do(request) + if err != nil { + fmt.Println(err.Error()) + return + } + defer response.Body.Close() + + err = json.NewDecoder(response.Body).Decode(&restaurants) + if err != nil { + fmt.Println(err.Error()) + return nil, err + } + + return +} + +func (c *Controller) GetRestaurantById(ctx context.Context, id primitive.ObjectID) (restaurant DataStructures.Restaurant, err error) { + url := fmt.Sprintf("%s/restaurant/%s", getEnv("RESTAURANTS_API", "http://localhost:8082"), id.Hex()) + + fmt.Println(url) + + request, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err.Error()) + return + } + + response, err := c.httpClient.Do(request) + if err != nil { + fmt.Println(err.Error()) + return + } + defer response.Body.Close() + + err = json.NewDecoder(response.Body).Decode(&restaurant) + if err != nil { + fmt.Println(err.Error()) + return + } + + return +} diff --git a/API_GatewayMobile/Logic/User.go b/API_GatewayMobile/Logic/User.go new file mode 100644 index 0000000..159860d --- /dev/null +++ b/API_GatewayMobile/Logic/User.go @@ -0,0 +1,60 @@ +package Logic + +import ( + "API_GatewayMobile/DataStructures" + "context" + "encoding/json" + "fmt" + "go.mongodb.org/mongo-driver/bson/primitive" + "net/http" +) + +func (c *Controller) GetAllUsers(ctx context.Context) (users []DataStructures.User, err error) { + url := fmt.Sprintf("%s/users", getEnv("USERS_API", "http://localhost:8081/api/v1")) + + request, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err.Error()) + return + } + + response, err := c.httpClient.Do(request) + if err != nil { + fmt.Println(err.Error()) + return + } + defer response.Body.Close() + + err = json.NewDecoder(response.Body).Decode(&users) + if err != nil { + fmt.Println(err.Error()) + return nil, err + } + + return +} + +func (c *Controller) GetUserById(ctx context.Context, id primitive.ObjectID) (user DataStructures.User, err error) { + url := fmt.Sprintf("%s/users/%s", getEnv("USERS_API", "http://localhost:8081/api/v1"), id.Hex()) + + request, err := http.NewRequest("GET", url, nil) + if err != nil { + fmt.Println(err.Error()) + return + } + + response, err := c.httpClient.Do(request) + if err != nil { + fmt.Println(err.Error()) + return + } + defer response.Body.Close() + + err = json.NewDecoder(response.Body).Decode(&user) + if err != nil { + fmt.Println(err.Error()) + return + } + + return +} diff --git a/API_GatewayMobile/Logic/main.go b/API_GatewayMobile/Logic/main.go new file mode 100644 index 0000000..104d67c --- /dev/null +++ b/API_GatewayMobile/Logic/main.go @@ -0,0 +1,28 @@ +package Logic + +import ( + "API_GatewayMobile/gRPC_Client" + "net/http" + "os" +) + +type Controller struct { + httpClient *http.Client + grpc *gRPC_Client.Controller +} + +func New(grpc *gRPC_Client.Controller) (*Controller, error) { + httpClient := &http.Client{} + + return &Controller{ + httpClient: httpClient, + grpc: grpc, + }, nil +} + +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} diff --git a/API_GatewayMobile/docker-compose.yml b/API_GatewayMobile/docker-compose.yml new file mode 100644 index 0000000..2bc6cc8 --- /dev/null +++ b/API_GatewayMobile/docker-compose.yml @@ -0,0 +1,9 @@ +version: '3.9' + +services: + api_gateway_web: + container_name: api_gateway_web + build: . + ports: + - "8081:8080" + restart: always \ No newline at end of file diff --git a/API_GatewayMobile/gRPC_Client/main.go b/API_GatewayMobile/gRPC_Client/main.go new file mode 100644 index 0000000..6e731dc --- /dev/null +++ b/API_GatewayMobile/gRPC_Client/main.go @@ -0,0 +1,38 @@ +package gRPC_Client + +import ( + "API_GatewayMobile/DataStructures/com.blazc" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials/insecure" + "os" +) + +type Controller struct { + Client com_blazc.OrderServiceClient +} + +func NewController() *Controller { + return &Controller{} +} + +func (c *Controller) EstablishConnection() (err error) { + + opts := []grpc.DialOption{ + grpc.WithTransportCredentials(insecure.NewCredentials()), + } + + conn, err := grpc.Dial(getEnv("ORDERS_GRPC_API", "localhost:9000"), opts...) + if err != nil { + return err + } + + c.Client = com_blazc.NewOrderServiceClient(conn) + return +} + +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} diff --git a/API_GatewayMobile/main.go b/API_GatewayMobile/main.go new file mode 100644 index 0000000..1ac5a90 --- /dev/null +++ b/API_GatewayMobile/main.go @@ -0,0 +1,45 @@ +package main + +import ( + "API_GatewayMobile/HTTP_API" + "API_GatewayMobile/Logic" + "API_GatewayMobile/gRPC_Client" + "fmt" + "os" + "os/signal" +) + +func main() { + + grpcClient := gRPC_Client.NewController() + err := grpcClient.EstablishConnection() + if err != nil { + fmt.Println(err.Error()) + return + } + + fmt.Println("gRPC connection established") + + logicController, err := Logic.New(grpcClient) + if err != nil { + fmt.Println(err.Error()) + return + } + + httpAPI := HTTP_API.New(logicController) + httpAPI.Start() + + quit := make(chan os.Signal, 0) + signal.Notify(quit, os.Interrupt) + + <-quit + + httpAPI.Stop() +} + +func getEnv(key, fallback string) string { + if value, ok := os.LookupEnv(key); ok { + return value + } + return fallback +} diff --git a/API_GatewayMobile/pkg/Converter/OrdersGrpc.go b/API_GatewayMobile/pkg/Converter/OrdersGrpc.go new file mode 100644 index 0000000..5d977cd --- /dev/null +++ b/API_GatewayMobile/pkg/Converter/OrdersGrpc.go @@ -0,0 +1,122 @@ +package Converter + +import ( + "API_GatewayMobile/DataStructures" + pb "API_GatewayMobile/DataStructures/com.blazc" + "go.mongodb.org/mongo-driver/bson/primitive" + "time" +) + +func ConvertFromOrderStatusString(status string) (orderStatus pb.OrderStatus) { + switch status { + case "PENDING": + orderStatus = pb.OrderStatus_PENDING + case "PREPARING": + orderStatus = pb.OrderStatus_PREPARING + case "READY_FOR_PICKUP": + orderStatus = pb.OrderStatus_READY_FOR_PICKUP + case "DELIVERING": + orderStatus = pb.OrderStatus_DELIVERING + case "DELIVERED": + orderStatus = pb.OrderStatus_DELIVERED + case "CANCELLED": + orderStatus = pb.OrderStatus_CANCELLED + } + return +} + +func ConvertFromPaymentTypeString(paymentType string) (paymentTypeGrpc pb.PaymentType) { + switch paymentType { + case "CASH": + paymentTypeGrpc = pb.PaymentType_CASH + case "CREDIT_CARD": + paymentTypeGrpc = pb.PaymentType_CREDIT_CARD + } + return + +} + +func ConvertOrderToGrpc(order DataStructures.Order) (orderGrpc *pb.Order) { + + orderItemsGrpc := make([]*pb.OrderItem, 0) + for _, item := range order.OrderItems { + orderItemsGrpc = append(orderItemsGrpc, &pb.OrderItem{ + Id: item.Id.Hex(), + Price: item.Price, + Quantity: item.Quantity, + Product: &pb.Product{ + Id: item.Id.Hex(), + Name: item.Product.Name, + Price: item.Product.Price, + }, + }) + } + + orderGrpc = &pb.Order{ + Id: order.Id.Hex(), + SellerId: order.SellerId.Hex(), + DeliveryPersonId: order.DeliveryPersonId.Hex(), + Address: order.Address, + CustomerName: order.CustomerName, + Items: orderItemsGrpc, + Status: ConvertFromOrderStatusString(order.Status), + Timestamp: time.Now().UTC().Unix(), + PaymentType: ConvertFromPaymentTypeString(order.PaymentType), + TotalPrice: order.TotalPrice, + } + + return +} + +func ConvertOrderFromGrpc(orderGrpc *pb.Order) (order DataStructures.Order, err error) { + + order.Id, err = primitive.ObjectIDFromHex(orderGrpc.Id) + if err != nil { + return + } + + order.SellerId, err = primitive.ObjectIDFromHex(orderGrpc.SellerId) + if err != nil { + return + } + + order.DeliveryPersonId, err = primitive.ObjectIDFromHex(orderGrpc.DeliveryPersonId) + if err != nil { + return + } + + order.Address = orderGrpc.Address + order.CustomerName = orderGrpc.CustomerName + + items := make([]DataStructures.OrderItem, 0) + for _, item := range orderGrpc.Items { + id, err := primitive.ObjectIDFromHex(item.Id) + if err != nil { + return order, err + } + + productId, err := primitive.ObjectIDFromHex(item.Product.Id) + if err != nil { + return order, err + } + + orderItem := DataStructures.OrderItem{ + Id: id, + Price: item.Price, + Quantity: item.Quantity, + Product: DataStructures.Product{ + Id: productId, + Name: item.Product.Name, + Price: item.Product.Price, + }, + } + items = append(items, orderItem) + } + + order.OrderItems = items + order.Status = orderGrpc.Status.String() + order.Timestamp = orderGrpc.Timestamp + order.PaymentType = orderGrpc.PaymentType.String() + order.TotalPrice = orderGrpc.TotalPrice + return +} diff --git a/docker-compose.yml b/docker-compose.yml index c38fb26..48b5f81 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -93,6 +93,23 @@ services: networks: - native + ### API Gateway for Mobile + mobile-api-gateway: + build: + context: API_GatewayMobile + dockerfile: Dockerfile + restart: always + environment: + USERS_API: http://user-management-api:8080/api/v1 + RESTAURANTS_API: http://restaurant-management-api:8080 + ORDERS_GRPC_API: order-processing-grpc-api:9000 + expose: + - 8080 + ports: + - "8081:8080" + networks: + - native + networks: native: name: native-network