chore: update tag service

This commit is contained in:
Steven 2023-10-03 09:39:39 +08:00
parent 69d575fd5b
commit 1542f3172a
8 changed files with 703 additions and 79 deletions

View File

@ -23,6 +23,25 @@ func NewTagService(store *store.Store) *TagService {
}
}
func (s *TagService) UpsertTag(ctx context.Context, request *apiv2pb.UpsertTagRequest) (*apiv2pb.UpsertTagResponse, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get user")
}
tag, err := s.Store.UpsertTag(ctx, &store.Tag{
Name: request.Name,
CreatorID: user.ID,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to upsert tag: %v", err)
}
return &apiv2pb.UpsertTagResponse{
Tag: convertTagFromStore(tag),
}, nil
}
func (s *TagService) ListTags(ctx context.Context, request *apiv2pb.ListTagsRequest) (*apiv2pb.ListTagsResponse, error) {
tags, err := s.Store.ListTags(ctx, &store.FindTag{
CreatorID: request.CreatorId,
@ -38,6 +57,18 @@ func (s *TagService) ListTags(ctx context.Context, request *apiv2pb.ListTagsRequ
return response, nil
}
func (s *TagService) DeleteTag(ctx context.Context, request *apiv2pb.DeleteTagRequest) (*apiv2pb.DeleteTagResponse, error) {
err := s.Store.DeleteTag(ctx, &store.DeleteTag{
Name: request.Tag.Name,
CreatorID: request.Tag.CreatorId,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete tag: %v", err)
}
return &apiv2pb.DeleteTagResponse{}, nil
}
func convertTagFromStore(tag *store.Tag) *apiv2pb.Tag {
return &apiv2pb.Tag{
Name: tag.Name,

View File

@ -7,9 +7,15 @@ import "google/api/annotations.proto";
option go_package = "gen/api/v2";
service TagService {
rpc UpsertTag(UpsertTagRequest) returns (UpsertTagResponse) {
option (google.api.http) = {post: "/api/v2/tags"};
}
rpc ListTags(ListTagsRequest) returns (ListTagsResponse) {
option (google.api.http) = {get: "/api/v2/tags"};
}
rpc DeleteTag(DeleteTagRequest) returns (DeleteTagResponse) {
option (google.api.http) = {delete: "/api/v2/tags"};
}
}
message Tag {
@ -17,6 +23,14 @@ message Tag {
int32 creator_id = 2;
}
message UpsertTagRequest {
string name = 1;
}
message UpsertTagResponse {
Tag tag = 1;
}
message ListTagsRequest {
int32 creator_id = 1;
}
@ -24,3 +38,9 @@ message ListTagsRequest {
message ListTagsResponse {
repeated Tag tags = 1;
}
message DeleteTagRequest {
Tag tag = 1;
}
message DeleteTagResponse {}

View File

@ -42,9 +42,13 @@
- [SystemService](#memos-api-v2-SystemService)
- [api/v2/tag_service.proto](#api_v2_tag_service-proto)
- [DeleteTagRequest](#memos-api-v2-DeleteTagRequest)
- [DeleteTagResponse](#memos-api-v2-DeleteTagResponse)
- [ListTagsRequest](#memos-api-v2-ListTagsRequest)
- [ListTagsResponse](#memos-api-v2-ListTagsResponse)
- [Tag](#memos-api-v2-Tag)
- [UpsertTagRequest](#memos-api-v2-UpsertTagRequest)
- [UpsertTagResponse](#memos-api-v2-UpsertTagResponse)
- [TagService](#memos-api-v2-TagService)
@ -528,6 +532,31 @@
<a name="memos-api-v2-DeleteTagRequest"></a>
### DeleteTagRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| tag | [Tag](#memos-api-v2-Tag) | | |
<a name="memos-api-v2-DeleteTagResponse"></a>
### DeleteTagResponse
<a name="memos-api-v2-ListTagsRequest"></a>
### ListTagsRequest
@ -573,6 +602,36 @@
<a name="memos-api-v2-UpsertTagRequest"></a>
### UpsertTagRequest
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| name | [string](#string) | | |
<a name="memos-api-v2-UpsertTagResponse"></a>
### UpsertTagResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| tag | [Tag](#memos-api-v2-Tag) | | |
@ -587,7 +646,9 @@
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| 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) | |

View File

@ -76,6 +76,100 @@ func (x *Tag) GetCreatorId() int32 {
return 0
}
type UpsertTagRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
}
func (x *UpsertTagRequest) Reset() {
*x = UpsertTagRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v2_tag_service_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpsertTagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpsertTagRequest) ProtoMessage() {}
func (x *UpsertTagRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_v2_tag_service_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpsertTagRequest.ProtoReflect.Descriptor instead.
func (*UpsertTagRequest) Descriptor() ([]byte, []int) {
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{1}
}
func (x *UpsertTagRequest) GetName() string {
if x != nil {
return x.Name
}
return ""
}
type UpsertTagResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Tag *Tag `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"`
}
func (x *UpsertTagResponse) Reset() {
*x = UpsertTagResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v2_tag_service_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *UpsertTagResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*UpsertTagResponse) ProtoMessage() {}
func (x *UpsertTagResponse) ProtoReflect() protoreflect.Message {
mi := &file_api_v2_tag_service_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use UpsertTagResponse.ProtoReflect.Descriptor instead.
func (*UpsertTagResponse) Descriptor() ([]byte, []int) {
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{2}
}
func (x *UpsertTagResponse) GetTag() *Tag {
if x != nil {
return x.Tag
}
return nil
}
type ListTagsRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -87,7 +181,7 @@ type ListTagsRequest struct {
func (x *ListTagsRequest) Reset() {
*x = ListTagsRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v2_tag_service_proto_msgTypes[1]
mi := &file_api_v2_tag_service_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -100,7 +194,7 @@ func (x *ListTagsRequest) String() string {
func (*ListTagsRequest) ProtoMessage() {}
func (x *ListTagsRequest) ProtoReflect() protoreflect.Message {
mi := &file_api_v2_tag_service_proto_msgTypes[1]
mi := &file_api_v2_tag_service_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -113,7 +207,7 @@ func (x *ListTagsRequest) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListTagsRequest.ProtoReflect.Descriptor instead.
func (*ListTagsRequest) Descriptor() ([]byte, []int) {
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{1}
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{3}
}
func (x *ListTagsRequest) GetCreatorId() int32 {
@ -134,7 +228,7 @@ type ListTagsResponse struct {
func (x *ListTagsResponse) Reset() {
*x = ListTagsResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v2_tag_service_proto_msgTypes[2]
mi := &file_api_v2_tag_service_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
@ -147,7 +241,7 @@ func (x *ListTagsResponse) String() string {
func (*ListTagsResponse) ProtoMessage() {}
func (x *ListTagsResponse) ProtoReflect() protoreflect.Message {
mi := &file_api_v2_tag_service_proto_msgTypes[2]
mi := &file_api_v2_tag_service_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
@ -160,7 +254,7 @@ func (x *ListTagsResponse) ProtoReflect() protoreflect.Message {
// Deprecated: Use ListTagsResponse.ProtoReflect.Descriptor instead.
func (*ListTagsResponse) Descriptor() ([]byte, []int) {
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{2}
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{4}
}
func (x *ListTagsResponse) GetTags() []*Tag {
@ -170,6 +264,91 @@ func (x *ListTagsResponse) GetTags() []*Tag {
return nil
}
type DeleteTagRequest struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Tag *Tag `protobuf:"bytes,1,opt,name=tag,proto3" json:"tag,omitempty"`
}
func (x *DeleteTagRequest) Reset() {
*x = DeleteTagRequest{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v2_tag_service_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteTagRequest) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteTagRequest) ProtoMessage() {}
func (x *DeleteTagRequest) 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 DeleteTagRequest.ProtoReflect.Descriptor instead.
func (*DeleteTagRequest) Descriptor() ([]byte, []int) {
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{5}
}
func (x *DeleteTagRequest) GetTag() *Tag {
if x != nil {
return x.Tag
}
return nil
}
type DeleteTagResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
}
func (x *DeleteTagResponse) Reset() {
*x = DeleteTagResponse{}
if protoimpl.UnsafeEnabled {
mi := &file_api_v2_tag_service_proto_msgTypes[6]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeleteTagResponse) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeleteTagResponse) ProtoMessage() {}
func (x *DeleteTagResponse) 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 DeleteTagResponse.ProtoReflect.Descriptor instead.
func (*DeleteTagResponse) Descriptor() ([]byte, []int) {
return file_api_v2_tag_service_proto_rawDescGZIP(), []int{6}
}
var File_api_v2_tag_service_proto protoreflect.FileDescriptor
var file_api_v2_tag_service_proto_rawDesc = []byte{
@ -181,31 +360,55 @@ var file_api_v2_tag_service_proto_rawDesc = []byte{
0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d,
0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x69, 0x64, 0x18,
0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x49, 0x64,
0x22, 0x30, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65, 0x71, 0x75,
0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72, 0x5f, 0x69,
0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72,
0x49, 0x64, 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, 0x32, 0x6d, 0x0a,
0x0a, 0x54, 0x61, 0x67, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 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, 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,
0x22, 0x26, 0x0a, 0x10, 0x55, 0x70, 0x73, 0x65, 0x72, 0x74, 0x54, 0x61, 0x67, 0x52, 0x65, 0x71,
0x75, 0x65, 0x73, 0x74, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01,
0x28, 0x09, 0x52, 0x04, 0x6e, 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, 0x30, 0x0a, 0x0f, 0x4c, 0x69, 0x73, 0x74, 0x54, 0x61, 0x67, 0x73, 0x52, 0x65,
0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x72, 0x65, 0x61, 0x74, 0x6f, 0x72,
0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x09, 0x63, 0x72, 0x65, 0x61, 0x74,
0x6f, 0x72, 0x49, 0x64, 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,
}
var (
@ -220,21 +423,31 @@ 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, 3)
var file_api_v2_tag_service_proto_msgTypes = make([]protoimpl.MessageInfo, 7)
var file_api_v2_tag_service_proto_goTypes = []interface{}{
(*Tag)(nil), // 0: memos.api.v2.Tag
(*ListTagsRequest)(nil), // 1: memos.api.v2.ListTagsRequest
(*ListTagsResponse)(nil), // 2: memos.api.v2.ListTagsResponse
(*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
}
var file_api_v2_tag_service_proto_depIdxs = []int32{
0, // 0: memos.api.v2.ListTagsResponse.tags:type_name -> memos.api.v2.Tag
1, // 1: memos.api.v2.TagService.ListTags:input_type -> memos.api.v2.ListTagsRequest
2, // 2: memos.api.v2.TagService.ListTags:output_type -> memos.api.v2.ListTagsResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
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
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
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
}
func init() { file_api_v2_tag_service_proto_init() }
@ -256,7 +469,7 @@ func file_api_v2_tag_service_proto_init() {
}
}
file_api_v2_tag_service_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListTagsRequest); i {
switch v := v.(*UpsertTagRequest); i {
case 0:
return &v.state
case 1:
@ -268,6 +481,30 @@ func file_api_v2_tag_service_proto_init() {
}
}
file_api_v2_tag_service_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*UpsertTagResponse); 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[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListTagsRequest); 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[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*ListTagsResponse); i {
case 0:
return &v.state
@ -279,6 +516,30 @@ func file_api_v2_tag_service_proto_init() {
return nil
}
}
file_api_v2_tag_service_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeleteTagRequest); 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[6].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
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
@ -286,7 +547,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: 3,
NumMessages: 7,
NumExtensions: 0,
NumServices: 1,
},

View File

@ -31,6 +31,42 @@ var _ = runtime.String
var _ = utilities.NewDoubleArray
var _ = metadata.Join
var (
filter_TagService_UpsertTag_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_TagService_UpsertTag_0(ctx context.Context, marshaler runtime.Marshaler, client TagServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq UpsertTagRequest
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_UpsertTag_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.UpsertTag(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_TagService_UpsertTag_0(ctx context.Context, marshaler runtime.Marshaler, server TagServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq UpsertTagRequest
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_UpsertTag_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.UpsertTag(ctx, &protoReq)
return msg, metadata, err
}
var (
filter_TagService_ListTags_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
@ -67,12 +103,73 @@ func local_request_TagService_ListTags_0(ctx context.Context, marshaler runtime.
}
var (
filter_TagService_DeleteTag_0 = &utilities.DoubleArray{Encoding: map[string]int{}, Base: []int(nil), Check: []int(nil)}
)
func request_TagService_DeleteTag_0(ctx context.Context, marshaler runtime.Marshaler, client TagServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq DeleteTagRequest
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_DeleteTag_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := client.DeleteTag(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_TagService_DeleteTag_0(ctx context.Context, marshaler runtime.Marshaler, server TagServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq DeleteTagRequest
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_DeleteTag_0); err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "%v", err)
}
msg, err := server.DeleteTag(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.
// Note that using this registration option will cause many gRPC library features to stop working. Consider using RegisterTagServiceHandlerFromEndpoint instead.
func RegisterTagServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux, server TagServiceServer) error {
mux.Handle("POST", pattern_TagService_UpsertTag_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/UpsertTag", runtime.WithHTTPPathPattern("/api/v2/tags"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_TagService_UpsertTag_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_UpsertTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_TagService_ListTags_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@ -98,6 +195,31 @@ func RegisterTagServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux,
})
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()
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/DeleteTag", runtime.WithHTTPPathPattern("/api/v2/tags"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_TagService_DeleteTag_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_DeleteTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
@ -139,6 +261,28 @@ func RegisterTagServiceHandler(ctx context.Context, mux *runtime.ServeMux, conn
// "TagServiceClient" to call the correct interceptors.
func RegisterTagServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux, client TagServiceClient) error {
mux.Handle("POST", pattern_TagService_UpsertTag_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/UpsertTag", runtime.WithHTTPPathPattern("/api/v2/tags"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_TagService_UpsertTag_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_UpsertTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("GET", pattern_TagService_ListTags_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@ -161,13 +305,43 @@ func RegisterTagServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux,
})
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()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v2.TagService/DeleteTag", runtime.WithHTTPPathPattern("/api/v2/tags"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_TagService_DeleteTag_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_DeleteTag_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
return nil
}
var (
pattern_TagService_UpsertTag_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v2", "tags"}, ""))
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"}, ""))
)
var (
forward_TagService_UpsertTag_0 = runtime.ForwardResponseMessage
forward_TagService_ListTags_0 = runtime.ForwardResponseMessage
forward_TagService_DeleteTag_0 = runtime.ForwardResponseMessage
)

View File

@ -19,14 +19,18 @@ import (
const _ = grpc.SupportPackageIsVersion7
const (
TagService_ListTags_FullMethodName = "/memos.api.v2.TagService/ListTags"
TagService_UpsertTag_FullMethodName = "/memos.api.v2.TagService/UpsertTag"
TagService_ListTags_FullMethodName = "/memos.api.v2.TagService/ListTags"
TagService_DeleteTag_FullMethodName = "/memos.api.v2.TagService/DeleteTag"
)
// TagServiceClient is the client API for TagService service.
//
// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.
type 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)
}
type tagServiceClient struct {
@ -37,6 +41,15 @@ func NewTagServiceClient(cc grpc.ClientConnInterface) TagServiceClient {
return &tagServiceClient{cc}
}
func (c *tagServiceClient) UpsertTag(ctx context.Context, in *UpsertTagRequest, opts ...grpc.CallOption) (*UpsertTagResponse, error) {
out := new(UpsertTagResponse)
err := c.cc.Invoke(ctx, TagService_UpsertTag_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *tagServiceClient) ListTags(ctx context.Context, in *ListTagsRequest, opts ...grpc.CallOption) (*ListTagsResponse, error) {
out := new(ListTagsResponse)
err := c.cc.Invoke(ctx, TagService_ListTags_FullMethodName, in, out, opts...)
@ -46,11 +59,22 @@ func (c *tagServiceClient) ListTags(ctx context.Context, in *ListTagsRequest, op
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...)
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
type TagServiceServer interface {
UpsertTag(context.Context, *UpsertTagRequest) (*UpsertTagResponse, error)
ListTags(context.Context, *ListTagsRequest) (*ListTagsResponse, error)
DeleteTag(context.Context, *DeleteTagRequest) (*DeleteTagResponse, error)
mustEmbedUnimplementedTagServiceServer()
}
@ -58,9 +82,15 @@ type TagServiceServer interface {
type UnimplementedTagServiceServer struct {
}
func (UnimplementedTagServiceServer) UpsertTag(context.Context, *UpsertTagRequest) (*UpsertTagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpsertTag not implemented")
}
func (UnimplementedTagServiceServer) ListTags(context.Context, *ListTagsRequest) (*ListTagsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListTags not implemented")
}
func (UnimplementedTagServiceServer) DeleteTag(context.Context, *DeleteTagRequest) (*DeleteTagResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteTag not implemented")
}
func (UnimplementedTagServiceServer) mustEmbedUnimplementedTagServiceServer() {}
// UnsafeTagServiceServer may be embedded to opt out of forward compatibility for this service.
@ -74,6 +104,24 @@ func RegisterTagServiceServer(s grpc.ServiceRegistrar, srv TagServiceServer) {
s.RegisterService(&TagService_ServiceDesc, srv)
}
func _TagService_UpsertTag_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpsertTagRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(TagServiceServer).UpsertTag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: TagService_UpsertTag_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TagServiceServer).UpsertTag(ctx, req.(*UpsertTagRequest))
}
return interceptor(ctx, in, info, handler)
}
func _TagService_ListTags_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListTagsRequest)
if err := dec(in); err != nil {
@ -92,6 +140,24 @@ func _TagService_ListTags_Handler(srv interface{}, ctx context.Context, dec func
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 {
return nil, err
}
if interceptor == nil {
return srv.(TagServiceServer).DeleteTag(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: TagService_DeleteTag_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(TagServiceServer).DeleteTag(ctx, req.(*DeleteTagRequest))
}
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)
@ -99,10 +165,18 @@ var TagService_ServiceDesc = grpc.ServiceDesc{
ServiceName: "memos.api.v2.TagService",
HandlerType: (*TagServiceServer)(nil),
Methods: []grpc.MethodDesc{
{
MethodName: "UpsertTag",
Handler: _TagService_UpsertTag_Handler,
},
{
MethodName: "ListTags",
Handler: _TagService_ListTags_Handler,
},
{
MethodName: "DeleteTag",
Handler: _TagService_DeleteTag_Handler,
},
},
Streams: []grpc.StreamDesc{},
Metadata: "api/v2/tag_service.proto",

View File

@ -155,26 +155,10 @@ export function deleteResourceById(id: ResourceId) {
return axios.delete(`/api/v1/resource/${id}`);
}
export function getTagList() {
return axios.get<string[]>(`/api/v1/tag`);
}
export function getTagSuggestionList() {
return axios.get<string[]>(`/api/v1/tag/suggestion`);
}
export function upsertTag(tagName: string) {
return axios.post<string>(`/api/v1/tag`, {
name: tagName,
});
}
export function deleteTag(tagName: string) {
return axios.post(`/api/v1/tag/delete`, {
name: tagName,
});
}
export function getStorageList() {
return axios.get<ObjectStorage[]>(`/api/v1/storage`);
}

View File

@ -1,26 +1,45 @@
import * as api from "@/helpers/api";
import { tagServiceClient } from "@/grpcweb";
import useCurrentUser from "@/hooks/useCurrentUser";
import store, { useAppSelector } from "..";
import { deleteTag, setTags, upsertTag } from "../reducer/tag";
import { deleteTag as deleteTagAction, setTags, upsertTag as upsertTagAction } from "../reducer/tag";
export const useTagStore = () => {
const state = useAppSelector((state) => state.tag);
const currentUser = useCurrentUser();
const getState = () => {
return store.getState().tag;
};
const fetchTags = async () => {
const { tags } = await tagServiceClient.listTags({
creatorId: currentUser.id,
});
store.dispatch(setTags(tags.map((tag) => tag.name)));
};
const upsertTag = async (tagName: string) => {
await tagServiceClient.upsertTag({
name: tagName,
});
store.dispatch(upsertTagAction(tagName));
};
const deleteTag = async (tagName: string) => {
await tagServiceClient.deleteTag({
tag: {
name: tagName,
creatorId: currentUser.id,
},
});
store.dispatch(deleteTagAction(tagName));
};
return {
state,
getState: () => {
return store.getState().tag;
},
fetchTags: async () => {
const { data } = await api.getTagList();
store.dispatch(setTags(data));
},
upsertTag: async (tagName: string) => {
await api.upsertTag(tagName);
store.dispatch(upsertTag(tagName));
},
deleteTag: async (tagName: string) => {
await api.deleteTag(tagName);
store.dispatch(deleteTag(tagName));
},
getState,
fetchTags,
upsertTag,
deleteTag,
};
};