diff --git a/migrations/2405310815_create_friend_table.up.sql b/migrations/2405310815_create_friend_table.up.sql index baace5b..3057d02 100644 --- a/migrations/2405310815_create_friend_table.up.sql +++ b/migrations/2405310815_create_friend_table.up.sql @@ -12,8 +12,9 @@ CREATE TABLE friend_bill( friend_bill_id uuid PRIMARY KEY, relation_id uuid NOT NULL REFERENCES friend(relation_id), amount double precision NOT NULL, - title varchar(50) NOT NULL , + title varchar(50) NOT NULL, description varchar(100) NOT NULL default '', + in_debt varchar(30) NOT NULL, created_at timestamp NOT NULL default CURRENT_TIMESTAMP ) diff --git a/protobuf/friend_bill.proto b/protobuf/friend_bill.proto index 12039ca..54a86af 100644 --- a/protobuf/friend_bill.proto +++ b/protobuf/friend_bill.proto @@ -37,6 +37,7 @@ message CreateFriendBillRequest { double amount = 2; string title = 3; string description = 4; + string in_debt = 5; } message CreateFriendBillResponse { @@ -49,9 +50,11 @@ message DeleteFriendBillRequest { message ModifyFriendBillRequest { string friend_bill_id = 1; - double amount = 2; - string title = 3; - string description = 4; + string relation_id = 2; + double amount = 3; + string title = 4; + string description = 5; + string in_debt = 6; } message ListFriendBillRequest { @@ -68,4 +71,5 @@ message FriendBill { double amount = 2; string title = 3; string description = 4; + string in_debt = 5; } \ No newline at end of file diff --git a/protobuf/gen/go/friend_bill.pb.go b/protobuf/gen/go/friend_bill.pb.go index 07f73c1..4db574c 100644 --- a/protobuf/gen/go/friend_bill.pb.go +++ b/protobuf/gen/go/friend_bill.pb.go @@ -31,6 +31,7 @@ type CreateFriendBillRequest struct { 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"` + InDebt string `protobuf:"bytes,5,opt,name=in_debt,json=inDebt,proto3" json:"in_debt,omitempty"` } func (x *CreateFriendBillRequest) Reset() { @@ -93,6 +94,13 @@ func (x *CreateFriendBillRequest) GetDescription() string { return "" } +func (x *CreateFriendBillRequest) GetInDebt() string { + if x != nil { + return x.InDebt + } + return "" +} + type CreateFriendBillResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -193,9 +201,11 @@ type ModifyFriendBillRequest struct { 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"` + RelationId string `protobuf:"bytes,2,opt,name=relation_id,json=relationId,proto3" json:"relation_id,omitempty"` + Amount float64 `protobuf:"fixed64,3,opt,name=amount,proto3" json:"amount,omitempty"` + Title string `protobuf:"bytes,4,opt,name=title,proto3" json:"title,omitempty"` + Description string `protobuf:"bytes,5,opt,name=description,proto3" json:"description,omitempty"` + InDebt string `protobuf:"bytes,6,opt,name=in_debt,json=inDebt,proto3" json:"in_debt,omitempty"` } func (x *ModifyFriendBillRequest) Reset() { @@ -237,6 +247,13 @@ func (x *ModifyFriendBillRequest) GetFriendBillId() string { return "" } +func (x *ModifyFriendBillRequest) GetRelationId() string { + if x != nil { + return x.RelationId + } + return "" +} + func (x *ModifyFriendBillRequest) GetAmount() float64 { if x != nil { return x.Amount @@ -258,6 +275,13 @@ func (x *ModifyFriendBillRequest) GetDescription() string { return "" } +func (x *ModifyFriendBillRequest) GetInDebt() string { + if x != nil { + return x.InDebt + } + return "" +} + type ListFriendBillRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -361,6 +385,7 @@ type FriendBill struct { 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"` + InDebt string `protobuf:"bytes,5,opt,name=in_debt,json=inDebt,proto3" json:"in_debt,omitempty"` } func (x *FriendBill) Reset() { @@ -423,6 +448,13 @@ func (x *FriendBill) GetDescription() string { return "" } +func (x *FriendBill) GetInDebt() string { + if x != nil { + return x.InDebt + } + return "" +} + var File_friend_bill_proto protoreflect.FileDescriptor var file_friend_bill_proto_rawDesc = []byte{ @@ -430,7 +462,7 @@ var file_friend_bill_proto_rawDesc = []byte{ 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, + 0x75, 0x66, 0x2f, 0x65, 0x6d, 0x70, 0x74, 0x79, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa3, 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, @@ -439,69 +471,76 @@ var file_friend_bill_proto_rawDesc = []byte{ 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, + 0x64, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x07, 0x69, + 0x6e, 0x5f, 0x64, 0x65, 0x62, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x6e, + 0x44, 0x65, 0x62, 0x74, 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, 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, + 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, 0xc9, 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, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x6c, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x02, 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, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x06, 0x61, 0x6d, 0x6f, 0x75, + 0x6e, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x69, 0x74, 0x6c, 0x65, 0x18, 0x04, 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, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x64, + 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x17, 0x0a, 0x07, 0x69, 0x6e, + 0x5f, 0x64, 0x65, 0x62, 0x74, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, 0x6e, 0x44, + 0x65, 0x62, 0x74, 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, 0x9b, 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, 0x12, 0x17, 0x0a, 0x07, + 0x69, 0x6e, 0x5f, 0x64, 0x65, 0x62, 0x74, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x69, + 0x6e, 0x44, 0x65, 0x62, 0x74, 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 ( diff --git a/services/api/controllers/friend_bill/create.go b/services/api/controllers/friend_bill/create.go index 0fdbf65..744f09c 100644 --- a/services/api/controllers/friend_bill/create.go +++ b/services/api/controllers/friend_bill/create.go @@ -17,25 +17,24 @@ func (s Service) CreateFriendBill(ctx context.Context, req *monify.CreateFriendB 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") + if req.Amount == 0 { + return nil, status.Error(codes.InvalidArgument, "Amount should not be zero") + } + if req.InDebt == "" { + return nil, status.Error(codes.InvalidArgument, "InDebt person is required") } _, 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) + _, err := db.ExecContext(ctx, ` + INSERT INTO friend_bill (friend_bill_id, relation_id, amount, title, description, in_debt) + VALUES ($1, $2, $3, $4, $5, $6) + `, friend_billId, req.RelationId, req.Amount, req.Title, req.Description, req.InDebt) if err != nil { logger.Error("Insert values into friend_bill error.", zap.Error(err)) return nil, status.Error(codes.Internal, "") diff --git a/services/api/controllers/friend_bill/list_friend_bill.go b/services/api/controllers/friend_bill/list_friend_bill.go index 0a7f031..2424ee2 100644 --- a/services/api/controllers/friend_bill/list_friend_bill.go +++ b/services/api/controllers/friend_bill/list_friend_bill.go @@ -20,7 +20,7 @@ func (s Service) ListFriendBill(ctx context.Context, req *monify.ListFriendBillR } db := ctx.Value(lib.DatabaseContextKey{}).(*sql.DB) query, err := db.QueryContext(ctx, ` - SELECT friend_bill_id, amount, title, description + SELECT friend_bill_id, amount, title, description, in_debt FROM friend_bill WHERE relation_id = $1`, req.RelationId) if err != nil { @@ -35,7 +35,7 @@ func (s Service) ListFriendBill(ctx context.Context, req *monify.ListFriendBillR break } var friend_bill monify.FriendBill - if err = query.Scan(&friend_bill.FriendBillId, &friend_bill.Amount, &friend_bill.Title, &friend_bill.Description); err != nil { + if err = query.Scan(&friend_bill.FriendBillId, &friend_bill.Amount, &friend_bill.Title, &friend_bill.Description, &friend_bill.InDebt); err != nil { logger.Error("Scan friend bill information error.", zap.Error(err)) return nil, status.Error(codes.Internal, "") } diff --git a/services/api/controllers/friend_bill/modify.go b/services/api/controllers/friend_bill/modify.go new file mode 100644 index 0000000..1829db1 --- /dev/null +++ b/services/api/controllers/friend_bill/modify.go @@ -0,0 +1,55 @@ +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) ModifyFriendBill(ctx context.Context, req *monify.ModifyFriendBillRequest) (*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) + + //START transaction + tx, err := db.BeginTx(ctx, &sql.TxOptions{Isolation: sql.LevelReadUncommitted}) + if err != nil { + logger.Error("Failed to begin transaction", zap.Error(err)) + return nil, status.Error(codes.Internal, "Internal") + } + defer tx.Rollback() + + // Delete + _, err = tx.ExecContext(ctx, `DELETE FROM friend_bill WHERE friend_bill_id = $1`, req.FriendBillId) + if err != nil { + logger.Error("Delete friend bill error. (Modify)", zap.Error(err)) + return nil, status.Error(codes.Internal, "") + } + + // Insert + _, err = tx.ExecContext(ctx, ` + INSERT INTO friend_bill (friend_bill_id, relation_id, amount, title, description, in_debt) + VALUES ($1, $2, $3, $4, $5, $6) + `, req.FriendBillId, req.RelationId, req.Amount, req.Title, req.Description, req.InDebt) + if err != nil { + logger.Error("Insert values into friend_bill error. (Modify)", zap.Error(err)) + return nil, status.Error(codes.Internal, "") + } + + //Commit + if err = tx.Commit(); err != nil { + logger.Error("Failed to commit transaction", zap.Error(err)) + return nil, status.Error(codes.Internal, "Internal") + } + return &emptypb.Empty{}, nil +} diff --git a/services/api/test/friend_bill_test.go b/services/api/test/friend_bill_test.go index 8906462..891e7fc 100644 --- a/services/api/test/friend_bill_test.go +++ b/services/api/test/friend_bill_test.go @@ -36,12 +36,14 @@ func TestFriendBill(t *testing.T) { Amount: 300, Title: "test1", Description: "test1", + InDebt: "friend_bill_nickId1", }) _, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{ RelationId: friendS_relationId[0], Amount: 500, Title: "test2", Description: "test2", + InDebt: "friend_bill_nickId1", }) assert.NoError(t, err) _, err = client.CreateFriendBill(context.TODO(), &monify.CreateFriendBillRequest{ @@ -49,21 +51,46 @@ func TestFriendBill(t *testing.T) { Amount: 0, Title: "test2", Description: "test2", + InDebt: "friend_bill_nickId1", }) 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]}) + res1, err := client.ListFriendBill(context.TODO(), &monify.ListFriendBillRequest{RelationId: friendS_relationId[0]}) assert.NoError(t, err) - assert.Equal(t, len(friend_bills.GetFriendBills()), 2) + assert.Equal(t, len(res1.GetFriendBills()), 2) + assert.Equal(t, 300.0, res1.FriendBills[0].Amount) + assert.Equal(t, "test1", res1.FriendBills[0].Title) + assert.Equal(t, "test1", res1.FriendBills[0].Description) + assert.Equal(t, "friend_bill_nickId1", res1.FriendBills[0].InDebt) + assert.Equal(t, 500.0, res1.FriendBills[1].Amount) + assert.Equal(t, "test2", res1.FriendBills[1].Title) + assert.Equal(t, "test2", res1.FriendBills[1].Description) + assert.Equal(t, "friend_bill_nickId1", res1.FriendBills[1].InDebt) // 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]}) + _, err = client.DeleteFriendBill(context.TODO(), &monify.DeleteFriendBillRequest{FriendBillId: res1.FriendBills[0].FriendBillId}) + assert.NoError(t, err) + res2, err := client.ListFriendBill(context.TODO(), &monify.ListFriendBillRequest{RelationId: friendS_relationId[0]}) + assert.Equal(t, len(res2.GetFriendBills()), 1) + assert.Equal(t, 500.0, res2.FriendBills[0].Amount) + assert.Equal(t, "test2", res2.FriendBills[0].Title) + assert.Equal(t, "test2", res2.FriendBills[0].Description) + assert.Equal(t, "friend_bill_nickId1", res2.FriendBills[0].InDebt) + + // Test modify friend bill + _, err = client.ModifyFriendBill(context.TODO(), &monify.ModifyFriendBillRequest{ + FriendBillId: res2.FriendBills[0].FriendBillId, + RelationId: friendS_relationId[0], + Amount: 1000, + Title: "test3", + Description: "test3", + InDebt: "friend_bill_nickId2", + }) 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) + res3, err := client.ListFriendBill(context.TODO(), &monify.ListFriendBillRequest{RelationId: friendS_relationId[0]}) + assert.Equal(t, 1000.0, res3.FriendBills[0].Amount) + assert.Equal(t, "test3", res3.FriendBills[0].Title) + assert.Equal(t, "test3", res3.FriendBills[0].Description) + assert.Equal(t, "friend_bill_nickId2", res3.FriendBills[0].InDebt) }