From d0fd93c0122f0510583eafc8a5735b18371ac7b6 Mon Sep 17 00:00:00 2001 From: Danielllllllllllllll Date: Mon, 5 Aug 2024 03:31:35 +0800 Subject: [PATCH] feature: modify friend bill --- protobuf/friend_bill.proto | 7 +- protobuf/gen/go/friend_bill.pb.go | 116 ++++++++++-------- .../api/controllers/friend_bill/create.go | 12 +- .../api/controllers/friend_bill/modify.go | 55 +++++++++ services/api/test/friend_bill_test.go | 37 ++++-- 5 files changed, 154 insertions(+), 73 deletions(-) create mode 100644 services/api/controllers/friend_bill/modify.go diff --git a/protobuf/friend_bill.proto b/protobuf/friend_bill.proto index 12039ca..3d6c71a 100644 --- a/protobuf/friend_bill.proto +++ b/protobuf/friend_bill.proto @@ -49,9 +49,10 @@ 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; } message ListFriendBillRequest { diff --git a/protobuf/gen/go/friend_bill.pb.go b/protobuf/gen/go/friend_bill.pb.go index 07f73c1..d7816f5 100644 --- a/protobuf/gen/go/friend_bill.pb.go +++ b/protobuf/gen/go/friend_bill.pb.go @@ -193,9 +193,10 @@ 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"` } func (x *ModifyFriendBillRequest) Reset() { @@ -237,6 +238,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 @@ -447,61 +455,63 @@ var file_friend_bill_proto_rawDesc = []byte{ 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, + 0x52, 0x0c, 0x66, 0x72, 0x69, 0x65, 0x6e, 0x64, 0x42, 0x69, 0x6c, 0x6c, 0x49, 0x64, 0x22, 0xb0, 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, + 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, 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, 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, + 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..74042c7 100644 --- a/services/api/controllers/friend_bill/create.go +++ b/services/api/controllers/friend_bill/create.go @@ -17,25 +17,21 @@ 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") } _, 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, ` + _, 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) + `, friend_billId, req.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, "") diff --git a/services/api/controllers/friend_bill/modify.go b/services/api/controllers/friend_bill/modify.go new file mode 100644 index 0000000..57c3ffe --- /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) + VALUES ($1, $2, $3, $4, $5) + `, req.FriendBillId, req.RelationId, req.Amount, req.Title, req.Description) + 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..12ada65 100644 --- a/services/api/test/friend_bill_test.go +++ b/services/api/test/friend_bill_test.go @@ -53,17 +53,36 @@ func TestFriendBill(t *testing.T) { 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, 500.0, res1.FriendBills[1].Amount) + assert.Equal(t, "test2", res1.FriendBills[1].Title) + assert.Equal(t, "test2", res1.FriendBills[1].Description) // 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) + + // 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", + }) 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) }