From bcd8a5a7a9cc8a2a17d15a84bd0ec0cb6f7a2944 Mon Sep 17 00:00:00 2001 From: Steven Date: Wed, 22 Nov 2023 22:33:02 +0800 Subject: [PATCH] chore: migrate get tag suggestions --- api/v2/tag_service.go | 78 +++++++- proto/api/v2/tag_service.proto | 15 +- proto/gen/api/v2/README.md | 35 +++- proto/gen/api/v2/tag_service.pb.go | 256 ++++++++++++++++++------ proto/gen/api/v2/tag_service.pb.gw.go | 87 ++++++++ proto/gen/api/v2/tag_service_grpc.pb.go | 43 +++- web/src/components/CreateTagDialog.tsx | 16 +- web/src/helpers/api.ts | 4 - web/src/store/module/tag.ts | 2 +- 9 files changed, 461 insertions(+), 75 deletions(-) diff --git a/api/v2/tag_service.go b/api/v2/tag_service.go index 77ca429e..ee8b6837 100644 --- a/api/v2/tag_service.go +++ b/api/v2/tag_service.go @@ -3,8 +3,11 @@ package v2 import ( "context" "fmt" + "regexp" + "sort" "github.com/pkg/errors" + "golang.org/x/exp/slices" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" @@ -36,7 +39,7 @@ func (s *APIV2Service) UpsertTag(ctx context.Context, request *apiv2pb.UpsertTag } func (s *APIV2Service) ListTags(ctx context.Context, request *apiv2pb.ListTagsRequest) (*apiv2pb.ListTagsResponse, error) { - username, err := ExtractUsernameFromName(request.Creator) + username, err := ExtractUsernameFromName(request.User) if err != nil { return nil, status.Errorf(codes.InvalidArgument, "invalid username: %v", err) } @@ -91,6 +94,61 @@ func (s *APIV2Service) DeleteTag(ctx context.Context, request *apiv2pb.DeleteTag return &apiv2pb.DeleteTagResponse{}, nil } +func (s *APIV2Service) GetTagSuggestions(ctx context.Context, request *apiv2pb.GetTagSuggestionsRequest) (*apiv2pb.GetTagSuggestionsResponse, 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") + } + normalRowStatus := store.Normal + memoFind := &store.FindMemo{ + CreatorID: &user.ID, + ContentSearch: []string{"#"}, + RowStatus: &normalRowStatus, + } + memoList, err := s.Store.ListMemos(ctx, memoFind) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to list memos: %v", err) + } + + tagList, err := s.Store.ListTags(ctx, &store.FindTag{ + CreatorID: user.ID, + }) + if err != nil { + return nil, status.Errorf(codes.Internal, "failed to list tags: %v", err) + } + + tagNameList := []string{} + for _, tag := range tagList { + tagNameList = append(tagNameList, tag.Name) + } + tagMapSet := make(map[string]bool) + for _, memo := range memoList { + for _, tag := range findTagListFromMemoContent(memo.Content) { + if !slices.Contains(tagNameList, tag) { + tagMapSet[tag] = true + } + } + } + suggestions := []string{} + for tag := range tagMapSet { + suggestions = append(suggestions, tag) + } + sort.Strings(suggestions) + + return &apiv2pb.GetTagSuggestionsResponse{ + Tags: suggestions, + }, nil +} + func (s *APIV2Service) convertTagFromStore(ctx context.Context, tag *store.Tag) (*apiv2pb.Tag, error) { user, err := s.Store.GetUser(ctx, &store.FindUser{ ID: &tag.CreatorID, @@ -103,3 +161,21 @@ func (s *APIV2Service) convertTagFromStore(ctx context.Context, tag *store.Tag) Creator: fmt.Sprintf("%s%s", UserNamePrefix, user.Username), }, nil } + +var tagRegexp = regexp.MustCompile(`#([^\s#,]+)`) + +func findTagListFromMemoContent(memoContent string) []string { + tagMapSet := make(map[string]bool) + matches := tagRegexp.FindAllStringSubmatch(memoContent, -1) + for _, v := range matches { + tagName := v[1] + tagMapSet[tagName] = true + } + + tagList := []string{} + for tag := range tagMapSet { + tagList = append(tagList, tag) + } + sort.Strings(tagList) + return tagList +} diff --git a/proto/api/v2/tag_service.proto b/proto/api/v2/tag_service.proto index cc762f67..60809475 100644 --- a/proto/api/v2/tag_service.proto +++ b/proto/api/v2/tag_service.proto @@ -16,6 +16,9 @@ service TagService { rpc DeleteTag(DeleteTagRequest) returns (DeleteTagResponse) { option (google.api.http) = {delete: "/api/v2/tags"}; } + rpc GetTagSuggestions(GetTagSuggestionsRequest) returns (GetTagSuggestionsResponse) { + option (google.api.http) = {get: "/api/v2/tags/suggestion"}; + } } message Tag { @@ -36,7 +39,7 @@ message UpsertTagResponse { message ListTagsRequest { // The creator of tags. // Format: users/{username} - string creator = 1; + string user = 1; } message ListTagsResponse { @@ -48,3 +51,13 @@ message DeleteTagRequest { } message DeleteTagResponse {} + +message GetTagSuggestionsRequest { + // The creator of tags. + // Format: users/{username} + string user = 1; +} + +message GetTagSuggestionsResponse { + repeated string tags = 1; +} diff --git a/proto/gen/api/v2/README.md b/proto/gen/api/v2/README.md index f67046e0..7e565164 100644 --- a/proto/gen/api/v2/README.md +++ b/proto/gen/api/v2/README.md @@ -72,6 +72,8 @@ - [api/v2/tag_service.proto](#api_v2_tag_service-proto) - [DeleteTagRequest](#memos-api-v2-DeleteTagRequest) - [DeleteTagResponse](#memos-api-v2-DeleteTagResponse) + - [GetTagSuggestionsRequest](#memos-api-v2-GetTagSuggestionsRequest) + - [GetTagSuggestionsResponse](#memos-api-v2-GetTagSuggestionsResponse) - [ListTagsRequest](#memos-api-v2-ListTagsRequest) - [ListTagsResponse](#memos-api-v2-ListTagsResponse) - [Tag](#memos-api-v2-Tag) @@ -938,6 +940,36 @@ + + +### GetTagSuggestionsRequest + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| user | [string](#string) | | The creator of tags. Format: users/{username} | + + + + + + + + +### GetTagSuggestionsResponse + + + +| Field | Type | Label | Description | +| ----- | ---- | ----- | ----------- | +| tags | [string](#string) | repeated | | + + + + + + ### ListTagsRequest @@ -946,7 +978,7 @@ | Field | Type | Label | Description | | ----- | ---- | ----- | ----------- | -| creator | [string](#string) | | The creator of tags. Format: users/{username} | +| user | [string](#string) | | The creator of tags. Format: users/{username} | @@ -1030,6 +1062,7 @@ | UpsertTag | [UpsertTagRequest](#memos-api-v2-UpsertTagRequest) | [UpsertTagResponse](#memos-api-v2-UpsertTagResponse) | | | ListTags | [ListTagsRequest](#memos-api-v2-ListTagsRequest) | [ListTagsResponse](#memos-api-v2-ListTagsResponse) | | | 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 b6998b55..9334b9bd 100644 --- a/proto/gen/api/v2/tag_service.pb.go +++ b/proto/gen/api/v2/tag_service.pb.go @@ -179,7 +179,7 @@ type ListTagsRequest struct { // The creator of tags. // Format: users/{username} - Creator string `protobuf:"bytes,1,opt,name=creator,proto3" json:"creator,omitempty"` + User string `protobuf:"bytes,1,opt,name=user,proto3" json:"user,omitempty"` } func (x *ListTagsRequest) Reset() { @@ -214,9 +214,9 @@ func (*ListTagsRequest) Descriptor() ([]byte, []int) { return file_api_v2_tag_service_proto_rawDescGZIP(), []int{3} } -func (x *ListTagsRequest) GetCreator() string { +func (x *ListTagsRequest) GetUser() string { if x != nil { - return x.Creator + return x.User } return "" } @@ -353,6 +353,102 @@ func (*DeleteTagResponse) Descriptor() ([]byte, []int) { return file_api_v2_tag_service_proto_rawDescGZIP(), []int{6} } +type GetTagSuggestionsRequest 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"` +} + +func (x *GetTagSuggestionsRequest) Reset() { + *x = GetTagSuggestionsRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_api_v2_tag_service_proto_msgTypes[7] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetTagSuggestionsRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetTagSuggestionsRequest) ProtoMessage() {} + +func (x *GetTagSuggestionsRequest) ProtoReflect() protoreflect.Message { + 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 { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetTagSuggestionsRequest.ProtoReflect.Descriptor instead. +func (*GetTagSuggestionsRequest) Descriptor() ([]byte, []int) { + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{7} +} + +func (x *GetTagSuggestionsRequest) GetUser() string { + if x != nil { + return x.User + } + return "" +} + +type GetTagSuggestionsResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Tags []string `protobuf:"bytes,1,rep,name=tags,proto3" json:"tags,omitempty"` +} + +func (x *GetTagSuggestionsResponse) Reset() { + *x = GetTagSuggestionsResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_api_v2_tag_service_proto_msgTypes[8] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *GetTagSuggestionsResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*GetTagSuggestionsResponse) ProtoMessage() {} + +func (x *GetTagSuggestionsResponse) ProtoReflect() protoreflect.Message { + 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 { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use GetTagSuggestionsResponse.ProtoReflect.Descriptor instead. +func (*GetTagSuggestionsResponse) Descriptor() ([]byte, []int) { + return file_api_v2_tag_service_proto_rawDescGZIP(), []int{8} +} + +func (x *GetTagSuggestionsResponse) GetTags() []string { + if x != nil { + return x.Tags + } + return nil +} + var File_api_v2_tag_service_proto protoreflect.FileDescriptor var file_api_v2_tag_service_proto_rawDesc = []byte{ @@ -369,49 +465,63 @@ var file_api_v2_tag_service_proto_rawDesc = []byte{ 0x61, 0x6d, 0x65, 0x22, 0x38, 0x0a, 0x11, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 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, 0x2b, 0x0a, + 0x69, 0x2e, 0x76, 0x32, 0x2e, 0x54, 0x61, 0x67, 0x52, 0x03, 0x74, 0x61, 0x67, 0x22, 0x25, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x18, 0x0a, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x07, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x22, 0x39, 0x0a, 0x10, 0x4c, 0x69, - 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 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, 0x32, 0xb5, 0x02, 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, 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, + 0x12, 0x12, 0x0a, 0x04, 0x75, 0x73, 0x65, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x75, 0x73, 0x65, 0x72, 0x22, 0x39, 0x0a, 0x10, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, + 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, } var ( @@ -426,15 +536,17 @@ 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, 7) +var file_api_v2_tag_service_proto_msgTypes = make([]protoimpl.MessageInfo, 9) 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 + (*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 } var file_api_v2_tag_service_proto_depIdxs = []int32{ 0, // 0: memos.api.v2.UpsertTagResponse.tag:type_name -> memos.api.v2.Tag @@ -443,11 +555,13 @@ var file_api_v2_tag_service_proto_depIdxs = []int32{ 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 - 2, // 6: memos.api.v2.TagService.UpsertTag:output_type -> memos.api.v2.UpsertTagResponse - 4, // 7: memos.api.v2.TagService.ListTags:output_type -> memos.api.v2.ListTagsResponse - 6, // 8: memos.api.v2.TagService.DeleteTag:output_type -> memos.api.v2.DeleteTagResponse - 6, // [6:9] is the sub-list for method output_type - 3, // [3:6] is the sub-list for method input_type + 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 @@ -543,6 +657,30 @@ func file_api_v2_tag_service_proto_init() { return nil } } + file_api_v2_tag_service_proto_msgTypes[7].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[8].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*GetTagSuggestionsResponse); 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{ @@ -550,7 +688,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: 7, + NumMessages: 9, 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 d17731c2..3ac580b4 100644 --- a/proto/gen/api/v2/tag_service.pb.gw.go +++ b/proto/gen/api/v2/tag_service.pb.gw.go @@ -139,6 +139,42 @@ func local_request_TagService_DeleteTag_0(ctx context.Context, marshaler runtime } +var ( + filter_TagService_GetTagSuggestions_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)} +) + +func request_TagService_GetTagSuggestions_0(ctx context.Context, marshaler runtime.Marshaler, client TagServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetTagSuggestionsRequest + 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_GetTagSuggestions_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := client.GetTagSuggestions(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) + return msg, metadata, err + +} + +func local_request_TagService_GetTagSuggestions_0(ctx context.Context, marshaler runtime.Marshaler, server TagServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { + var protoReq GetTagSuggestionsRequest + 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_GetTagSuggestions_0); err != nil { + return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err) + } + + msg, err := server.GetTagSuggestions(ctx, &protoReq) + return msg, metadata, err + +} + // RegisterTagServiceHandlerServer registers the http handlers for service TagService to "mux". // UnaryRPC :call TagServiceServer directly. // StreamingRPC :currently unsupported pending https://github.com/grpc/grpc-go/issues/906. @@ -220,6 +256,31 @@ func RegisterTagServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, }) + mux.Handle("GET", pattern_TagService_GetTagSuggestions_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/GetTagSuggestions", runtime.WithHTTPPathPattern("/api/v2/tags/suggestion")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := local_request_TagService_GetTagSuggestions_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_GetTagSuggestions_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -327,6 +388,28 @@ func RegisterTagServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, }) + mux.Handle("GET", pattern_TagService_GetTagSuggestions_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/GetTagSuggestions", runtime.WithHTTPPathPattern("/api/v2/tags/suggestion")) + if err != nil { + runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) + return + } + resp, md, err := request_TagService_GetTagSuggestions_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_GetTagSuggestions_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) + + }) + return nil } @@ -336,6 +419,8 @@ var ( pattern_TagService_ListTags_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "tags"}, "")) 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"}, "")) ) var ( @@ -344,4 +429,6 @@ var ( forward_TagService_ListTags_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 871ef1d4..00666e0d 100644 --- a/proto/gen/api/v2/tag_service_grpc.pb.go +++ b/proto/gen/api/v2/tag_service_grpc.pb.go @@ -19,9 +19,10 @@ import ( const _ = grpc.SupportPackageIsVersion7 const ( - TagService_UpsertTag_FullMethodName = "/memos.api.v2.TagService/UpsertTag" - TagService_ListTags_FullMethodName = "/memos.api.v2.TagService/ListTags" - TagService_DeleteTag_FullMethodName = "/memos.api.v2.TagService/DeleteTag" + TagService_UpsertTag_FullMethodName = "/memos.api.v2.TagService/UpsertTag" + TagService_ListTags_FullMethodName = "/memos.api.v2.TagService/ListTags" + TagService_DeleteTag_FullMethodName = "/memos.api.v2.TagService/DeleteTag" + TagService_GetTagSuggestions_FullMethodName = "/memos.api.v2.TagService/GetTagSuggestions" ) // TagServiceClient is the client API for TagService service. @@ -31,6 +32,7 @@ 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) DeleteTag(ctx context.Context, in *DeleteTagRequest, opts ...grpc.CallOption) (*DeleteTagResponse, error) + GetTagSuggestions(ctx context.Context, in *GetTagSuggestionsRequest, opts ...grpc.CallOption) (*GetTagSuggestionsResponse, error) } type tagServiceClient struct { @@ -68,6 +70,15 @@ func (c *tagServiceClient) DeleteTag(ctx context.Context, in *DeleteTagRequest, return out, nil } +func (c *tagServiceClient) GetTagSuggestions(ctx context.Context, in *GetTagSuggestionsRequest, opts ...grpc.CallOption) (*GetTagSuggestionsResponse, error) { + out := new(GetTagSuggestionsResponse) + err := c.cc.Invoke(ctx, TagService_GetTagSuggestions_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + // TagServiceServer is the server API for TagService service. // All implementations must embed UnimplementedTagServiceServer // for forward compatibility @@ -75,6 +86,7 @@ type TagServiceServer interface { UpsertTag(context.Context, *UpsertTagRequest) (*UpsertTagResponse, error) ListTags(context.Context, *ListTagsRequest) (*ListTagsResponse, error) DeleteTag(context.Context, *DeleteTagRequest) (*DeleteTagResponse, error) + GetTagSuggestions(context.Context, *GetTagSuggestionsRequest) (*GetTagSuggestionsResponse, error) mustEmbedUnimplementedTagServiceServer() } @@ -91,6 +103,9 @@ func (UnimplementedTagServiceServer) ListTags(context.Context, *ListTagsRequest) func (UnimplementedTagServiceServer) DeleteTag(context.Context, *DeleteTagRequest) (*DeleteTagResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method DeleteTag not implemented") } +func (UnimplementedTagServiceServer) GetTagSuggestions(context.Context, *GetTagSuggestionsRequest) (*GetTagSuggestionsResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method GetTagSuggestions not implemented") +} func (UnimplementedTagServiceServer) mustEmbedUnimplementedTagServiceServer() {} // UnsafeTagServiceServer may be embedded to opt out of forward compatibility for this service. @@ -158,6 +173,24 @@ func _TagService_DeleteTag_Handler(srv interface{}, ctx context.Context, dec fun return interceptor(ctx, in, info, handler) } +func _TagService_GetTagSuggestions_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(GetTagSuggestionsRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(TagServiceServer).GetTagSuggestions(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: TagService_GetTagSuggestions_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(TagServiceServer).GetTagSuggestions(ctx, req.(*GetTagSuggestionsRequest)) + } + return interceptor(ctx, in, info, handler) +} + // TagService_ServiceDesc is the grpc.ServiceDesc for TagService service. // It's only intended for direct use with grpc.RegisterService, // and not to be introspected or modified (even as a copy) @@ -177,6 +210,10 @@ var TagService_ServiceDesc = grpc.ServiceDesc{ MethodName: "DeleteTag", Handler: _TagService_DeleteTag_Handler, }, + { + MethodName: "GetTagSuggestions", + Handler: _TagService_GetTagSuggestions_Handler, + }, }, Streams: []grpc.StreamDesc{}, Metadata: "api/v2/tag_service.proto", diff --git a/web/src/components/CreateTagDialog.tsx b/web/src/components/CreateTagDialog.tsx index 76cc2223..8fe9b601 100644 --- a/web/src/components/CreateTagDialog.tsx +++ b/web/src/components/CreateTagDialog.tsx @@ -1,7 +1,8 @@ import { Button, Input } from "@mui/joy"; import React, { useEffect, useState } from "react"; import { toast } from "react-hot-toast"; -import { getTagSuggestionList } from "@/helpers/api"; +import { tagServiceClient } from "@/grpcweb"; +import useCurrentUser from "@/hooks/useCurrentUser"; import { matcher } from "@/labs/marked/matcher"; import Tag from "@/labs/marked/parser/Tag"; import { useTagStore } from "@/store/module"; @@ -22,8 +23,9 @@ const validateTagName = (tagName: string): boolean => { const CreateTagDialog: React.FC = (props: Props) => { const { destroy } = props; - const tagStore = useTagStore(); const t = useTranslate(); + const currentUser = useCurrentUser(); + const tagStore = useTagStore(); const [tagName, setTagName] = useState(""); const [suggestTagNameList, setSuggestTagNameList] = useState([]); const [showTagSuggestions, setShowTagSuggestions] = useState(false); @@ -31,9 +33,13 @@ const CreateTagDialog: React.FC = (props: Props) => { const shownSuggestTagNameList = suggestTagNameList.filter((tag) => !tagNameList.includes(tag)); useEffect(() => { - getTagSuggestionList().then(({ data }) => { - setSuggestTagNameList(data.filter((tag) => validateTagName(tag))); - }); + tagServiceClient + .getTagSuggestions({ + user: currentUser.name, + }) + .then(({ tags }) => { + setSuggestTagNameList(tags.filter((tag) => validateTagName(tag))); + }); }, [tagNameList]); const handleTagNameInputKeyDown = (event: React.KeyboardEvent) => { diff --git a/web/src/helpers/api.ts b/web/src/helpers/api.ts index c307cdcd..ead0514c 100644 --- a/web/src/helpers/api.ts +++ b/web/src/helpers/api.ts @@ -144,10 +144,6 @@ export function createResourceWithBlob(formData: FormData) { return axios.post("/api/v1/resource/blob", formData); } -export function getTagSuggestionList() { - return axios.get(`/api/v1/tag/suggestion`); -} - export function getStorageList() { return axios.get(`/api/v1/storage`); } diff --git a/web/src/store/module/tag.ts b/web/src/store/module/tag.ts index 4d816cef..ff8f6c94 100644 --- a/web/src/store/module/tag.ts +++ b/web/src/store/module/tag.ts @@ -13,7 +13,7 @@ export const useTagStore = () => { const fetchTags = async () => { const { tags } = await tagServiceClient.listTags({ - creator: currentUser.name, + user: currentUser.name, }); store.dispatch(setTags(tags.map((tag) => tag.name))); };