chore: implement memo property endpoint

This commit is contained in:
Steven
2024-05-22 09:21:12 +08:00
parent 16d3de63c2
commit e0600388b2
8 changed files with 1123 additions and 654 deletions

View File

@@ -57,10 +57,14 @@ service MemoService {
body: "*"
};
}
// ListMemoProperties lists memo properties.
rpc ListMemoProperties(ListMemoPropertiesRequest) returns (ListMemoPropertiesResponse) {
option (google.api.http) = {get: "/api/v1/{name=memos/*}/properties"};
}
// RebuildMemoProperty rebuilds a memo property.
rpc RebuildMemoProperty(RebuildMemoPropertyRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {
post: "/api/v1/{name=memos/*}:rebuild"
post: "/api/v1/{name=memos/*}/properties:rebuild"
body: "*"
};
}
@@ -181,13 +185,24 @@ message Memo {
bool pinned = 12;
optional int32 parent_id = 13 [(google.api.field_behavior) = OUTPUT_ONLY];
MemoProperty property = 13 [(google.api.field_behavior) = OUTPUT_ONLY];
repeated Resource resources = 14 [(google.api.field_behavior) = OUTPUT_ONLY];
// The name of the parent memo.
// Format: memos/{id}
// id is the system generated id.
optional string parent = 14 [(google.api.field_behavior) = OUTPUT_ONLY];
repeated MemoRelation relations = 15 [(google.api.field_behavior) = OUTPUT_ONLY];
repeated Resource resources = 15 [(google.api.field_behavior) = OUTPUT_ONLY];
repeated Reaction reactions = 16 [(google.api.field_behavior) = OUTPUT_ONLY];
repeated MemoRelation relations = 16 [(google.api.field_behavior) = OUTPUT_ONLY];
repeated Reaction reactions = 17 [(google.api.field_behavior) = OUTPUT_ONLY];
}
message MemoProperty {
repeated string tags = 1;
bool has_link = 2;
bool has_task_list = 3;
}
message CreateMemoRequest {
@@ -254,6 +269,16 @@ message ExportMemosResponse {
bytes content = 1;
}
message ListMemoPropertiesRequest {
// The name of the memo.
// Format: memos/{id}. Use "memos/-" to list all properties.
string name = 1;
}
message ListMemoPropertiesResponse {
repeated MemoProperty properties = 1;
}
message RebuildMemoPropertyRequest {
// The name of the memo.
// Format: memos/{id}. Use "memos/-" to rebuild all memos.

File diff suppressed because it is too large Load Diff

View File

@@ -359,6 +359,58 @@ func local_request_MemoService_ExportMemos_0(ctx context.Context, marshaler runt
}
func request_MemoService_ListMemoProperties_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListMemoPropertiesRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["name"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name")
}
protoReq.Name, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err)
}
msg, err := client.ListMemoProperties(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_MemoService_ListMemoProperties_0(ctx context.Context, marshaler runtime.Marshaler, server MemoServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq ListMemoPropertiesRequest
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
val, ok = pathParams["name"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "name")
}
protoReq.Name, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "name", err)
}
msg, err := server.ListMemoProperties(ctx, &protoReq)
return msg, metadata, err
}
func request_MemoService_RebuildMemoProperty_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var protoReq RebuildMemoPropertyRequest
var metadata runtime.ServerMetadata
@@ -1356,6 +1408,31 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
})
mux.Handle("GET", pattern_MemoService_ListMemoProperties_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.v1.MemoService/ListMemoProperties", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/properties"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_MemoService_ListMemoProperties_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_MemoService_ListMemoProperties_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_MemoService_RebuildMemoProperty_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@@ -1364,7 +1441,7 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
var err error
var annotatedContext context.Context
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/RebuildMemoProperty", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}:rebuild"))
annotatedContext, err = runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/RebuildMemoProperty", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/properties:rebuild"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
@@ -1901,13 +1978,35 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
})
mux.Handle("GET", pattern_MemoService_ListMemoProperties_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.v1.MemoService/ListMemoProperties", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/properties"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_MemoService_ListMemoProperties_0(annotatedContext, inboundMarshaler, client, req, pathParams)
annotatedContext = runtime.NewServerMetadataContext(annotatedContext, md)
if err != nil {
runtime.HTTPError(annotatedContext, mux, outboundMarshaler, w, req, err)
return
}
forward_MemoService_ListMemoProperties_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle("POST", pattern_MemoService_RebuildMemoProperty_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.v1.MemoService/RebuildMemoProperty", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}:rebuild"))
annotatedContext, err = runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/RebuildMemoProperty", runtime.WithHTTPPathPattern("/api/v1/{name=memos/*}/properties:rebuild"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
@@ -2227,7 +2326,9 @@ var (
pattern_MemoService_ExportMemos_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "export"))
pattern_MemoService_RebuildMemoProperty_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "rebuild"))
pattern_MemoService_ListMemoProperties_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "properties"}, ""))
pattern_MemoService_RebuildMemoProperty_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "properties"}, "rebuild"))
pattern_MemoService_ListMemoTags_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "parent", "tags"}, ""))
@@ -2271,6 +2372,8 @@ var (
forward_MemoService_ExportMemos_0 = runtime.ForwardResponseMessage
forward_MemoService_ListMemoProperties_0 = runtime.ForwardResponseMessage
forward_MemoService_RebuildMemoProperty_0 = runtime.ForwardResponseMessage
forward_MemoService_ListMemoTags_0 = runtime.ForwardResponseMessage

View File

@@ -27,6 +27,7 @@ const (
MemoService_UpdateMemo_FullMethodName = "/memos.api.v1.MemoService/UpdateMemo"
MemoService_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo"
MemoService_ExportMemos_FullMethodName = "/memos.api.v1.MemoService/ExportMemos"
MemoService_ListMemoProperties_FullMethodName = "/memos.api.v1.MemoService/ListMemoProperties"
MemoService_RebuildMemoProperty_FullMethodName = "/memos.api.v1.MemoService/RebuildMemoProperty"
MemoService_ListMemoTags_FullMethodName = "/memos.api.v1.MemoService/ListMemoTags"
MemoService_RenameMemoTag_FullMethodName = "/memos.api.v1.MemoService/RenameMemoTag"
@@ -61,6 +62,8 @@ type MemoServiceClient interface {
DeleteMemo(ctx context.Context, in *DeleteMemoRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// ExportMemos exports memos.
ExportMemos(ctx context.Context, in *ExportMemosRequest, opts ...grpc.CallOption) (*ExportMemosResponse, error)
// ListMemoProperties lists memo properties.
ListMemoProperties(ctx context.Context, in *ListMemoPropertiesRequest, opts ...grpc.CallOption) (*ListMemoPropertiesResponse, error)
// RebuildMemoProperty rebuilds a memo property.
RebuildMemoProperty(ctx context.Context, in *RebuildMemoPropertyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// ListMemoTags lists tags for a memo.
@@ -162,6 +165,15 @@ func (c *memoServiceClient) ExportMemos(ctx context.Context, in *ExportMemosRequ
return out, nil
}
func (c *memoServiceClient) ListMemoProperties(ctx context.Context, in *ListMemoPropertiesRequest, opts ...grpc.CallOption) (*ListMemoPropertiesResponse, error) {
out := new(ListMemoPropertiesResponse)
err := c.cc.Invoke(ctx, MemoService_ListMemoProperties_FullMethodName, in, out, opts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *memoServiceClient) RebuildMemoProperty(ctx context.Context, in *RebuildMemoPropertyRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, MemoService_RebuildMemoProperty_FullMethodName, in, out, opts...)
@@ -306,6 +318,8 @@ type MemoServiceServer interface {
DeleteMemo(context.Context, *DeleteMemoRequest) (*emptypb.Empty, error)
// ExportMemos exports memos.
ExportMemos(context.Context, *ExportMemosRequest) (*ExportMemosResponse, error)
// ListMemoProperties lists memo properties.
ListMemoProperties(context.Context, *ListMemoPropertiesRequest) (*ListMemoPropertiesResponse, error)
// RebuildMemoProperty rebuilds a memo property.
RebuildMemoProperty(context.Context, *RebuildMemoPropertyRequest) (*emptypb.Empty, error)
// ListMemoTags lists tags for a memo.
@@ -362,6 +376,9 @@ func (UnimplementedMemoServiceServer) DeleteMemo(context.Context, *DeleteMemoReq
func (UnimplementedMemoServiceServer) ExportMemos(context.Context, *ExportMemosRequest) (*ExportMemosResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ExportMemos not implemented")
}
func (UnimplementedMemoServiceServer) ListMemoProperties(context.Context, *ListMemoPropertiesRequest) (*ListMemoPropertiesResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListMemoProperties not implemented")
}
func (UnimplementedMemoServiceServer) RebuildMemoProperty(context.Context, *RebuildMemoPropertyRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method RebuildMemoProperty not implemented")
}
@@ -543,6 +560,24 @@ func _MemoService_ExportMemos_Handler(srv interface{}, ctx context.Context, dec
return interceptor(ctx, in, info, handler)
}
func _MemoService_ListMemoProperties_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(ListMemoPropertiesRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MemoServiceServer).ListMemoProperties(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: MemoService_ListMemoProperties_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MemoServiceServer).ListMemoProperties(ctx, req.(*ListMemoPropertiesRequest))
}
return interceptor(ctx, in, info, handler)
}
func _MemoService_RebuildMemoProperty_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(RebuildMemoPropertyRequest)
if err := dec(in); err != nil {
@@ -830,6 +865,10 @@ var MemoService_ServiceDesc = grpc.ServiceDesc{
MethodName: "ExportMemos",
Handler: _MemoService_ExportMemos_Handler,
},
{
MethodName: "ListMemoProperties",
Handler: _MemoService_ListMemoProperties_Handler,
},
{
MethodName: "RebuildMemoProperty",
Handler: _MemoService_RebuildMemoProperty_Handler,