diff --git a/protobuf/friend_bill.proto b/protobuf/friend_bill.proto new file mode 100644 index 0000000..12039ca --- /dev/null +++ b/protobuf/friend_bill.proto @@ -0,0 +1,71 @@ +syntax = "proto3"; +option go_package = "github.com/SpeedReach/monify"; + +import "google/api/annotations.proto"; +import "google/protobuf/empty.proto"; + +service FriendBillService { + rpc CreateFriendBill(CreateFriendBillRequest) returns (CreateFriendBillResponse) { + option (google.api.http) = { + post: "/v1/friend_bill" + body: "*" + }; + } + + rpc DeleteFriendBill(DeleteFriendBillRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + delete: "/v1/friend_bill" + }; + } + + rpc ModifyFriendBill(ModifyFriendBillRequest) returns (google.protobuf.Empty) { + option (google.api.http) = { + put: "/v1/friend_bill" + body: "*" + }; + } + + rpc ListFriendBill (ListFriendBillRequest) returns (ListFriendBillResponse) { + option (google.api.http) = { + get: "/v1/friend_bill" + }; + } +} + +message CreateFriendBillRequest { + string relation_id = 1; + double amount = 2; + string title = 3; + string description = 4; +} + +message CreateFriendBillResponse { + string friend_bill_id = 1; +} + +message DeleteFriendBillRequest { + string friend_bill_id = 1; +} + +message ModifyFriendBillRequest { + string friend_bill_id = 1; + double amount = 2; + string title = 3; + string description = 4; +} + +message ListFriendBillRequest { + string relation_id = 1; +} + +message ListFriendBillResponse { + repeated FriendBill friend_bills = 1; + //double total = 2; +} + +message FriendBill { + string friend_bill_id = 1; + double amount = 2; + string title = 3; + string description = 4; +} \ No newline at end of file diff --git a/protobuf/gen/go/friend_bill.pb.go b/protobuf/gen/go/friend_bill.pb.go new file mode 100644 index 0000000..07f73c1 --- /dev/null +++ b/protobuf/gen/go/friend_bill.pb.go @@ -0,0 +1,656 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.28.1 +// protoc v5.27.0 +// source: friend_bill.proto + +package monify + +import ( + _ "google.golang.org/genproto/googleapis/api/annotations" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" + emptypb "google.golang.org/protobuf/types/known/emptypb" + 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 CreateFriendBillRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + RelationId string `protobuf:"bytes,1,opt,name=relation_id,json=relationId,proto3" json:"relation_id,omitempty"` + Amount float64 `protobuf:"fixed64,2,opt,name=amount,proto3" json:"amount,omitempty"` + Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` +} + +func (x *CreateFriendBillRequest) Reset() { + *x = CreateFriendBillRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateFriendBillRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateFriendBillRequest) ProtoMessage() {} + +func (x *CreateFriendBillRequest) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 CreateFriendBillRequest.ProtoReflect.Descriptor instead. +func (*CreateFriendBillRequest) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{0} +} + +func (x *CreateFriendBillRequest) GetRelationId() string { + if x != nil { + return x.RelationId + } + return "" +} + +func (x *CreateFriendBillRequest) GetAmount() float64 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *CreateFriendBillRequest) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *CreateFriendBillRequest) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +type CreateFriendBillResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FriendBillId string `protobuf:"bytes,1,opt,name=friend_bill_id,json=friendBillId,proto3" json:"friend_bill_id,omitempty"` +} + +func (x *CreateFriendBillResponse) Reset() { + *x = CreateFriendBillResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *CreateFriendBillResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*CreateFriendBillResponse) ProtoMessage() {} + +func (x *CreateFriendBillResponse) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 CreateFriendBillResponse.ProtoReflect.Descriptor instead. +func (*CreateFriendBillResponse) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{1} +} + +func (x *CreateFriendBillResponse) GetFriendBillId() string { + if x != nil { + return x.FriendBillId + } + return "" +} + +type DeleteFriendBillRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FriendBillId string `protobuf:"bytes,1,opt,name=friend_bill_id,json=friendBillId,proto3" json:"friend_bill_id,omitempty"` +} + +func (x *DeleteFriendBillRequest) Reset() { + *x = DeleteFriendBillRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *DeleteFriendBillRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*DeleteFriendBillRequest) ProtoMessage() {} + +func (x *DeleteFriendBillRequest) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 DeleteFriendBillRequest.ProtoReflect.Descriptor instead. +func (*DeleteFriendBillRequest) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{2} +} + +func (x *DeleteFriendBillRequest) GetFriendBillId() string { + if x != nil { + return x.FriendBillId + } + return "" +} + +type ModifyFriendBillRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FriendBillId string `protobuf:"bytes,1,opt,name=friend_bill_id,json=friendBillId,proto3" json:"friend_bill_id,omitempty"` + Amount float64 `protobuf:"fixed64,2,opt,name=amount,proto3" json:"amount,omitempty"` + Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` +} + +func (x *ModifyFriendBillRequest) Reset() { + *x = ModifyFriendBillRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ModifyFriendBillRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ModifyFriendBillRequest) ProtoMessage() {} + +func (x *ModifyFriendBillRequest) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 ModifyFriendBillRequest.ProtoReflect.Descriptor instead. +func (*ModifyFriendBillRequest) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{3} +} + +func (x *ModifyFriendBillRequest) GetFriendBillId() string { + if x != nil { + return x.FriendBillId + } + return "" +} + +func (x *ModifyFriendBillRequest) GetAmount() float64 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *ModifyFriendBillRequest) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *ModifyFriendBillRequest) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +type ListFriendBillRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + RelationId string `protobuf:"bytes,1,opt,name=relation_id,json=relationId,proto3" json:"relation_id,omitempty"` +} + +func (x *ListFriendBillRequest) Reset() { + *x = ListFriendBillRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListFriendBillRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListFriendBillRequest) ProtoMessage() {} + +func (x *ListFriendBillRequest) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 ListFriendBillRequest.ProtoReflect.Descriptor instead. +func (*ListFriendBillRequest) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{4} +} + +func (x *ListFriendBillRequest) GetRelationId() string { + if x != nil { + return x.RelationId + } + return "" +} + +type ListFriendBillResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FriendBills []*FriendBill `protobuf:"bytes,1,rep,name=friend_bills,json=friendBills,proto3" json:"friend_bills,omitempty"` //double total = 2; +} + +func (x *ListFriendBillResponse) Reset() { + *x = ListFriendBillResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *ListFriendBillResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*ListFriendBillResponse) ProtoMessage() {} + +func (x *ListFriendBillResponse) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 ListFriendBillResponse.ProtoReflect.Descriptor instead. +func (*ListFriendBillResponse) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{5} +} + +func (x *ListFriendBillResponse) GetFriendBills() []*FriendBill { + if x != nil { + return x.FriendBills + } + return nil +} + +type FriendBill struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FriendBillId string `protobuf:"bytes,1,opt,name=friend_bill_id,json=friendBillId,proto3" json:"friend_bill_id,omitempty"` + Amount float64 `protobuf:"fixed64,2,opt,name=amount,proto3" json:"amount,omitempty"` + Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,4,opt,name=description,proto3" json:"description,omitempty"` +} + +func (x *FriendBill) Reset() { + *x = FriendBill{} + if protoimpl.UnsafeEnabled { + mi := &file_friend_bill_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FriendBill) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FriendBill) ProtoMessage() {} + +func (x *FriendBill) ProtoReflect() protoreflect.Message { + mi := &file_friend_bill_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 FriendBill.ProtoReflect.Descriptor instead. +func (*FriendBill) Descriptor() ([]byte, []int) { + return file_friend_bill_proto_rawDescGZIP(), []int{6} +} + +func (x *FriendBill) GetFriendBillId() string { + if x != nil { + return x.FriendBillId + } + return "" +} + +func (x *FriendBill) GetAmount() float64 { + if x != nil { + return x.Amount + } + return 0 +} + +func (x *FriendBill) GetTitle() string { + if x != nil { + return x.Title + } + return "" +} + +func (x *FriendBill) GetDescription() string { + if x != nil { + return x.Description + } + return "" +} + +var File_friend_bill_proto protoreflect.FileDescriptor + +var file_friend_bill_proto_rawDesc = []byte{ + 0x0a, 0x11, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x69, 0x6c, 0x6c, 0x2e, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x1a, 0x1c, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x61, 0x70, 0x69, 0x2f, + 0x61, 0x6e, 0x6e, 0x6f, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x1a, 0x1b, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x8a, + 0x01, 0x0a, 0x17, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, + 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, + 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, + 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, + 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x40, 0x0a, 0x18, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x24, 0x0a, 0x0e, 0x66, 0x72, 0x69, 0x65, 0x6e, + 0x64, 0x5f, 0x62, 0x69, 0x6c, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x49, 0x64, 0x22, 0x3f, 0x0a, + 0x17, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, + 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x66, 0x72, 0x69, 0x65, + 0x6e, 0x64, 0x5f, 0x62, 0x69, 0x6c, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x49, 0x64, 0x22, 0x8f, + 0x01, 0x0a, 0x17, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, + 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x66, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x69, 0x6c, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x49, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, + 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, + 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x20, + 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, + 0x22, 0x38, 0x0a, 0x15, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, + 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x6c, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x22, 0x48, 0x0a, 0x16, 0x4c, 0x69, + 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2e, 0x0a, 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, + 0x69, 0x6c, 0x6c, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x0b, 0x2e, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, 0x0b, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, + 0x69, 0x6c, 0x6c, 0x73, 0x22, 0x82, 0x01, 0x0a, 0x0a, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, + 0x69, 0x6c, 0x6c, 0x12, 0x24, 0x0a, 0x0e, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x69, + 0x6c, 0x6c, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x61, 0x6d, 0x6f, + 0x75, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, 0x6e, + 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x12, 0x20, 0x0a, 0x0b, 0x64, 0x65, 0x73, 0x63, 0x72, + 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, 0x65, + 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0x95, 0x03, 0x0a, 0x11, 0x46, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, + 0x63, 0x0a, 0x10, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, + 0x69, 0x6c, 0x6c, 0x12, 0x18, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x46, 0x72, 0x69, 0x65, + 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x19, 0x2e, + 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x14, + 0x22, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x69, 0x6c, + 0x6c, 0x3a, 0x01, 0x2a, 0x12, 0x5d, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x46, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x12, 0x18, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x17, 0x82, 0xd3, 0xe4, 0x93, + 0x02, 0x11, 0x2a, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, + 0x69, 0x6c, 0x6c, 0x12, 0x60, 0x0a, 0x10, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x12, 0x18, 0x2e, 0x4d, 0x6f, 0x64, 0x69, 0x66, 0x79, + 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x16, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x22, 0x1a, 0x82, 0xd3, 0xe4, 0x93, 0x02, + 0x14, 0x1a, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x69, + 0x6c, 0x6c, 0x3a, 0x01, 0x2a, 0x12, 0x5a, 0x0a, 0x0e, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, + 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x12, 0x16, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, + 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x17, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x46, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x17, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x11, + 0x12, 0x0f, 0x2f, 0x76, 0x31, 0x2f, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x5f, 0x62, 0x69, 0x6c, + 0x6c, 0x42, 0x1e, 0x5a, 0x1c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x53, 0x70, 0x65, 0x65, 0x64, 0x52, 0x65, 0x61, 0x63, 0x68, 0x2f, 0x6d, 0x6f, 0x6e, 0x69, 0x66, + 0x79, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_friend_bill_proto_rawDescOnce sync.Once + file_friend_bill_proto_rawDescData = file_friend_bill_proto_rawDesc +) + +func file_friend_bill_proto_rawDescGZIP() []byte { + file_friend_bill_proto_rawDescOnce.Do(func() { + file_friend_bill_proto_rawDescData = protoimpl.X.CompressGZIP(file_friend_bill_proto_rawDescData) + }) + return file_friend_bill_proto_rawDescData +} + +var file_friend_bill_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_friend_bill_proto_goTypes = []interface{}{ + (*CreateFriendBillRequest)(nil), // 0: CreateFriendBillRequest + (*CreateFriendBillResponse)(nil), // 1: CreateFriendBillResponse + (*DeleteFriendBillRequest)(nil), // 2: DeleteFriendBillRequest + (*ModifyFriendBillRequest)(nil), // 3: ModifyFriendBillRequest + (*ListFriendBillRequest)(nil), // 4: ListFriendBillRequest + (*ListFriendBillResponse)(nil), // 5: ListFriendBillResponse + (*FriendBill)(nil), // 6: FriendBill + (*emptypb.Empty)(nil), // 7: google.protobuf.Empty +} +var file_friend_bill_proto_depIdxs = []int32{ + 6, // 0: ListFriendBillResponse.friend_bills:type_name -> FriendBill + 0, // 1: FriendBillService.CreateFriendBill:input_type -> CreateFriendBillRequest + 2, // 2: FriendBillService.DeleteFriendBill:input_type -> DeleteFriendBillRequest + 3, // 3: FriendBillService.ModifyFriendBill:input_type -> ModifyFriendBillRequest + 4, // 4: FriendBillService.ListFriendBill:input_type -> ListFriendBillRequest + 1, // 5: FriendBillService.CreateFriendBill:output_type -> CreateFriendBillResponse + 7, // 6: FriendBillService.DeleteFriendBill:output_type -> google.protobuf.Empty + 7, // 7: FriendBillService.ModifyFriendBill:output_type -> google.protobuf.Empty + 5, // 8: FriendBillService.ListFriendBill:output_type -> ListFriendBillResponse + 5, // [5:9] is the sub-list for method output_type + 1, // [1:5] 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 +} + +func init() { file_friend_bill_proto_init() } +func file_friend_bill_proto_init() { + if File_friend_bill_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_friend_bill_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateFriendBillRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_bill_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*CreateFriendBillResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_bill_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteFriendBillRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_bill_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ModifyFriendBillRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_bill_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListFriendBillRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_bill_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*ListFriendBillResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_friend_bill_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FriendBill); 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_friend_bill_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_friend_bill_proto_goTypes, + DependencyIndexes: file_friend_bill_proto_depIdxs, + MessageInfos: file_friend_bill_proto_msgTypes, + }.Build() + File_friend_bill_proto = out.File + file_friend_bill_proto_rawDesc = nil + file_friend_bill_proto_goTypes = nil + file_friend_bill_proto_depIdxs = nil +} diff --git a/protobuf/gen/go/friend_bill.pb.gw.go b/protobuf/gen/go/friend_bill.pb.gw.go new file mode 100644 index 0000000..a61289f --- /dev/null +++ b/protobuf/gen/go/friend_bill.pb.gw.go @@ -0,0 +1,414 @@ +// Code generated by protoc-gen-grpc-gateway. DO NOT EDIT. +// source: friend_bill.proto + +/* +Package monify is a reverse proxy. + +It translates gRPC into RESTful JSON APIs. +*/ +package monify + +import ( + "context" + "io" + "net/http" + + "github.com/grpc-ecosystem/grpc-gateway/v2/runtime" + "github.com/grpc-ecosystem/grpc-gateway/v2/utilities" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/grpclog" + "google.golang.org/grpc/metadata" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +// Suppress "imported and not used" errors +var _ codes.Code +var _ io.Reader +var _ status.Status +var _ = runtime.String +var _ = utilities.NewDoubleArray +var _ = metadata.Join + +func request_FriendBillService_CreateFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, client FriendBillServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateFriendBillRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.CreateFriendBill(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_FriendBillService_CreateFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, server FriendBillServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq CreateFriendBillRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.CreateFriendBill(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_FriendBillService_DeleteFriendBill_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_FriendBillService_DeleteFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, client FriendBillServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DeleteFriendBillRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_FriendBillService_DeleteFriendBill_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.DeleteFriendBill(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_FriendBillService_DeleteFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, server FriendBillServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq DeleteFriendBillRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_FriendBillService_DeleteFriendBill_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.DeleteFriendBill(ctx, &protoReq) + return msg, metadata, err + +} + +func request_FriendBillService_ModifyFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, client FriendBillServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ModifyFriendBillRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ModifyFriendBill(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_FriendBillService_ModifyFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, server FriendBillServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ModifyFriendBillRequest + var metadata runtime.ServerMetadata + + if err := marshaler.NewDecoder(req.Body).Decode(&protoReq); err != nil && err != io.EOF { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ModifyFriendBill(ctx, &protoReq) + return msg, metadata, err + +} + +var ( + filter_FriendBillService_ListFriendBill_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_FriendBillService_ListFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, client FriendBillServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListFriendBillRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_FriendBillService_ListFriendBill_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.ListFriendBill(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_FriendBillService_ListFriendBill_0(ctx context.Context, marshaler runtime.Marshaler, server FriendBillServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq ListFriendBillRequest + var metadata runtime.ServerMetadata + + if err := req.ParseForm(); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + if err := runtime.PopulateQueryParameters(&protoReq, req.Form, filter_FriendBillService_ListFriendBill_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.ListFriendBill(ctx, &protoReq) + return msg, metadata, err + +} + +// RegisterFriendBillServiceHandlerServer registers the http handlers for service FriendBillService to "mux". +// UnaryRPC :call FriendBillServiceServer directly. +// StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. +// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterFriendBillServiceHandlerFromEndpoint instead. +func RegisterFriendBillServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server FriendBillServiceServer) error { + + mux.Handle("POST", pattern_FriendBillService_CreateFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.FriendBillService/CreateFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_FriendBillService_CreateFriendBill_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_CreateFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_FriendBillService_DeleteFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.FriendBillService/DeleteFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_FriendBillService_DeleteFriendBill_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_DeleteFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("PUT", pattern_FriendBillService_ModifyFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.FriendBillService/ModifyFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_FriendBillService_ModifyFriendBill_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_ModifyFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_FriendBillService_ListFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/.FriendBillService/ListFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_FriendBillService_ListFriendBill_0(annotatedContext, inboundMarshaler, server, req, pathParams) + md.HeaderMD, md.TrailerMD = metadata.Join(md.HeaderMD, stream.Header()), metadata.Join(md.TrailerMD, stream.Trailer()) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_ListFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +// RegisterFriendBillServiceHandlerFromEndpoint is same as RegisterFriendBillServiceHandler but +// automatically dials to "endpoint" and closes the connection when "ctx" gets done. +func RegisterFriendBillServiceHandlerFromEndpoint(ctx context.Context, mux *runtime.ServeMux, endpoint string, opts []grpc.DialOption) (err error) { + conn, err := grpc.NewClient(endpoint, opts...) + if err != nil { + return err + } + defer func() { + if err != nil { + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + return + } + go func() { + <-ctx.Done() + if cerr := conn.Close(); cerr != nil { + grpclog.Errorf("Failed to close conn to %s: %v", endpoint, cerr) + } + }() + }() + + return RegisterFriendBillServiceHandler(ctx, mux, conn) +} + +// RegisterFriendBillServiceHandler registers the http handlers for service FriendBillService to "mux". +// The handlers forward requests to the grpc endpoint over "conn". +func RegisterFriendBillServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn *grpc.ClientConn) error { + return RegisterFriendBillServiceHandlerClient(ctx, mux, NewFriendBillServiceClient(conn)) +} + +// RegisterFriendBillServiceHandlerClient registers the http handlers for service FriendBillService +// to "mux". The handlers forward requests to the grpc endpoint over the given implementation of "FriendBillServiceClient". +// Note: the gRPC framework executes interceptors within the gRPC handler. If the passed in "FriendBillServiceClient" +// doesn't go through the normal gRPC flow (creating a gRPC client etc.) then it will be up to the passed in +// "FriendBillServiceClient" to call the correct interceptors. +func RegisterFriendBillServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client FriendBillServiceClient) error { + + mux.Handle("POST", pattern_FriendBillService_CreateFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.FriendBillService/CreateFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_FriendBillService_CreateFriendBill_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_CreateFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("DELETE", pattern_FriendBillService_DeleteFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.FriendBillService/DeleteFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_FriendBillService_DeleteFriendBill_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_DeleteFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("PUT", pattern_FriendBillService_ModifyFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.FriendBillService/ModifyFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_FriendBillService_ModifyFriendBill_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_ModifyFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + mux.Handle("GET", pattern_FriendBillService_ListFriendBill_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) + var err error + var annotatedContext context.Context + annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/.FriendBillService/ListFriendBill", runtime.WithHTTPPathPattern("/v1/friend_bill")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_FriendBillService_ListFriendBill_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_FriendBillService_ListFriendBill_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + + return nil +} + +var ( + pattern_FriendBillService_CreateFriendBill_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "friend_bill"}, "")) + + pattern_FriendBillService_DeleteFriendBill_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "friend_bill"}, "")) + + pattern_FriendBillService_ModifyFriendBill_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "friend_bill"}, "")) + + pattern_FriendBillService_ListFriendBill_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1}, []string{"v1", "friend_bill"}, "")) +) + +var ( + forward_FriendBillService_CreateFriendBill_0 = runtime.ForwardResponseMessage + + forward_FriendBillService_DeleteFriendBill_0 = runtime.ForwardResponseMessage + + forward_FriendBillService_ModifyFriendBill_0 = runtime.ForwardResponseMessage + + forward_FriendBillService_ListFriendBill_0 = runtime.ForwardResponseMessage +) diff --git a/protobuf/gen/go/friend_bill_grpc.pb.go b/protobuf/gen/go/friend_bill_grpc.pb.go new file mode 100644 index 0000000..2fc1d72 --- /dev/null +++ b/protobuf/gen/go/friend_bill_grpc.pb.go @@ -0,0 +1,214 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.2.0 +// - protoc v5.27.0 +// source: friend_bill.proto + +package monify + +import ( + context "context" + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" + emptypb "google.golang.org/protobuf/types/known/emptypb" +) + +// 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 + +// FriendBillServiceClient is the client API for FriendBillService 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 FriendBillServiceClient interface { + CreateFriendBill(ctx context.Context, in *CreateFriendBillRequest, opts ...grpc.CallOption) (*CreateFriendBillResponse, error) + DeleteFriendBill(ctx context.Context, in *DeleteFriendBillRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + ModifyFriendBill(ctx context.Context, in *ModifyFriendBillRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) + ListFriendBill(ctx context.Context, in *ListFriendBillRequest, opts ...grpc.CallOption) (*ListFriendBillResponse, error) +} + +type friendBillServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewFriendBillServiceClient(cc grpc.ClientConnInterface) FriendBillServiceClient { + return &friendBillServiceClient{cc} +} + +func (c *friendBillServiceClient) CreateFriendBill(ctx context.Context, in *CreateFriendBillRequest, opts ...grpc.CallOption) (*CreateFriendBillResponse, error) { + out := new(CreateFriendBillResponse) + err := c.cc.Invoke(ctx, "/FriendBillService/CreateFriendBill", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *friendBillServiceClient) DeleteFriendBill(ctx context.Context, in *DeleteFriendBillRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, "/FriendBillService/DeleteFriendBill", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *friendBillServiceClient) ModifyFriendBill(ctx context.Context, in *ModifyFriendBillRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) { + out := new(emptypb.Empty) + err := c.cc.Invoke(ctx, "/FriendBillService/ModifyFriendBill", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *friendBillServiceClient) ListFriendBill(ctx context.Context, in *ListFriendBillRequest, opts ...grpc.CallOption) (*ListFriendBillResponse, error) { + out := new(ListFriendBillResponse) + err := c.cc.Invoke(ctx, "/FriendBillService/ListFriendBill", in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + +// FriendBillServiceServer is the server API for FriendBillService service. +// All implementations must embed UnimplementedFriendBillServiceServer +// for forward compatibility +type FriendBillServiceServer interface { + CreateFriendBill(context.Context, *CreateFriendBillRequest) (*CreateFriendBillResponse, error) + DeleteFriendBill(context.Context, *DeleteFriendBillRequest) (*emptypb.Empty, error) + ModifyFriendBill(context.Context, *ModifyFriendBillRequest) (*emptypb.Empty, error) + ListFriendBill(context.Context, *ListFriendBillRequest) (*ListFriendBillResponse, error) + mustEmbedUnimplementedFriendBillServiceServer() +} + +// UnimplementedFriendBillServiceServer must be embedded to have forward compatible implementations. +type UnimplementedFriendBillServiceServer struct { +} + +func (UnimplementedFriendBillServiceServer) CreateFriendBill(context.Context, *CreateFriendBillRequest) (*CreateFriendBillResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method CreateFriendBill not implemented") +} +func (UnimplementedFriendBillServiceServer) DeleteFriendBill(context.Context, *DeleteFriendBillRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method DeleteFriendBill not implemented") +} +func (UnimplementedFriendBillServiceServer) ModifyFriendBill(context.Context, *ModifyFriendBillRequest) (*emptypb.Empty, error) { + return nil, status.Errorf(codes.Unimplemented, "method ModifyFriendBill not implemented") +} +func (UnimplementedFriendBillServiceServer) ListFriendBill(context.Context, *ListFriendBillRequest) (*ListFriendBillResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method ListFriendBill not implemented") +} +func (UnimplementedFriendBillServiceServer) mustEmbedUnimplementedFriendBillServiceServer() {} + +// UnsafeFriendBillServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to FriendBillServiceServer will +// result in compilation errors. +type UnsafeFriendBillServiceServer interface { + mustEmbedUnimplementedFriendBillServiceServer() +} + +func RegisterFriendBillServiceServer(s grpc.ServiceRegistrar, srv FriendBillServiceServer) { + s.RegisterService(&FriendBillService_ServiceDesc, srv) +} + +func _FriendBillService_CreateFriendBill_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(CreateFriendBillRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FriendBillServiceServer).CreateFriendBill(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/FriendBillService/CreateFriendBill", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FriendBillServiceServer).CreateFriendBill(ctx, req.(*CreateFriendBillRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _FriendBillService_DeleteFriendBill_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(DeleteFriendBillRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FriendBillServiceServer).DeleteFriendBill(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/FriendBillService/DeleteFriendBill", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FriendBillServiceServer).DeleteFriendBill(ctx, req.(*DeleteFriendBillRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _FriendBillService_ModifyFriendBill_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ModifyFriendBillRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FriendBillServiceServer).ModifyFriendBill(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/FriendBillService/ModifyFriendBill", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FriendBillServiceServer).ModifyFriendBill(ctx, req.(*ModifyFriendBillRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _FriendBillService_ListFriendBill_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(ListFriendBillRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(FriendBillServiceServer).ListFriendBill(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: "/FriendBillService/ListFriendBill", + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(FriendBillServiceServer).ListFriendBill(ctx, req.(*ListFriendBillRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// FriendBillService_ServiceDesc is the grpc.ServiceDesc for FriendBillService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var FriendBillService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "FriendBillService", + HandlerType: (*FriendBillServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "CreateFriendBill", + Handler: _FriendBillService_CreateFriendBill_Handler, + }, + { + MethodName: "DeleteFriendBill", + Handler: _FriendBillService_DeleteFriendBill_Handler, + }, + { + MethodName: "ModifyFriendBill", + Handler: _FriendBillService_ModifyFriendBill_Handler, + }, + { + MethodName: "ListFriendBill", + Handler: _FriendBillService_ListFriendBill_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "friend_bill.proto", +} diff --git a/services/api/controllers/friend_bill/create.go b/services/api/controllers/friend_bill/create.go new file mode 100644 index 0000000..0fdbf65 --- /dev/null +++ b/services/api/controllers/friend_bill/create.go @@ -0,0 +1,48 @@ +package friend_bill + +import ( + "context" + "database/sql" + "monify/lib" + monify "monify/protobuf/gen/go" + + "github.com/google/uuid" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (s Service) CreateFriendBill(ctx context.Context, req *monify.CreateFriendBillRequest) (*monify.CreateFriendBillResponse, error) { + logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger) + if req.Title == "" { + return nil, status.Error(codes.InvalidArgument, "Title is required") + } + if req.Amount <= 0 { + return nil, status.Error(codes.InvalidArgument, "Amount should be more than zero") + } + _, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID) + if !ok { + return nil, status.Error(codes.Unauthenticated, "Unauthorized") + } + relationId, err := uuid.Parse(req.RelationId) + if err != nil { + return nil, status.Error(codes.InvalidArgument, "Invalid relation id") + } + + //Insert + friend_billId := uuid.New() + db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) + _, err = db.ExecContext(ctx, ` + INSERT INTO friend_bill (friend_bill_id, relation_id, amount, title, description) + VALUES ($1, $2, $3, $4, $5) + `, friend_billId, relationId, req.Amount, req.Title, req.Description) + if err != nil { + logger.Error("Insert values into friend_bill error.", zap.Error(err)) + return nil, status.Error(codes.Internal, "") + } + + return &monify.CreateFriendBillResponse{ + FriendBillId: friend_billId.String(), + }, nil + +} diff --git a/services/api/controllers/friend_bill/delete.go b/services/api/controllers/friend_bill/delete.go new file mode 100644 index 0000000..78507cd --- /dev/null +++ b/services/api/controllers/friend_bill/delete.go @@ -0,0 +1,29 @@ +package friend_bill + +import ( + "context" + "database/sql" + "monify/lib" + monify "monify/protobuf/gen/go" + + "github.com/google/uuid" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/emptypb" +) + +func (s Service) DeleteFriendBill(ctx context.Context, req *monify.DeleteFriendBillRequest) (*emptypb.Empty, error) { + logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger) + _, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID) + if !ok { + return nil, status.Error(codes.Unauthenticated, "Unauthorized.") + } + db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) + _, err := db.ExecContext(ctx, `DELETE FROM friend_bill WHERE friend_bill_id = $1`, req.FriendBillId) + if err != nil { + logger.Error("Delete friend bill error.", zap.Error(err)) + return nil, status.Error(codes.Internal, "") + } + return &emptypb.Empty{}, nil +} diff --git a/services/api/controllers/friend_bill/list_friend_bill.go b/services/api/controllers/friend_bill/list_friend_bill.go new file mode 100644 index 0000000..0a7f031 --- /dev/null +++ b/services/api/controllers/friend_bill/list_friend_bill.go @@ -0,0 +1,48 @@ +package friend_bill + +import ( + "context" + "database/sql" + "monify/lib" + monify "monify/protobuf/gen/go" + + "github.com/google/uuid" + "go.uber.org/zap" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +func (s Service) ListFriendBill(ctx context.Context, req *monify.ListFriendBillRequest) (*monify.ListFriendBillResponse, error) { + logger := ctx.Value(lib.LoggerContextKey{}).(*zap.Logger) + _, ok := ctx.Value(lib.UserIdContextKey{}).(uuid.UUID) + if !ok { + return nil, status.Error(codes.Unauthenticated, "Unauthorized.") + } + db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) + query, err := db.QueryContext(ctx, ` + SELECT friend_bill_id, amount, title, description + FROM friend_bill + WHERE relation_id = $1`, req.RelationId) + if err != nil { + logger.Error("Select friend bill information error.", zap.Error(err)) + return nil, status.Error(codes.Internal, "") + } + defer query.Close() + + var friend_bills []*monify.FriendBill + for { + if !query.Next() { + break + } + var friend_bill monify.FriendBill + if err = query.Scan(&friend_bill.FriendBillId, &friend_bill.Amount, &friend_bill.Title, &friend_bill.Description); err != nil { + logger.Error("Scan friend bill information error.", zap.Error(err)) + return nil, status.Error(codes.Internal, "") + } + friend_bills = append(friend_bills, &friend_bill) + } + + return &monify.ListFriendBillResponse{ + FriendBills: friend_bills, + }, nil +} diff --git a/services/api/controllers/friend_bill/service.go b/services/api/controllers/friend_bill/service.go new file mode 100644 index 0000000..46812ad --- /dev/null +++ b/services/api/controllers/friend_bill/service.go @@ -0,0 +1,9 @@ +package friend_bill + +import ( + monify "monify/protobuf/gen/go" +) + +type Service struct { + monify.UnimplementedFriendBillServiceServer +} diff --git a/services/api/server.go b/services/api/server.go index ee26835..1977b24 100644 --- a/services/api/server.go +++ b/services/api/server.go @@ -9,6 +9,7 @@ import ( monify "monify/protobuf/gen/go" "monify/services/api/controllers/auth" "monify/services/api/controllers/friend" + "monify/services/api/controllers/friend_bill" "monify/services/api/controllers/group" "monify/services/api/controllers/group_bill" "monify/services/api/controllers/user" @@ -51,6 +52,7 @@ func SetupServices(g *grpc.Server, config ServerConfig) { monify.RegisterGroupsBillServiceServer(g, group_bill.Service{}) monify.RegisterUserServiceServer(g, user.Service{}) monify.RegisterFriendServiceServer(g, friend.Service{}) + monify.RegisterFriendBillServiceServer(g, friend_bill.Service{}) } func setupInterceptor(resources infra.Resources, config ServerConfig) grpc.ServerOption { diff --git a/services/api/test/friend_bill_test.go b/services/api/test/friend_bill_test.go new file mode 100644 index 0000000..8906462 --- /dev/null +++ b/services/api/test/friend_bill_test.go @@ -0,0 +1,69 @@ +package test + +import ( + "context" + monify "monify/protobuf/gen/go" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestFriendBill(t *testing.T) { + // Set a friend relation + client := GetTestClient(t) + user1 := client.CreateTestUser() + _, err := client.UpdateUserNickId(context.Background(), &monify.UpdateUserNickIdRequest{NickId: "friend_bill_nickId1"}) + assert.NoError(t, err) + user2 := client.CreateTestUser() + _, err = client.UpdateUserNickId(context.Background(), &monify.UpdateUserNickIdRequest{NickId: "friend_bill_nickId2"}) + _, err = client.InviteFriend(context.TODO(), &monify.InviteFriendRequest{ReceiverNickId: "friend_bill_nickId1"}) + assert.NoError(t, err) + client.SetTestUser(user1) + invitaions, err := client.ListFriendInvitation(context.TODO(), &monify.FriendEmpty{}) + assert.NoError(t, err) + _, err = client.AcceptInvitation(context.TODO(), &monify.AcceptInvitationRequest{User1Id: user1, User2Id: user2, InviteId: invitaions.Invitation[0].InviteId}) + assert.NoError(t, err) + friends, err := client.ListFriend(context.TODO(), &monify.FriendEmpty{}) + assert.NoError(t, err) + var friendS_relationId []string + for _, friend := range friends.GetFriends() { + friendS_relationId = append(friendS_relationId, friend.RelationId) + } + + // Test create friend bill + _, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{ + RelationId: friendS_relationId[0], + Amount: 300, + Title: "test1", + Description: "test1", + }) + _, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{ + RelationId: friendS_relationId[0], + Amount: 500, + Title: "test2", + Description: "test2", + }) + assert.NoError(t, err) + _, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{ + RelationId: friendS_relationId[0], + Amount: 0, + Title: "test2", + Description: "test2", + }) + assert.Error(t, err) // Amount must not be zero + + // Test list friend bill + friend_bills, err := client.ListFriendBill(context.TODO(), &monify.ListFriendBillRequest{RelationId: friendS_relationId[0]}) + assert.NoError(t, err) + assert.Equal(t, len(friend_bills.GetFriendBills()), 2) + + // Test delete friend bill + var friend_billId []string + for _, friend_bill := range friend_bills.GetFriendBills() { + friend_billId = append(friend_billId, friend_bill.FriendBillId) + } + _, err = client.DeleteFriendBill(context.TODO(), &monify.DeleteFriendBillRequest{FriendBillId: friend_billId[0]}) + assert.NoError(t, err) + friend_bills, err = client.ListFriendBill(context.TODO(), &monify.ListFriendBillRequest{RelationId: friendS_relationId[0]}) + assert.Equal(t, len(friend_bills.GetFriendBills()), 1) +} diff --git a/services/api/test/server.go b/services/api/test/server.go index 6cc67ea..17f9b8c 100644 --- a/services/api/test/server.go +++ b/services/api/test/server.go @@ -31,6 +31,7 @@ type Client struct { monify.GroupsBillServiceClient monify.UserServiceClient monify.FriendServiceClient + monify.FriendBillServiceClient users *map[string]string currentUser *string } @@ -111,6 +112,7 @@ func createClient(lis *bufconn.Listener) Client { GroupsBillServiceClient: monify.NewGroupsBillServiceClient(conn), UserServiceClient: monify.NewUserServiceClient(conn), FriendServiceClient: monify.NewFriendServiceClient(conn), + FriendBillServiceClient: monify.NewFriendBillServiceClient(conn), users: &users, currentUser: ¤tUser, }