diff --git a/api/v2/tag_service.go b/api/v2/tag_service.go index ee8b6837..f9922642 100644 --- a/api/v2/tag_service.go +++ b/api/v2/tag_service.go @@ -11,6 +11,10 @@ import ( "google.golang.org/grpc/codes" "google.golang.org/grpc/status" + "github.com/usememos/memos/plugin/gomark/ast" + "github.com/usememos/memos/plugin/gomark/parser" + "github.com/usememos/memos/plugin/gomark/parser/tokenizer" + "github.com/usememos/memos/plugin/gomark/restore" apiv2pb "github.com/usememos/memos/proto/gen/api/v2" "github.com/usememos/memos/store" ) @@ -70,6 +74,71 @@ func (s *APIV2Service) ListTags(ctx context.Context, request *apiv2pb.ListTagsRe return response, nil } +func (s *APIV2Service) RenameTag(ctx context.Context, request *apiv2pb.RenameTagRequest) (*apiv2pb.RenameTagResponse, error) { + username, err := ExtractUsernameFromName(request.User) + if err != nil { + return nil, status.Errorf(codes.InvalidArgument, "invalid username: %v", err) + } + user, err := s.Store.GetUser(ctx, &store.FindUser{ + Username: &username, + }) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to get user: %v", err) + } + if user == nil { + return nil, status.Errorf(codes.NotFound, "user not found") + } + + // Find all related memos. + memos, err := s.Store.ListMemos(ctx, &store.FindMemo{ + CreatorID: &user.ID, + ContentSearch: []string{fmt.Sprintf("#%s", request.OldName)}, + }) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to list memos: %v", err) + } + // Replace tag name in memo content. + for _, memo := range memos { + nodes, err := parser.Parse(tokenizer.Tokenize(memo.Content)) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to parse memo: %v", err) + } + traverseASTNodes(nodes, func(node ast.Node) { + if tag, ok := node.(*ast.Tag); ok { + tag.Content = request.NewName + } + }) + content := restore.Restore(nodes) + if err := s.Store.UpdateMemo(ctx, &store.UpdateMemo{ + ID: memo.ID, + Content: &content, + }); err != nil { + return nil, status.Errorf(codes.Internal, "failed to update memo: %v", err) + } + } + + // Delete old tag and create new tag. + if err := s.Store.DeleteTag(ctx, &store.DeleteTag{ + CreatorID: user.ID, + Name: request.OldName, + }); err != nil { + return nil, status.Errorf(codes.Internal, "failed to delete tag: %v", err) + } + tag, err := s.Store.UpsertTag(ctx, &store.Tag{ + CreatorID: user.ID, + Name: request.NewName, + }) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to upsert tag: %v", err) + } + + tagMessage, err := s.convertTagFromStore(ctx, tag) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to convert tag: %v", err) + } + return &apiv2pb.RenameTagResponse{Tag: tagMessage}, nil +} + func (s *APIV2Service) DeleteTag(ctx context.Context, request *apiv2pb.DeleteTagRequest) (*apiv2pb.DeleteTagResponse, error) { username, err := ExtractUsernameFromName(request.Tag.Creator) if err != nil { diff --git a/proto/api/v2/tag_service.proto b/proto/api/v2/tag_service.proto index 60809475..40a61a75 100644 --- a/proto/api/v2/tag_service.proto +++ b/proto/api/v2/tag_service.proto @@ -13,6 +13,9 @@ service TagService { rpc ListTags(ListTagsRequest) returns (ListTagsResponse) { option (google.api.http) = {get: "/api/v2/tags"}; } + rpc RenameTag(RenameTagRequest) returns (RenameTagResponse) { + option (google.api.http) = {patch: "/api/v2/tags:rename"}; + } rpc DeleteTag(DeleteTagRequest) returns (DeleteTagResponse) { option (google.api.http) = {delete: "/api/v2/tags"}; } @@ -46,6 +49,18 @@ message ListTagsResponse { repeated Tag tags = 1; } +message RenameTagRequest { + // The creator of tags. + // Format: users/{username} + string user = 1; + string old_name = 2; + string new_name = 3; +} + +message RenameTagResponse { + Tag tag = 1; +} + message DeleteTagRequest { Tag tag = 1; } diff --git a/proto/gen/api/v2/README.md b/proto/gen/api/v2/README.md index aab27f7a..808d56ec 100644 --- a/proto/gen/api/v2/README.md +++ b/proto/gen/api/v2/README.md @@ -175,6 +175,8 @@ - [GetTagSuggestionsResponse](#memos-api-v2-GetTagSuggestionsResponse) - [ListTagsRequest](#memos-api-v2-ListTagsRequest) - [ListTagsResponse](#memos-api-v2-ListTagsResponse) + - [RenameTagRequest](#memos-api-v2-RenameTagRequest) + - [RenameTagResponse](#memos-api-v2-RenameTagResponse) - [Tag](#memos-api-v2-Tag) - [UpsertTagRequest](#memos-api-v2-UpsertTagRequest) - [UpsertTagResponse](#memos-api-v2-UpsertTagResponse) @@ -2503,6 +2505,38 @@ + + +### RenameTagRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| user | [string](#string) | | The creator of tags. Format: users/{username} | +| old_name | [string](#string) | | | +| new_name | [string](#string) | | | + + + + + + + + +### RenameTagResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| tag | [Tag](#memos-api-v2-Tag) | | | + + + + + + ### Tag @@ -2564,6 +2598,7 @@ | ----------- | ------------ | ------------- | ------------| | UpsertTag | [UpsertTagRequest](#memos-api-v2-UpsertTagRequest) | [UpsertTagResponse](#memos-api-v2-UpsertTagResponse) | | | ListTags | [ListTagsRequest](#memos-api-v2-ListTagsRequest) | [ListTagsResponse](#memos-api-v2-ListTagsResponse) | | +| RenameTag | [RenameTagRequest](#memos-api-v2-RenameTagRequest) | [RenameTagResponse](#memos-api-v2-RenameTagResponse) | | | DeleteTag | [DeleteTagRequest](#memos-api-v2-DeleteTagRequest) | [DeleteTagResponse](#memos-api-v2-DeleteTagResponse) | | | GetTagSuggestions | [GetTagSuggestionsRequest](#memos-api-v2-GetTagSuggestionsRequest) | [GetTagSuggestionsResponse](#memos-api-v2-GetTagSuggestionsResponse) | | diff --git a/proto/gen/api/v2/tag_service.pb.go b/proto/gen/api/v2/tag_service.pb.go index 9334b9bd..05903e46 100644 --- a/proto/gen/api/v2/tag_service.pb.go +++ b/proto/gen/api/v2/tag_service.pb.go @@ -268,6 +268,118 @@ func (x *ListTagsResponse) GetTags() []*Tag { return nil } +type RenameTagRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // The creator of tags. + // Format: users/{username} + User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` + OldName string `protobuf:"bytes,2,opt,name=old_name,json=oldName,proto3" json:"old_name,omitempty"` + NewName string `protobuf:"bytes,3,opt,name=new_name,json=newName,proto3" json:"new_name,omitempty"` +} + +func (x *RenameTagRequest) Reset() { + *x = RenameTagRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_api_v2_tag_service_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RenameTagRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RenameTagRequest) ProtoMessage() {} + +func (x *RenameTagRequest) ProtoReflect() protoreflect.Message { + mi := &file_api_v2_tag_service_proto_msgTypes[5] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RenameTagRequest.ProtoReflect.Descriptor instead. +func (*RenameTagRequest) Descriptor() ([]byte, []int) { + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{5} +} + +func (x *RenameTagRequest) GetUser() string { + if x != nil { + return x.User + } + return "" +} + +func (x *RenameTagRequest) GetOldName() string { + if x != nil { + return x.OldName + } + return "" +} + +func (x *RenameTagRequest) GetNewName() string { + if x != nil { + return x.NewName + } + return "" +} + +type RenameTagResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Tag *Tag `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"` +} + +func (x *RenameTagResponse) Reset() { + *x = RenameTagResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_api_v2_tag_service_proto_msgTypes[6] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *RenameTagResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*RenameTagResponse) ProtoMessage() {} + +func (x *RenameTagResponse) ProtoReflect() protoreflect.Message { + mi := &file_api_v2_tag_service_proto_msgTypes[6] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use RenameTagResponse.ProtoReflect.Descriptor instead. +func (*RenameTagResponse) Descriptor() ([]byte, []int) { + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{6} +} + +func (x *RenameTagResponse) GetTag() *Tag { + if x != nil { + return x.Tag + } + return nil +} + type DeleteTagRequest struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -279,7 +391,7 @@ type DeleteTagRequest struct { func (x *DeleteTagRequest) Reset() { *x = DeleteTagRequest{} if protoimpl.UnsafeEnabled { - mi := &file_api_v2_tag_service_proto_msgTypes[5] + mi := &file_api_v2_tag_service_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -292,7 +404,7 @@ func (x *DeleteTagRequest) String() string { func (*DeleteTagRequest) ProtoMessage() {} func (x *DeleteTagRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v2_tag_service_proto_msgTypes[5] + mi := &file_api_v2_tag_service_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -305,7 +417,7 @@ func (x *DeleteTagRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteTagRequest.ProtoReflect.Descriptor instead. func (*DeleteTagRequest) Descriptor() ([]byte, []int) { - return file_api_v2_tag_service_proto_rawDescGZIP(), []int{5} + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{7} } func (x *DeleteTagRequest) GetTag() *Tag { @@ -324,7 +436,7 @@ type DeleteTagResponse struct { func (x *DeleteTagResponse) Reset() { *x = DeleteTagResponse{} if protoimpl.UnsafeEnabled { - mi := &file_api_v2_tag_service_proto_msgTypes[6] + mi := &file_api_v2_tag_service_proto_msgTypes[8] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -337,7 +449,7 @@ func (x *DeleteTagResponse) String() string { func (*DeleteTagResponse) ProtoMessage() {} func (x *DeleteTagResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_v2_tag_service_proto_msgTypes[6] + mi := &file_api_v2_tag_service_proto_msgTypes[8] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -350,7 +462,7 @@ func (x *DeleteTagResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use DeleteTagResponse.ProtoReflect.Descriptor instead. func (*DeleteTagResponse) Descriptor() ([]byte, []int) { - return file_api_v2_tag_service_proto_rawDescGZIP(), []int{6} + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{8} } type GetTagSuggestionsRequest struct { @@ -366,7 +478,7 @@ type GetTagSuggestionsRequest struct { func (x *GetTagSuggestionsRequest) Reset() { *x = GetTagSuggestionsRequest{} if protoimpl.UnsafeEnabled { - mi := &file_api_v2_tag_service_proto_msgTypes[7] + mi := &file_api_v2_tag_service_proto_msgTypes[9] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -379,7 +491,7 @@ func (x *GetTagSuggestionsRequest) String() string { func (*GetTagSuggestionsRequest) ProtoMessage() {} func (x *GetTagSuggestionsRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_v2_tag_service_proto_msgTypes[7] + mi := &file_api_v2_tag_service_proto_msgTypes[9] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -392,7 +504,7 @@ func (x *GetTagSuggestionsRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use GetTagSuggestionsRequest.ProtoReflect.Descriptor instead. func (*GetTagSuggestionsRequest) Descriptor() ([]byte, []int) { - return file_api_v2_tag_service_proto_rawDescGZIP(), []int{7} + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{9} } func (x *GetTagSuggestionsRequest) GetUser() string { @@ -413,7 +525,7 @@ type GetTagSuggestionsResponse struct { func (x *GetTagSuggestionsResponse) Reset() { *x = GetTagSuggestionsResponse{} if protoimpl.UnsafeEnabled { - mi := &file_api_v2_tag_service_proto_msgTypes[8] + mi := &file_api_v2_tag_service_proto_msgTypes[10] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -426,7 +538,7 @@ func (x *GetTagSuggestionsResponse) String() string { func (*GetTagSuggestionsResponse) ProtoMessage() {} func (x *GetTagSuggestionsResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_v2_tag_service_proto_msgTypes[8] + mi := &file_api_v2_tag_service_proto_msgTypes[10] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -439,7 +551,7 @@ func (x *GetTagSuggestionsResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use GetTagSuggestionsResponse.ProtoReflect.Descriptor instead. func (*GetTagSuggestionsResponse) Descriptor() ([]byte, []int) { - return file_api_v2_tag_service_proto_rawDescGZIP(), []int{8} + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{10} } func (x *GetTagSuggestionsResponse) GetTags() []string { @@ -472,56 +584,73 @@ var file_api_v2_tag_service_proto_rawDesc = []byte{ 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x54, 0x61, 0x67, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x22, - 0x37, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x23, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, - 0x32, 0x11, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, - 0x54, 0x61, 0x67, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0x13, 0x0a, 0x11, 0x44, 0x65, 0x6c, 0x65, - 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x0a, - 0x18, 0x47, 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, - 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x2f, 0x0a, - 0x19, 0x47, 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, - 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, - 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x32, 0xbd, - 0x03, 0x0a, 0x0a, 0x54, 0x61, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, - 0x09, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x54, 0x61, 0x67, 0x12, 0x1e, 0x2e, 0x6d, 0x65, 0x6d, - 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, - 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x65, 0x6d, - 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, - 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, 0xe4, - 0x93, 0x02, 0x0e, 0x22, 0x0c, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, 0x67, - 0x73, 0x12, 0x5f, 0x0a, 0x08, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 0x12, 0x1d, 0x2e, - 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x4c, 0x69, 0x73, - 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x6d, - 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, - 0xe4, 0x93, 0x02, 0x0e, 0x12, 0x0c, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, - 0x67, 0x73, 0x12, 0x62, 0x0a, 0x09, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x12, - 0x1e, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x1f, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x2a, 0x0c, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, - 0x32, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x12, 0x85, 0x01, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x54, 0x61, - 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x26, 0x2e, 0x6d, - 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x54, - 0x61, 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1f, 0x82, - 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x12, 0x17, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, - 0x61, 0x67, 0x73, 0x2f, 0x73, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x42, 0xa7, - 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, - 0x2e, 0x76, 0x32, 0x42, 0x0f, 0x54, 0x61, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x50, - 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, - 0x6f, 0x6d, 0x2f, 0x75, 0x73, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, 0x65, 0x6d, 0x6f, - 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, 0x70, 0x69, 0x2f, - 0x76, 0x32, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x32, 0xa2, 0x02, 0x03, 0x4d, 0x41, 0x58, 0xaa, 0x02, - 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x70, 0x69, 0x2e, 0x56, 0x32, 0xca, 0x02, 0x0c, - 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32, 0xe2, 0x02, 0x18, 0x4d, - 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32, 0x5c, 0x47, 0x50, 0x42, 0x4d, - 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0e, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x3a, - 0x3a, 0x41, 0x70, 0x69, 0x3a, 0x3a, 0x56, 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x5c, 0x0a, 0x10, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x04, 0x75, 0x73, 0x65, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x6f, 0x6c, 0x64, 0x5f, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6f, 0x6c, 0x64, 0x4e, 0x61, + 0x6d, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x6e, 0x65, 0x77, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6e, 0x65, 0x77, 0x4e, 0x61, 0x6d, 0x65, 0x22, 0x38, 0x0a, + 0x11, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x23, 0x0a, 0x03, 0x74, 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x11, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x54, + 0x61, 0x67, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0x37, 0x0a, 0x10, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x23, 0x0a, 0x03, 0x74, + 0x61, 0x67, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, + 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x54, 0x61, 0x67, 0x52, 0x03, 0x74, 0x61, 0x67, + 0x22, 0x13, 0x0a, 0x11, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x2e, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, + 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x75, 0x73, 0x65, 0x72, 0x22, 0x2f, 0x0a, 0x19, 0x47, 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, + 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x61, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x04, 0x74, 0x61, 0x67, 0x73, 0x32, 0xa8, 0x04, 0x0a, 0x0a, 0x54, 0x61, 0x67, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x09, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x54, + 0x61, 0x67, 0x12, 0x1e, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x32, 0x2e, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x32, 0x2e, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x22, 0x0c, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x12, 0x5f, 0x0a, 0x08, 0x4c, 0x69, 0x73, + 0x74, 0x54, 0x61, 0x67, 0x73, 0x12, 0x1d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, + 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, + 0x2e, 0x76, 0x32, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x12, 0x0c, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x12, 0x69, 0x0a, 0x09, 0x52, 0x65, + 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x67, 0x12, 0x1e, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x67, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x52, 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x54, 0x61, 0x67, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x1b, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x15, + 0x32, 0x13, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x3a, 0x72, + 0x65, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x62, 0x0a, 0x09, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, + 0x61, 0x67, 0x12, 0x1e, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x32, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, + 0x32, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x54, 0x61, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x22, 0x14, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x0e, 0x2a, 0x0c, 0x2f, 0x61, 0x70, + 0x69, 0x2f, 0x76, 0x32, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x12, 0x85, 0x01, 0x0a, 0x11, 0x47, 0x65, + 0x74, 0x54, 0x61, 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, + 0x26, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x47, + 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x47, 0x65, 0x74, 0x54, 0x61, 0x67, 0x53, 0x75, 0x67, + 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x22, 0x1f, 0x82, 0xd3, 0xe4, 0x93, 0x02, 0x19, 0x12, 0x17, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x76, + 0x32, 0x2f, 0x74, 0x61, 0x67, 0x73, 0x2f, 0x73, 0x75, 0x67, 0x67, 0x65, 0x73, 0x74, 0x69, 0x6f, + 0x6e, 0x42, 0xa7, 0x01, 0x0a, 0x10, 0x63, 0x6f, 0x6d, 0x2e, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, + 0x61, 0x70, 0x69, 0x2e, 0x76, 0x32, 0x42, 0x0f, 0x54, 0x61, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, + 0x63, 0x65, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x30, 0x67, 0x69, 0x74, 0x68, 0x75, + 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x73, 0x65, 0x6d, 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x6d, + 0x65, 0x6d, 0x6f, 0x73, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x61, + 0x70, 0x69, 0x2f, 0x76, 0x32, 0x3b, 0x61, 0x70, 0x69, 0x76, 0x32, 0xa2, 0x02, 0x03, 0x4d, 0x41, + 0x58, 0xaa, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x2e, 0x41, 0x70, 0x69, 0x2e, 0x56, 0x32, + 0xca, 0x02, 0x0c, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32, 0xe2, + 0x02, 0x18, 0x4d, 0x65, 0x6d, 0x6f, 0x73, 0x5c, 0x41, 0x70, 0x69, 0x5c, 0x56, 0x32, 0x5c, 0x47, + 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x0e, 0x4d, 0x65, 0x6d, + 0x6f, 0x73, 0x3a, 0x3a, 0x41, 0x70, 0x69, 0x3a, 0x3a, 0x56, 0x32, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -536,35 +665,40 @@ func file_api_v2_tag_service_proto_rawDescGZIP() []byte { return file_api_v2_tag_service_proto_rawDescData } -var file_api_v2_tag_service_proto_msgTypes = make([]protoimpl.MessageInfo, 9) +var file_api_v2_tag_service_proto_msgTypes = make([]protoimpl.MessageInfo, 11) var file_api_v2_tag_service_proto_goTypes = []interface{}{ (*Tag)(nil), // 0: memos.api.v2.Tag (*UpsertTagRequest)(nil), // 1: memos.api.v2.UpsertTagRequest (*UpsertTagResponse)(nil), // 2: memos.api.v2.UpsertTagResponse (*ListTagsRequest)(nil), // 3: memos.api.v2.ListTagsRequest (*ListTagsResponse)(nil), // 4: memos.api.v2.ListTagsResponse - (*DeleteTagRequest)(nil), // 5: memos.api.v2.DeleteTagRequest - (*DeleteTagResponse)(nil), // 6: memos.api.v2.DeleteTagResponse - (*GetTagSuggestionsRequest)(nil), // 7: memos.api.v2.GetTagSuggestionsRequest - (*GetTagSuggestionsResponse)(nil), // 8: memos.api.v2.GetTagSuggestionsResponse + (*RenameTagRequest)(nil), // 5: memos.api.v2.RenameTagRequest + (*RenameTagResponse)(nil), // 6: memos.api.v2.RenameTagResponse + (*DeleteTagRequest)(nil), // 7: memos.api.v2.DeleteTagRequest + (*DeleteTagResponse)(nil), // 8: memos.api.v2.DeleteTagResponse + (*GetTagSuggestionsRequest)(nil), // 9: memos.api.v2.GetTagSuggestionsRequest + (*GetTagSuggestionsResponse)(nil), // 10: memos.api.v2.GetTagSuggestionsResponse } var file_api_v2_tag_service_proto_depIdxs = []int32{ - 0, // 0: memos.api.v2.UpsertTagResponse.tag:type_name -> memos.api.v2.Tag - 0, // 1: memos.api.v2.ListTagsResponse.tags:type_name -> memos.api.v2.Tag - 0, // 2: memos.api.v2.DeleteTagRequest.tag:type_name -> memos.api.v2.Tag - 1, // 3: memos.api.v2.TagService.UpsertTag:input_type -> memos.api.v2.UpsertTagRequest - 3, // 4: memos.api.v2.TagService.ListTags:input_type -> memos.api.v2.ListTagsRequest - 5, // 5: memos.api.v2.TagService.DeleteTag:input_type -> memos.api.v2.DeleteTagRequest - 7, // 6: memos.api.v2.TagService.GetTagSuggestions:input_type -> memos.api.v2.GetTagSuggestionsRequest - 2, // 7: memos.api.v2.TagService.UpsertTag:output_type -> memos.api.v2.UpsertTagResponse - 4, // 8: memos.api.v2.TagService.ListTags:output_type -> memos.api.v2.ListTagsResponse - 6, // 9: memos.api.v2.TagService.DeleteTag:output_type -> memos.api.v2.DeleteTagResponse - 8, // 10: memos.api.v2.TagService.GetTagSuggestions:output_type -> memos.api.v2.GetTagSuggestionsResponse - 7, // [7:11] is the sub-list for method output_type - 3, // [3:7] is the sub-list for method input_type - 3, // [3:3] is the sub-list for extension type_name - 3, // [3:3] is the sub-list for extension extendee - 0, // [0:3] is the sub-list for field type_name + 0, // 0: memos.api.v2.UpsertTagResponse.tag:type_name -> memos.api.v2.Tag + 0, // 1: memos.api.v2.ListTagsResponse.tags:type_name -> memos.api.v2.Tag + 0, // 2: memos.api.v2.RenameTagResponse.tag:type_name -> memos.api.v2.Tag + 0, // 3: memos.api.v2.DeleteTagRequest.tag:type_name -> memos.api.v2.Tag + 1, // 4: memos.api.v2.TagService.UpsertTag:input_type -> memos.api.v2.UpsertTagRequest + 3, // 5: memos.api.v2.TagService.ListTags:input_type -> memos.api.v2.ListTagsRequest + 5, // 6: memos.api.v2.TagService.RenameTag:input_type -> memos.api.v2.RenameTagRequest + 7, // 7: memos.api.v2.TagService.DeleteTag:input_type -> memos.api.v2.DeleteTagRequest + 9, // 8: memos.api.v2.TagService.GetTagSuggestions:input_type -> memos.api.v2.GetTagSuggestionsRequest + 2, // 9: memos.api.v2.TagService.UpsertTag:output_type -> memos.api.v2.UpsertTagResponse + 4, // 10: memos.api.v2.TagService.ListTags:output_type -> memos.api.v2.ListTagsResponse + 6, // 11: memos.api.v2.TagService.RenameTag:output_type -> memos.api.v2.RenameTagResponse + 8, // 12: memos.api.v2.TagService.DeleteTag:output_type -> memos.api.v2.DeleteTagResponse + 10, // 13: memos.api.v2.TagService.GetTagSuggestions:output_type -> memos.api.v2.GetTagSuggestionsResponse + 9, // [9:14] is the sub-list for method output_type + 4, // [4:9] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_api_v2_tag_service_proto_init() } @@ -634,7 +768,7 @@ func file_api_v2_tag_service_proto_init() { } } file_api_v2_tag_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteTagRequest); i { + switch v := v.(*RenameTagRequest); i { case 0: return &v.state case 1: @@ -646,7 +780,7 @@ func file_api_v2_tag_service_proto_init() { } } file_api_v2_tag_service_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*DeleteTagResponse); i { + switch v := v.(*RenameTagResponse); i { case 0: return &v.state case 1: @@ -658,7 +792,7 @@ func file_api_v2_tag_service_proto_init() { } } file_api_v2_tag_service_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*GetTagSuggestionsRequest); i { + switch v := v.(*DeleteTagRequest); i { case 0: return &v.state case 1: @@ -670,6 +804,30 @@ func file_api_v2_tag_service_proto_init() { } } file_api_v2_tag_service_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*DeleteTagResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_v2_tag_service_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetTagSuggestionsRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_api_v2_tag_service_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*GetTagSuggestionsResponse); i { case 0: return &v.state @@ -688,7 +846,7 @@ func file_api_v2_tag_service_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_api_v2_tag_service_proto_rawDesc, NumEnums: 0, - NumMessages: 9, + NumMessages: 11, NumExtensions: 0, NumServices: 1, }, diff --git a/proto/gen/api/v2/tag_service.pb.gw.go b/proto/gen/api/v2/tag_service.pb.gw.go index 3ac580b4..b8b1ad8f 100644 --- a/proto/gen/api/v2/tag_service.pb.gw.go +++ b/proto/gen/api/v2/tag_service.pb.gw.go @@ -103,6 +103,42 @@ func local_request_TagService_ListTags_0(ctx context.Context, marshaler runtime. } +var ( + filter_TagService_RenameTag_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_TagService_RenameTag_0(ctx context.Context, marshaler runtime.Marshaler, client TagServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RenameTagRequest + 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_TagService_RenameTag_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.RenameTag(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_TagService_RenameTag_0(ctx context.Context, marshaler runtime.Marshaler, server TagServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq RenameTagRequest + 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_TagService_RenameTag_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.RenameTag(ctx, &protoReq) + return msg, metadata, err + +} + var ( filter_TagService_DeleteTag_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} ) @@ -231,6 +267,31 @@ func RegisterTagServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, }) + mux.Handle("PATCH", pattern_TagService_RenameTag_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, "/memos.api.v2.TagService/RenameTag", runtime.WithHTTPPathPattern("/api/v2/tags:rename")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_TagService_RenameTag_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_TagService_RenameTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("DELETE", pattern_TagService_DeleteTag_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -366,6 +427,28 @@ func RegisterTagServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) + mux.Handle("PATCH", pattern_TagService_RenameTag_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, "/memos.api.v2.TagService/RenameTag", runtime.WithHTTPPathPattern("/api/v2/tags:rename")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_TagService_RenameTag_0(annotatedContext, inboundMarshaler, client, req, pathParams) + annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md) + if err != nil { + runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err) + return + } + + forward_TagService_RenameTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + mux.Handle("DELETE", pattern_TagService_DeleteTag_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { ctx, cancel := context.WithCancel(req.Context()) defer cancel() @@ -418,6 +501,8 @@ var ( pattern_TagService_ListTags_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "tags"}, "")) + pattern_TagService_RenameTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "tags"}, "rename")) + pattern_TagService_DeleteTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "tags"}, "")) pattern_TagService_GetTagSuggestions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 2, 3}, []string{"api", "v2", "tags", "suggestion"}, "")) @@ -428,6 +513,8 @@ var ( forward_TagService_ListTags_0 = runtime.ForwardResponseMessage + forward_TagService_RenameTag_0 = runtime.ForwardResponseMessage + forward_TagService_DeleteTag_0 = runtime.ForwardResponseMessage forward_TagService_GetTagSuggestions_0 = runtime.ForwardResponseMessage diff --git a/proto/gen/api/v2/tag_service_grpc.pb.go b/proto/gen/api/v2/tag_service_grpc.pb.go index 00666e0d..96a3edcf 100644 --- a/proto/gen/api/v2/tag_service_grpc.pb.go +++ b/proto/gen/api/v2/tag_service_grpc.pb.go @@ -21,6 +21,7 @@ const _ = grpc.SupportPackageIsVersion7 const ( TagService_UpsertTag_FullMethodName = "/memos.api.v2.TagService/UpsertTag" TagService_ListTags_FullMethodName = "/memos.api.v2.TagService/ListTags" + TagService_RenameTag_FullMethodName = "/memos.api.v2.TagService/RenameTag" TagService_DeleteTag_FullMethodName = "/memos.api.v2.TagService/DeleteTag" TagService_GetTagSuggestions_FullMethodName = "/memos.api.v2.TagService/GetTagSuggestions" ) @@ -31,6 +32,7 @@ const ( type TagServiceClient interface { UpsertTag(ctx context.Context, in *UpsertTagRequest, opts ...grpc.CallOption) (*UpsertTagResponse, error) ListTags(ctx context.Context, in *ListTagsRequest, opts ...grpc.CallOption) (*ListTagsResponse, error) + RenameTag(ctx context.Context, in *RenameTagRequest, opts ...grpc.CallOption) (*RenameTagResponse, error) DeleteTag(ctx context.Context, in *DeleteTagRequest, opts ...grpc.CallOption) (*DeleteTagResponse, error) GetTagSuggestions(ctx context.Context, in *GetTagSuggestionsRequest, opts ...grpc.CallOption) (*GetTagSuggestionsResponse, error) } @@ -61,6 +63,15 @@ func (c *tagServiceClient) ListTags(ctx context.Context, in *ListTagsRequest, op return out, nil } +func (c *tagServiceClient) RenameTag(ctx context.Context, in *RenameTagRequest, opts ...grpc.CallOption) (*RenameTagResponse, error) { + out := new(RenameTagResponse) + err := c.cc.Invoke(ctx, TagService_RenameTag_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *tagServiceClient) DeleteTag(ctx context.Context, in *DeleteTagRequest, opts ...grpc.CallOption) (*DeleteTagResponse, error) { out := new(DeleteTagResponse) err := c.cc.Invoke(ctx, TagService_DeleteTag_FullMethodName, in, out, opts...) @@ -85,6 +96,7 @@ func (c *tagServiceClient) GetTagSuggestions(ctx context.Context, in *GetTagSugg type TagServiceServer interface { UpsertTag(context.Context, *UpsertTagRequest) (*UpsertTagResponse, error) ListTags(context.Context, *ListTagsRequest) (*ListTagsResponse, error) + RenameTag(context.Context, *RenameTagRequest) (*RenameTagResponse, error) DeleteTag(context.Context, *DeleteTagRequest) (*DeleteTagResponse, error) GetTagSuggestions(context.Context, *GetTagSuggestionsRequest) (*GetTagSuggestionsResponse, error) mustEmbedUnimplementedTagServiceServer() @@ -100,6 +112,9 @@ func (UnimplementedTagServiceServer) UpsertTag(context.Context, *UpsertTagReques func (UnimplementedTagServiceServer) ListTags(context.Context, *ListTagsRequest) (*ListTagsResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method ListTags not implemented") } +func (UnimplementedTagServiceServer) RenameTag(context.Context, *RenameTagRequest) (*RenameTagResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method RenameTag not implemented") +} func (UnimplementedTagServiceServer) DeleteTag(context.Context, *DeleteTagRequest) (*DeleteTagResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteTag not implemented") } @@ -155,6 +170,24 @@ func _TagService_ListTags_Handler(srv interface{}, ctx context.Context, dec func return interceptor(ctx, in, info, handler) } +func _TagService_RenameTag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(RenameTagRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TagServiceServer).RenameTag(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: TagService_RenameTag_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TagServiceServer).RenameTag(ctx, req.(*RenameTagRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _TagService_DeleteTag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(DeleteTagRequest) if err := dec(in); err != nil { @@ -206,6 +239,10 @@ var TagService_ServiceDesc = grpc.ServiceDesc{ MethodName: "ListTags", Handler: _TagService_ListTags_Handler, }, + { + MethodName: "RenameTag", + Handler: _TagService_RenameTag_Handler, + }, { MethodName: "DeleteTag", Handler: _TagService_DeleteTag_Handler, diff --git a/web/src/components/RenameTagDialog.tsx b/web/src/components/RenameTagDialog.tsx new file mode 100644 index 00000000..c8a95602 --- /dev/null +++ b/web/src/components/RenameTagDialog.tsx @@ -0,0 +1,107 @@ +import { Button, IconButton, Input, List, ListItem } from "@mui/joy"; +import React, { useState } from "react"; +import { toast } from "react-hot-toast"; +import { tagServiceClient } from "@/grpcweb"; +import useCurrentUser from "@/hooks/useCurrentUser"; +import useLoading from "@/hooks/useLoading"; +import { useTranslate } from "@/utils/i18n"; +import { generateDialog } from "./Dialog"; +import Icon from "./Icon"; + +interface Props extends DialogProps { + tag: string; +} + +const RenameTagDialog: React.FC = (props: Props) => { + const { tag, destroy } = props; + const t = useTranslate(); + const currentUser = useCurrentUser(); + const [newName, setNewName] = useState(tag); + const requestState = useLoading(false); + + const handleTagNameInputChange = (e: React.ChangeEvent) => { + setNewName(e.target.value.trim()); + }; + + const handleConfirm = async () => { + if (!newName) { + toast.error("Please fill all required fields"); + return; + } + if (newName === tag) { + toast.error("New name cannot be the same as the old name"); + return; + } + + try { + await tagServiceClient.renameTag({ + user: currentUser.name, + oldName: tag, + newName: newName, + }); + toast.success("Rename tag successfully"); + setTimeout(() => { + window.location.reload(); + }, 300); + } catch (error: any) { + console.error(error); + toast.error(error.details); + } + }; + + return ( + <> + + {"Rename tag"} + destroy()}> + + + + + + + Old Name + + + + New Name + + + + All memes with this tag will be updated. + If the amount of data is large, it will take longer and the server load will become higher. + The page will be automatically refreshed when the task is completed + + + + + {t("common.cancel")} + + + {t("common.confirm")} + + + + > + ); +}; + +function showRenameTagDialog(props: Pick) { + generateDialog( + { + className: "rename-tag-dialog", + dialogName: "rename-tag-dialog", + }, + RenameTagDialog, + props + ); +} + +export default showRenameTagDialog; diff --git a/web/src/components/TagList.tsx b/web/src/components/TagList.tsx index 95f48258..1fdeaf51 100644 --- a/web/src/components/TagList.tsx +++ b/web/src/components/TagList.tsx @@ -1,3 +1,4 @@ +import { Dropdown, Menu, MenuButton, MenuItem } from "@mui/joy"; import { useEffect, useState } from "react"; import useToggle from "react-use/lib/useToggle"; import { useFilterStore, useTagStore } from "@/store/module"; @@ -5,6 +6,7 @@ import { useMemoList } from "@/store/v1"; import { useTranslate } from "@/utils/i18n"; import showCreateTagDialog from "./CreateTagDialog"; import Icon from "./Icon"; +import showRenameTagDialog from "./RenameTagDialog"; interface Tag { key: string; @@ -116,17 +118,25 @@ const TagItemContainer: React.FC = (props: TagItemContain return ( <> - + - - {tag.key} + + + + + + + + showRenameTagDialog({ tag: tag.text })}>Rename + + + + {tag.key} + {hasSubTags ? (
{"Rename tag"}