Commit 5e770dda authored by johnnyjoy's avatar johnnyjoy

refactor: memo name

parent 2f4c5d7b
...@@ -55,6 +55,6 @@ message ActivityVersionUpdatePayload { ...@@ -55,6 +55,6 @@ message ActivityVersionUpdatePayload {
message GetActivityRequest { message GetActivityRequest {
// The name of the activity. // The name of the activity.
// Format: activities/{id} // Format: activities/{id}, id is the system generated auto-incremented id.
string name = 1; string name = 1;
} }
...@@ -43,7 +43,7 @@ service IdentityProviderService { ...@@ -43,7 +43,7 @@ service IdentityProviderService {
message IdentityProvider { message IdentityProvider {
// The name of the identityProvider. // The name of the identityProvider.
// Format: identityProviders/{id} // Format: identityProviders/{id}, id is the system generated auto-incremented id.
string name = 1; string name = 1;
enum Type { enum Type {
...@@ -89,7 +89,6 @@ message ListIdentityProvidersResponse { ...@@ -89,7 +89,6 @@ message ListIdentityProvidersResponse {
message GetIdentityProviderRequest { message GetIdentityProviderRequest {
// The name of the identityProvider to get. // The name of the identityProvider to get.
// Format: identityProviders/{id}
string name = 1; string name = 1;
} }
...@@ -109,6 +108,5 @@ message UpdateIdentityProviderRequest { ...@@ -109,6 +108,5 @@ message UpdateIdentityProviderRequest {
message DeleteIdentityProviderRequest { message DeleteIdentityProviderRequest {
// The name of the identityProvider to delete. // The name of the identityProvider to delete.
// Format: identityProviders/{id}
string name = 1; string name = 1;
} }
...@@ -32,7 +32,7 @@ service InboxService { ...@@ -32,7 +32,7 @@ service InboxService {
message Inbox { message Inbox {
// The name of the inbox. // The name of the inbox.
// Format: inboxes/{id} // Format: inboxes/{id}, id is the system generated auto-incremented id.
string name = 1; string name = 1;
// Format: users/{user} // Format: users/{user}
string sender = 2; string sender = 2;
...@@ -85,6 +85,5 @@ message UpdateInboxRequest { ...@@ -85,6 +85,5 @@ message UpdateInboxRequest {
message DeleteInboxRequest { message DeleteInboxRequest {
// The name of the inbox to delete. // The name of the inbox to delete.
// Format: inboxes/{id}
string name = 1; string name = 1;
} }
...@@ -8,11 +8,11 @@ option go_package = "gen/api/v1"; ...@@ -8,11 +8,11 @@ option go_package = "gen/api/v1";
message MemoRelation { message MemoRelation {
// The name of memo. // The name of memo.
// Format: "memos/{id}" // Format: memos/{id}
Memo memo = 1; Memo memo = 1;
// The name of related memo. // The name of related memo.
// Format: "memos/{id}" // Format: memos/{id}
Memo related_memo = 2; Memo related_memo = 2;
enum Type { enum Type {
......
...@@ -33,11 +33,6 @@ service MemoService { ...@@ -33,11 +33,6 @@ service MemoService {
option (google.api.http) = {get: "/api/v1/{name=memos/*}"}; option (google.api.http) = {get: "/api/v1/{name=memos/*}"};
option (google.api.method_signature) = "name"; option (google.api.method_signature) = "name";
} }
// GetMemoByUid gets a memo by uid
rpc GetMemoByUid(GetMemoByUidRequest) returns (Memo) {
option (google.api.http) = {get: "/api/v1/memos:by-uid/{uid}"};
option (google.api.method_signature) = "uid";
}
// UpdateMemo updates a memo. // UpdateMemo updates a memo.
rpc UpdateMemo(UpdateMemoRequest) returns (Memo) { rpc UpdateMemo(UpdateMemoRequest) returns (Memo) {
option (google.api.http) = { option (google.api.http) = {
...@@ -130,12 +125,11 @@ enum Visibility { ...@@ -130,12 +125,11 @@ enum Visibility {
message Memo { message Memo {
// The name of the memo. // The name of the memo.
// Format: memos/{id} // Format: memos/{memo}, memo is the user defined id or uuid.
// id is the system generated id.
string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY]; string name = 1 [(google.api.field_behavior) = OUTPUT_ONLY];
// The user defined id of the memo. // The system generated unique id. Auto-incremented.
string uid = 2; int32 uid = 2 [(google.api.field_behavior) = OUTPUT_ONLY];
State state = 3; State state = 3;
...@@ -226,15 +220,9 @@ message ListMemosResponse { ...@@ -226,15 +220,9 @@ message ListMemosResponse {
message GetMemoRequest { message GetMemoRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
} }
message GetMemoByUidRequest {
// The uid of the memo.
string uid = 1;
}
message UpdateMemoRequest { message UpdateMemoRequest {
Memo memo = 1; Memo memo = 1;
...@@ -243,7 +231,6 @@ message UpdateMemoRequest { ...@@ -243,7 +231,6 @@ message UpdateMemoRequest {
message DeleteMemoRequest { message DeleteMemoRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
} }
...@@ -265,7 +252,6 @@ message DeleteMemoTagRequest { ...@@ -265,7 +252,6 @@ message DeleteMemoTagRequest {
message SetMemoResourcesRequest { message SetMemoResourcesRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
repeated Resource resources = 2; repeated Resource resources = 2;
...@@ -273,7 +259,6 @@ message SetMemoResourcesRequest { ...@@ -273,7 +259,6 @@ message SetMemoResourcesRequest {
message ListMemoResourcesRequest { message ListMemoResourcesRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
} }
...@@ -283,7 +268,6 @@ message ListMemoResourcesResponse { ...@@ -283,7 +268,6 @@ message ListMemoResourcesResponse {
message SetMemoRelationsRequest { message SetMemoRelationsRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
repeated MemoRelation relations = 2; repeated MemoRelation relations = 2;
...@@ -291,7 +275,6 @@ message SetMemoRelationsRequest { ...@@ -291,7 +275,6 @@ message SetMemoRelationsRequest {
message ListMemoRelationsRequest { message ListMemoRelationsRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
} }
...@@ -301,7 +284,6 @@ message ListMemoRelationsResponse { ...@@ -301,7 +284,6 @@ message ListMemoRelationsResponse {
message CreateMemoCommentRequest { message CreateMemoCommentRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
CreateMemoRequest comment = 2; CreateMemoRequest comment = 2;
...@@ -309,7 +291,6 @@ message CreateMemoCommentRequest { ...@@ -309,7 +291,6 @@ message CreateMemoCommentRequest {
message ListMemoCommentsRequest { message ListMemoCommentsRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
} }
...@@ -319,7 +300,6 @@ message ListMemoCommentsResponse { ...@@ -319,7 +300,6 @@ message ListMemoCommentsResponse {
message ListMemoReactionsRequest { message ListMemoReactionsRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
} }
...@@ -329,7 +309,6 @@ message ListMemoReactionsResponse { ...@@ -329,7 +309,6 @@ message ListMemoReactionsResponse {
message UpsertMemoReactionRequest { message UpsertMemoReactionRequest {
// The name of the memo. // The name of the memo.
// Format: memos/{id}
string name = 1; string name = 1;
Reaction reaction = 2; Reaction reaction = 2;
......
...@@ -56,8 +56,7 @@ service ResourceService { ...@@ -56,8 +56,7 @@ service ResourceService {
message Resource { message Resource {
// The name of the resource. // The name of the resource.
// Format: resources/{id} // Format: resources/{id}, id is the system generated auto-incremented id.
// id is the system generated unique identifier.
string name = 1; string name = 1;
// The user defined id of the resource. // The user defined id of the resource.
...@@ -75,8 +74,7 @@ message Resource { ...@@ -75,8 +74,7 @@ message Resource {
int64 size = 8; int64 size = 8;
// The related memo. // The related memo. Refer to `Memo.name`.
// Format: memos/{id}
optional string memo = 9; optional string memo = 9;
} }
...@@ -92,8 +90,6 @@ message ListResourcesResponse { ...@@ -92,8 +90,6 @@ message ListResourcesResponse {
message GetResourceRequest { message GetResourceRequest {
// The name of the resource. // The name of the resource.
// Format: resources/{id}
// id is the system generated unique identifier.
string name = 1; string name = 1;
} }
...@@ -104,8 +100,6 @@ message GetResourceByUidRequest { ...@@ -104,8 +100,6 @@ message GetResourceByUidRequest {
message GetResourceBinaryRequest { message GetResourceBinaryRequest {
// The name of the resource. // The name of the resource.
// Format: resources/{id}
// id is the system generated unique identifier.
string name = 1; string name = 1;
// The filename of the resource. Mainly used for downloading. // The filename of the resource. Mainly used for downloading.
...@@ -123,7 +117,5 @@ message UpdateResourceRequest { ...@@ -123,7 +117,5 @@ message UpdateResourceRequest {
message DeleteResourceRequest { message DeleteResourceRequest {
// The name of the resource. // The name of the resource.
// Format: resources/{id}
// id is the system generated unique identifier.
string name = 1; string name = 1;
} }
...@@ -97,7 +97,7 @@ service UserService { ...@@ -97,7 +97,7 @@ service UserService {
message User { message User {
// The name of the user. // The name of the user.
// Format: users/{user}. {user} is a system-generated auto-increment id. // Format: users/{id}, id is the system generated auto-incremented id.
string name = 1; string name = 1;
enum Role { enum Role {
...@@ -122,9 +122,9 @@ message User { ...@@ -122,9 +122,9 @@ message User {
State state = 10; State state = 10;
google.protobuf.Timestamp create_time = 11; google.protobuf.Timestamp create_time = 11 [(google.api.field_behavior) = OUTPUT_ONLY];
google.protobuf.Timestamp update_time = 12; google.protobuf.Timestamp update_time = 12 [(google.api.field_behavior) = OUTPUT_ONLY];
} }
message ListUsersRequest {} message ListUsersRequest {}
...@@ -145,13 +145,11 @@ message SearchUsersResponse { ...@@ -145,13 +145,11 @@ message SearchUsersResponse {
message GetUserRequest { message GetUserRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
} }
message GetUserAvatarBinaryRequest { message GetUserAvatarBinaryRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
// The raw HTTP body is bound to this field. // The raw HTTP body is bound to this field.
...@@ -170,13 +168,11 @@ message UpdateUserRequest { ...@@ -170,13 +168,11 @@ message UpdateUserRequest {
message DeleteUserRequest { message DeleteUserRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
} }
message UserStats { message UserStats {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
// The timestamps when the memos were displayed. // The timestamps when the memos were displayed.
...@@ -206,13 +202,11 @@ message ListAllUserStatsResponse { ...@@ -206,13 +202,11 @@ message ListAllUserStatsResponse {
message GetUserStatsRequest { message GetUserStatsRequest {
// The name of the user. // The name of the user.
// Format: users/{user}.
string name = 1; string name = 1;
} }
message UserSetting { message UserSetting {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
// The preferred locale of the user. // The preferred locale of the user.
string locale = 2; string locale = 2;
...@@ -224,7 +218,6 @@ message UserSetting { ...@@ -224,7 +218,6 @@ message UserSetting {
message GetUserSettingRequest { message GetUserSettingRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
} }
...@@ -243,7 +236,6 @@ message UserAccessToken { ...@@ -243,7 +236,6 @@ message UserAccessToken {
message ListUserAccessTokensRequest { message ListUserAccessTokensRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
} }
...@@ -253,7 +245,6 @@ message ListUserAccessTokensResponse { ...@@ -253,7 +245,6 @@ message ListUserAccessTokensResponse {
message CreateUserAccessTokenRequest { message CreateUserAccessTokenRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
string description = 2; string description = 2;
...@@ -263,7 +254,6 @@ message CreateUserAccessTokenRequest { ...@@ -263,7 +254,6 @@ message CreateUserAccessTokenRequest {
message DeleteUserAccessTokenRequest { message DeleteUserAccessTokenRequest {
// The name of the user. // The name of the user.
// Format: users/{user}
string name = 1; string name = 1;
// access_token is the access token to delete. // access_token is the access token to delete.
string access_token = 2; string access_token = 2;
......
...@@ -47,7 +47,6 @@ message Webhook { ...@@ -47,7 +47,6 @@ message Webhook {
int32 id = 1; int32 id = 1;
// The name of the creator. // The name of the creator.
// Format: users/{user}
string creator = 2; string creator = 2;
google.protobuf.Timestamp create_time = 3; google.protobuf.Timestamp create_time = 3;
...@@ -71,7 +70,6 @@ message GetWebhookRequest { ...@@ -71,7 +70,6 @@ message GetWebhookRequest {
message ListWebhooksRequest { message ListWebhooksRequest {
// The name of the creator. // The name of the creator.
// Format: users/{user}
string creator = 2; string creator = 2;
} }
......
...@@ -271,7 +271,7 @@ func (x *ActivityVersionUpdatePayload) GetVersion() string { ...@@ -271,7 +271,7 @@ func (x *ActivityVersionUpdatePayload) GetVersion() string {
type GetActivityRequest struct { type GetActivityRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the activity. // The name of the activity.
// Format: activities/{id} // Format: activities/{id}, id is the system generated auto-incremented id.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
......
...@@ -73,7 +73,7 @@ func (IdentityProvider_Type) EnumDescriptor() ([]byte, []int) { ...@@ -73,7 +73,7 @@ func (IdentityProvider_Type) EnumDescriptor() ([]byte, []int) {
type IdentityProvider struct { type IdentityProvider struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the identityProvider. // The name of the identityProvider.
// Format: identityProviders/{id} // Format: identityProviders/{id}, id is the system generated auto-incremented id.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
Type IdentityProvider_Type `protobuf:"varint,2,opt,name=type,proto3,enum=memos.api.v1.IdentityProvider_Type" json:"type,omitempty"` Type IdentityProvider_Type `protobuf:"varint,2,opt,name=type,proto3,enum=memos.api.v1.IdentityProvider_Type" json:"type,omitempty"`
Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"` Title string `protobuf:"bytes,3,opt,name=title,proto3" json:"title,omitempty"`
...@@ -449,7 +449,6 @@ func (x *ListIdentityProvidersResponse) GetIdentityProviders() []*IdentityProvid ...@@ -449,7 +449,6 @@ func (x *ListIdentityProvidersResponse) GetIdentityProviders() []*IdentityProvid
type GetIdentityProviderRequest struct { type GetIdentityProviderRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the identityProvider to get. // The name of the identityProvider to get.
// Format: identityProviders/{id}
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
...@@ -595,7 +594,6 @@ func (x *UpdateIdentityProviderRequest) GetUpdateMask() *fieldmaskpb.FieldMask { ...@@ -595,7 +594,6 @@ func (x *UpdateIdentityProviderRequest) GetUpdateMask() *fieldmaskpb.FieldMask {
type DeleteIdentityProviderRequest struct { type DeleteIdentityProviderRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the identityProvider to delete. // The name of the identityProvider to delete.
// Format: identityProviders/{id}
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
......
...@@ -126,7 +126,7 @@ func (Inbox_Type) EnumDescriptor() ([]byte, []int) { ...@@ -126,7 +126,7 @@ func (Inbox_Type) EnumDescriptor() ([]byte, []int) {
type Inbox struct { type Inbox struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the inbox. // The name of the inbox.
// Format: inboxes/{id} // Format: inboxes/{id}, id is the system generated auto-incremented id.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// Format: users/{user} // Format: users/{user}
Sender string `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"` Sender string `protobuf:"bytes,2,opt,name=sender,proto3" json:"sender,omitempty"`
...@@ -391,7 +391,6 @@ func (x *UpdateInboxRequest) GetUpdateMask() *fieldmaskpb.FieldMask { ...@@ -391,7 +391,6 @@ func (x *UpdateInboxRequest) GetUpdateMask() *fieldmaskpb.FieldMask {
type DeleteInboxRequest struct { type DeleteInboxRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the inbox to delete. // The name of the inbox to delete.
// Format: inboxes/{id}
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
......
...@@ -74,10 +74,10 @@ func (MemoRelation_Type) EnumDescriptor() ([]byte, []int) { ...@@ -74,10 +74,10 @@ func (MemoRelation_Type) EnumDescriptor() ([]byte, []int) {
type MemoRelation struct { type MemoRelation struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of memo. // The name of memo.
// Format: "memos/{id}" // Format: memos/{id}
Memo *MemoRelation_Memo `protobuf:"bytes,1,opt,name=memo,proto3" json:"memo,omitempty"` Memo *MemoRelation_Memo `protobuf:"bytes,1,opt,name=memo,proto3" json:"memo,omitempty"`
// The name of related memo. // The name of related memo.
// Format: "memos/{id}" // Format: memos/{id}
RelatedMemo *MemoRelation_Memo `protobuf:"bytes,2,opt,name=related_memo,json=relatedMemo,proto3" json:"related_memo,omitempty"` RelatedMemo *MemoRelation_Memo `protobuf:"bytes,2,opt,name=related_memo,json=relatedMemo,proto3" json:"related_memo,omitempty"`
Type MemoRelation_Type `protobuf:"varint,3,opt,name=type,proto3,enum=memos.api.v1.MemoRelation_Type" json:"type,omitempty"` Type MemoRelation_Type `protobuf:"varint,3,opt,name=type,proto3,enum=memos.api.v1.MemoRelation_Type" json:"type,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
......
This source diff could not be displayed because it is too large. You can view the blob instead.
...@@ -127,42 +127,6 @@ func local_request_MemoService_GetMemo_0(ctx context.Context, marshaler runtime. ...@@ -127,42 +127,6 @@ func local_request_MemoService_GetMemo_0(ctx context.Context, marshaler runtime.
return msg, metadata, err return msg, metadata, err
} }
func request_MemoService_GetMemoByUid_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq GetMemoByUidRequest
metadata runtime.ServerMetadata
err error
)
val, ok := pathParams["uid"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "uid")
}
protoReq.Uid, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err)
}
msg, err := client.GetMemoByUid(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err
}
func local_request_MemoService_GetMemoByUid_0(ctx context.Context, marshaler runtime.Marshaler, server MemoServiceServer, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
var (
protoReq GetMemoByUidRequest
metadata runtime.ServerMetadata
err error
)
val, ok := pathParams["uid"]
if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "uid")
}
protoReq.Uid, err = runtime.String(val)
if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "uid", err)
}
msg, err := server.GetMemoByUid(ctx, &protoReq)
return msg, metadata, err
}
var filter_MemoService_UpdateMemo_0 = &utilities.DoubleArray{Encoding: map[string]int{"memo": 0, "name": 1}, Base: []int{1, 2, 1, 0, 0}, Check: []int{0, 1, 2, 3, 2}} var filter_MemoService_UpdateMemo_0 = &utilities.DoubleArray{Encoding: map[string]int{"memo": 0, "name": 1}, Base: []int{1, 2, 1, 0, 0}, Check: []int{0, 1, 2, 3, 2}}
func request_MemoService_UpdateMemo_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) { func request_MemoService_UpdateMemo_0(ctx context.Context, marshaler runtime.Marshaler, client MemoServiceClient, req *http.Request, pathParams map[string]string) (proto.Message, runtime.ServerMetadata, error) {
...@@ -799,26 +763,6 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux ...@@ -799,26 +763,6 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
} }
forward_MemoService_GetMemo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) forward_MemoService_GetMemo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
}) })
mux.Handle(http.MethodGet, pattern_MemoService_GetMemoByUid_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)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/GetMemoByUid", runtime.WithHTTPPathPattern("/api/v1/memos:by-uid/{uid}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := local_request_MemoService_GetMemoByUid_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_GetMemoByUid_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPatch, pattern_MemoService_UpdateMemo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle(http.MethodPatch, pattern_MemoService_UpdateMemo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
...@@ -1170,23 +1114,6 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux ...@@ -1170,23 +1114,6 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
} }
forward_MemoService_GetMemo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...) forward_MemoService_GetMemo_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
}) })
mux.Handle(http.MethodGet, pattern_MemoService_GetMemoByUid_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)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/GetMemoByUid", runtime.WithHTTPPathPattern("/api/v1/memos:by-uid/{uid}"))
if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return
}
resp, md, err := request_MemoService_GetMemoByUid_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_GetMemoByUid_0(annotatedContext, mux, outboundMarshaler, w, req, resp, mux.GetForwardResponseOptions()...)
})
mux.Handle(http.MethodPatch, pattern_MemoService_UpdateMemo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) { mux.Handle(http.MethodPatch, pattern_MemoService_UpdateMemo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
...@@ -1415,7 +1342,6 @@ var ( ...@@ -1415,7 +1342,6 @@ var (
pattern_MemoService_CreateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "")) pattern_MemoService_CreateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, ""))
pattern_MemoService_ListMemos_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, "")) pattern_MemoService_ListMemos_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2}, []string{"api", "v1", "memos"}, ""))
pattern_MemoService_GetMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "")) pattern_MemoService_GetMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, ""))
pattern_MemoService_GetMemoByUid_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "memos:by-uid", "uid"}, ""))
pattern_MemoService_UpdateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "memo.name"}, "")) pattern_MemoService_UpdateMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "memo.name"}, ""))
pattern_MemoService_DeleteMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, "")) pattern_MemoService_DeleteMemo_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3}, []string{"api", "v1", "memos", "name"}, ""))
pattern_MemoService_RenameMemoTag_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"}, "rename")) pattern_MemoService_RenameMemoTag_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"}, "rename"))
...@@ -1435,7 +1361,6 @@ var ( ...@@ -1435,7 +1361,6 @@ var (
forward_MemoService_CreateMemo_0 = runtime.ForwardResponseMessage forward_MemoService_CreateMemo_0 = runtime.ForwardResponseMessage
forward_MemoService_ListMemos_0 = runtime.ForwardResponseMessage forward_MemoService_ListMemos_0 = runtime.ForwardResponseMessage
forward_MemoService_GetMemo_0 = runtime.ForwardResponseMessage forward_MemoService_GetMemo_0 = runtime.ForwardResponseMessage
forward_MemoService_GetMemoByUid_0 = runtime.ForwardResponseMessage
forward_MemoService_UpdateMemo_0 = runtime.ForwardResponseMessage forward_MemoService_UpdateMemo_0 = runtime.ForwardResponseMessage
forward_MemoService_DeleteMemo_0 = runtime.ForwardResponseMessage forward_MemoService_DeleteMemo_0 = runtime.ForwardResponseMessage
forward_MemoService_RenameMemoTag_0 = runtime.ForwardResponseMessage forward_MemoService_RenameMemoTag_0 = runtime.ForwardResponseMessage
......
...@@ -23,7 +23,6 @@ const ( ...@@ -23,7 +23,6 @@ const (
MemoService_CreateMemo_FullMethodName = "/memos.api.v1.MemoService/CreateMemo" MemoService_CreateMemo_FullMethodName = "/memos.api.v1.MemoService/CreateMemo"
MemoService_ListMemos_FullMethodName = "/memos.api.v1.MemoService/ListMemos" MemoService_ListMemos_FullMethodName = "/memos.api.v1.MemoService/ListMemos"
MemoService_GetMemo_FullMethodName = "/memos.api.v1.MemoService/GetMemo" MemoService_GetMemo_FullMethodName = "/memos.api.v1.MemoService/GetMemo"
MemoService_GetMemoByUid_FullMethodName = "/memos.api.v1.MemoService/GetMemoByUid"
MemoService_UpdateMemo_FullMethodName = "/memos.api.v1.MemoService/UpdateMemo" MemoService_UpdateMemo_FullMethodName = "/memos.api.v1.MemoService/UpdateMemo"
MemoService_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo" MemoService_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo"
MemoService_RenameMemoTag_FullMethodName = "/memos.api.v1.MemoService/RenameMemoTag" MemoService_RenameMemoTag_FullMethodName = "/memos.api.v1.MemoService/RenameMemoTag"
...@@ -49,8 +48,6 @@ type MemoServiceClient interface { ...@@ -49,8 +48,6 @@ type MemoServiceClient interface {
ListMemos(ctx context.Context, in *ListMemosRequest, opts ...grpc.CallOption) (*ListMemosResponse, error) ListMemos(ctx context.Context, in *ListMemosRequest, opts ...grpc.CallOption) (*ListMemosResponse, error)
// GetMemo gets a memo. // GetMemo gets a memo.
GetMemo(ctx context.Context, in *GetMemoRequest, opts ...grpc.CallOption) (*Memo, error) GetMemo(ctx context.Context, in *GetMemoRequest, opts ...grpc.CallOption) (*Memo, error)
// GetMemoByUid gets a memo by uid
GetMemoByUid(ctx context.Context, in *GetMemoByUidRequest, opts ...grpc.CallOption) (*Memo, error)
// UpdateMemo updates a memo. // UpdateMemo updates a memo.
UpdateMemo(ctx context.Context, in *UpdateMemoRequest, opts ...grpc.CallOption) (*Memo, error) UpdateMemo(ctx context.Context, in *UpdateMemoRequest, opts ...grpc.CallOption) (*Memo, error)
// DeleteMemo deletes a memo. // DeleteMemo deletes a memo.
...@@ -117,16 +114,6 @@ func (c *memoServiceClient) GetMemo(ctx context.Context, in *GetMemoRequest, opt ...@@ -117,16 +114,6 @@ func (c *memoServiceClient) GetMemo(ctx context.Context, in *GetMemoRequest, opt
return out, nil return out, nil
} }
func (c *memoServiceClient) GetMemoByUid(ctx context.Context, in *GetMemoByUidRequest, opts ...grpc.CallOption) (*Memo, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Memo)
err := c.cc.Invoke(ctx, MemoService_GetMemoByUid_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
}
return out, nil
}
func (c *memoServiceClient) UpdateMemo(ctx context.Context, in *UpdateMemoRequest, opts ...grpc.CallOption) (*Memo, error) { func (c *memoServiceClient) UpdateMemo(ctx context.Context, in *UpdateMemoRequest, opts ...grpc.CallOption) (*Memo, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Memo) out := new(Memo)
...@@ -267,8 +254,6 @@ type MemoServiceServer interface { ...@@ -267,8 +254,6 @@ type MemoServiceServer interface {
ListMemos(context.Context, *ListMemosRequest) (*ListMemosResponse, error) ListMemos(context.Context, *ListMemosRequest) (*ListMemosResponse, error)
// GetMemo gets a memo. // GetMemo gets a memo.
GetMemo(context.Context, *GetMemoRequest) (*Memo, error) GetMemo(context.Context, *GetMemoRequest) (*Memo, error)
// GetMemoByUid gets a memo by uid
GetMemoByUid(context.Context, *GetMemoByUidRequest) (*Memo, error)
// UpdateMemo updates a memo. // UpdateMemo updates a memo.
UpdateMemo(context.Context, *UpdateMemoRequest) (*Memo, error) UpdateMemo(context.Context, *UpdateMemoRequest) (*Memo, error)
// DeleteMemo deletes a memo. // DeleteMemo deletes a memo.
...@@ -314,9 +299,6 @@ func (UnimplementedMemoServiceServer) ListMemos(context.Context, *ListMemosReque ...@@ -314,9 +299,6 @@ func (UnimplementedMemoServiceServer) ListMemos(context.Context, *ListMemosReque
func (UnimplementedMemoServiceServer) GetMemo(context.Context, *GetMemoRequest) (*Memo, error) { func (UnimplementedMemoServiceServer) GetMemo(context.Context, *GetMemoRequest) (*Memo, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMemo not implemented") return nil, status.Errorf(codes.Unimplemented, "method GetMemo not implemented")
} }
func (UnimplementedMemoServiceServer) GetMemoByUid(context.Context, *GetMemoByUidRequest) (*Memo, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetMemoByUid not implemented")
}
func (UnimplementedMemoServiceServer) UpdateMemo(context.Context, *UpdateMemoRequest) (*Memo, error) { func (UnimplementedMemoServiceServer) UpdateMemo(context.Context, *UpdateMemoRequest) (*Memo, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateMemo not implemented") return nil, status.Errorf(codes.Unimplemented, "method UpdateMemo not implemented")
} }
...@@ -431,24 +413,6 @@ func _MemoService_GetMemo_Handler(srv interface{}, ctx context.Context, dec func ...@@ -431,24 +413,6 @@ func _MemoService_GetMemo_Handler(srv interface{}, ctx context.Context, dec func
return interceptor(ctx, in, info, handler) return interceptor(ctx, in, info, handler)
} }
func _MemoService_GetMemoByUid_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(GetMemoByUidRequest)
if err := dec(in); err != nil {
return nil, err
}
if interceptor == nil {
return srv.(MemoServiceServer).GetMemoByUid(ctx, in)
}
info := &grpc.UnaryServerInfo{
Server: srv,
FullMethod: MemoService_GetMemoByUid_FullMethodName,
}
handler := func(ctx context.Context, req interface{}) (interface{}, error) {
return srv.(MemoServiceServer).GetMemoByUid(ctx, req.(*GetMemoByUidRequest))
}
return interceptor(ctx, in, info, handler)
}
func _MemoService_UpdateMemo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { func _MemoService_UpdateMemo_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) {
in := new(UpdateMemoRequest) in := new(UpdateMemoRequest)
if err := dec(in); err != nil { if err := dec(in); err != nil {
...@@ -702,10 +666,6 @@ var MemoService_ServiceDesc = grpc.ServiceDesc{ ...@@ -702,10 +666,6 @@ var MemoService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetMemo", MethodName: "GetMemo",
Handler: _MemoService_GetMemo_Handler, Handler: _MemoService_GetMemo_Handler,
}, },
{
MethodName: "GetMemoByUid",
Handler: _MemoService_GetMemoByUid_Handler,
},
{ {
MethodName: "UpdateMemo", MethodName: "UpdateMemo",
Handler: _MemoService_UpdateMemo_Handler, Handler: _MemoService_UpdateMemo_Handler,
......
...@@ -29,8 +29,7 @@ const ( ...@@ -29,8 +29,7 @@ const (
type Resource struct { type Resource struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the resource. // The name of the resource.
// Format: resources/{id} // Format: resources/{id}, id is the system generated auto-incremented id.
// id is the system generated unique identifier.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The user defined id of the resource. // The user defined id of the resource.
Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"` Uid string `protobuf:"bytes,2,opt,name=uid,proto3" json:"uid,omitempty"`
...@@ -40,8 +39,7 @@ type Resource struct { ...@@ -40,8 +39,7 @@ type Resource struct {
ExternalLink string `protobuf:"bytes,6,opt,name=external_link,json=externalLink,proto3" json:"external_link,omitempty"` ExternalLink string `protobuf:"bytes,6,opt,name=external_link,json=externalLink,proto3" json:"external_link,omitempty"`
Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"` Type string `protobuf:"bytes,7,opt,name=type,proto3" json:"type,omitempty"`
Size int64 `protobuf:"varint,8,opt,name=size,proto3" json:"size,omitempty"` Size int64 `protobuf:"varint,8,opt,name=size,proto3" json:"size,omitempty"`
// The related memo. // The related memo. Refer to `Memo.name`.
// Format: memos/{id}
Memo *string `protobuf:"bytes,9,opt,name=memo,proto3,oneof" json:"memo,omitempty"` Memo *string `protobuf:"bytes,9,opt,name=memo,proto3,oneof" json:"memo,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
...@@ -267,8 +265,6 @@ func (x *ListResourcesResponse) GetResources() []*Resource { ...@@ -267,8 +265,6 @@ func (x *ListResourcesResponse) GetResources() []*Resource {
type GetResourceRequest struct { type GetResourceRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the resource. // The name of the resource.
// Format: resources/{id}
// id is the system generated unique identifier.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
...@@ -359,8 +355,6 @@ func (x *GetResourceByUidRequest) GetUid() string { ...@@ -359,8 +355,6 @@ func (x *GetResourceByUidRequest) GetUid() string {
type GetResourceBinaryRequest struct { type GetResourceBinaryRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the resource. // The name of the resource.
// Format: resources/{id}
// id is the system generated unique identifier.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
// The filename of the resource. Mainly used for downloading. // The filename of the resource. Mainly used for downloading.
Filename string `protobuf:"bytes,2,opt,name=filename,proto3" json:"filename,omitempty"` Filename string `protobuf:"bytes,2,opt,name=filename,proto3" json:"filename,omitempty"`
...@@ -476,8 +470,6 @@ func (x *UpdateResourceRequest) GetUpdateMask() *fieldmaskpb.FieldMask { ...@@ -476,8 +470,6 @@ func (x *UpdateResourceRequest) GetUpdateMask() *fieldmaskpb.FieldMask {
type DeleteResourceRequest struct { type DeleteResourceRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the resource. // The name of the resource.
// Format: resources/{id}
// id is the system generated unique identifier.
Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
......
This diff is collapsed.
...@@ -29,7 +29,6 @@ type Webhook struct { ...@@ -29,7 +29,6 @@ type Webhook struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"` Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
// The name of the creator. // The name of the creator.
// Format: users/{user}
Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"` Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"`
CreateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"` CreateTime *timestamppb.Timestamp `protobuf:"bytes,3,opt,name=create_time,json=createTime,proto3" json:"create_time,omitempty"`
UpdateTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty"` UpdateTime *timestamppb.Timestamp `protobuf:"bytes,4,opt,name=update_time,json=updateTime,proto3" json:"update_time,omitempty"`
...@@ -210,7 +209,6 @@ func (x *GetWebhookRequest) GetId() int32 { ...@@ -210,7 +209,6 @@ func (x *GetWebhookRequest) GetId() int32 {
type ListWebhooksRequest struct { type ListWebhooksRequest struct {
state protoimpl.MessageState `protogen:"open.v1"` state protoimpl.MessageState `protogen:"open.v1"`
// The name of the creator. // The name of the creator.
// Format: users/{user}
Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"` Creator string `protobuf:"bytes,2,opt,name=creator,proto3" json:"creator,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
sizeCache protoimpl.SizeCache sizeCache protoimpl.SizeCache
......
This diff is collapsed.
...@@ -33,23 +33,41 @@ func (s *APIV1Service) GetActivity(ctx context.Context, request *v1pb.GetActivit ...@@ -33,23 +33,41 @@ func (s *APIV1Service) GetActivity(ctx context.Context, request *v1pb.GetActivit
return activityMessage, nil return activityMessage, nil
} }
func (*APIV1Service) convertActivityFromStore(_ context.Context, activity *store.Activity) (*v1pb.Activity, error) { func (s *APIV1Service) convertActivityFromStore(ctx context.Context, activity *store.Activity) (*v1pb.Activity, error) {
payload, err := s.convertActivityPayloadFromStore(ctx, activity.Payload)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert activity payload from store: %v", err)
}
return &v1pb.Activity{ return &v1pb.Activity{
Name: fmt.Sprintf("%s%d", ActivityNamePrefix, activity.ID), Name: fmt.Sprintf("%s%d", ActivityNamePrefix, activity.ID),
Creator: fmt.Sprintf("%s%d", UserNamePrefix, activity.CreatorID), Creator: fmt.Sprintf("%s%d", UserNamePrefix, activity.CreatorID),
Type: activity.Type.String(), Type: activity.Type.String(),
Level: activity.Level.String(), Level: activity.Level.String(),
CreateTime: timestamppb.New(time.Unix(activity.CreatedTs, 0)), CreateTime: timestamppb.New(time.Unix(activity.CreatedTs, 0)),
Payload: convertActivityPayloadFromStore(activity.Payload), Payload: payload,
}, nil }, nil
} }
func convertActivityPayloadFromStore(payload *storepb.ActivityPayload) *v1pb.ActivityPayload { func (s *APIV1Service) convertActivityPayloadFromStore(ctx context.Context, payload *storepb.ActivityPayload) (*v1pb.ActivityPayload, error) {
v2Payload := &v1pb.ActivityPayload{} v2Payload := &v1pb.ActivityPayload{}
if payload.MemoComment != nil { if payload.MemoComment != nil {
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
ID: &payload.MemoComment.MemoId,
ExcludeContent: true,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo: %v", err)
}
relatedMemo, err := s.Store.GetMemo(ctx, &store.FindMemo{
ID: &payload.MemoComment.RelatedMemoId,
ExcludeContent: true,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get related memo: %v", err)
}
v2Payload.MemoComment = &v1pb.ActivityMemoCommentPayload{ v2Payload.MemoComment = &v1pb.ActivityMemoCommentPayload{
Memo: fmt.Sprintf("%s%d", MemoNamePrefix, payload.MemoComment.MemoId), Memo: fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID),
RelatedMemo: fmt.Sprintf("%s%d", MemoNamePrefix, payload.MemoComment.RelatedMemoId), RelatedMemo: fmt.Sprintf("%s%s", MemoNamePrefix, relatedMemo.UID),
} }
} }
if payload.VersionUpdate != nil { if payload.VersionUpdate != nil {
...@@ -57,5 +75,5 @@ func convertActivityPayloadFromStore(payload *storepb.ActivityPayload) *v1pb.Act ...@@ -57,5 +75,5 @@ func convertActivityPayloadFromStore(payload *storepb.ActivityPayload) *v1pb.Act
Version: payload.VersionUpdate.Version, Version: payload.VersionUpdate.Version,
} }
} }
return v2Payload return v2Payload, nil
} }
...@@ -14,14 +14,18 @@ import ( ...@@ -14,14 +14,18 @@ import (
) )
func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMemoRelationsRequest) (*emptypb.Empty, error) { func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMemoRelationsRequest) (*emptypb.Empty, error) {
id, err := ExtractMemoIDFromName(request.Name) memoID, err := ExtractMemoIDFromName(request.Name)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &memoID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo")
}
referenceType := store.MemoRelationReference referenceType := store.MemoRelationReference
// Delete all reference relations first. // Delete all reference relations first.
if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{ if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{
MemoID: &id, MemoID: &memo.ID,
Type: &referenceType, Type: &referenceType,
}); err != nil { }); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete memo relation") return nil, status.Errorf(codes.Internal, "failed to delete memo relation")
...@@ -41,9 +45,13 @@ func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMe ...@@ -41,9 +45,13 @@ func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMe
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid related memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid related memo name: %v", err)
} }
relatedMemo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &relatedMemoID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get related memo")
}
if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelation{ if _, err := s.Store.UpsertMemoRelation(ctx, &store.MemoRelation{
MemoID: id, MemoID: memo.ID,
RelatedMemoID: relatedMemoID, RelatedMemoID: relatedMemo.ID,
Type: convertMemoRelationTypeToStore(relation.Type), Type: convertMemoRelationTypeToStore(relation.Type),
}); err != nil { }); err != nil {
return nil, status.Errorf(codes.Internal, "failed to upsert memo relation") return nil, status.Errorf(codes.Internal, "failed to upsert memo relation")
...@@ -54,13 +62,17 @@ func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMe ...@@ -54,13 +62,17 @@ func (s *APIV1Service) SetMemoRelations(ctx context.Context, request *v1pb.SetMe
} }
func (s *APIV1Service) ListMemoRelations(ctx context.Context, request *v1pb.ListMemoRelationsRequest) (*v1pb.ListMemoRelationsResponse, error) { func (s *APIV1Service) ListMemoRelations(ctx context.Context, request *v1pb.ListMemoRelationsRequest) (*v1pb.ListMemoRelationsResponse, error) {
id, err := ExtractMemoIDFromName(request.Name) memoID, err := ExtractMemoIDFromName(request.Name)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &memoID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo")
}
relationList := []*v1pb.MemoRelation{} relationList := []*v1pb.MemoRelation{}
tempList, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{ tempList, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{
MemoID: &id, MemoID: &memo.ID,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -73,7 +85,7 @@ func (s *APIV1Service) ListMemoRelations(ctx context.Context, request *v1pb.List ...@@ -73,7 +85,7 @@ func (s *APIV1Service) ListMemoRelations(ctx context.Context, request *v1pb.List
relationList = append(relationList, relation) relationList = append(relationList, relation)
} }
tempList, err = s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{ tempList, err = s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{
RelatedMemoID: &id, RelatedMemoID: &memo.ID,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -111,12 +123,12 @@ func (s *APIV1Service) convertMemoRelationFromStore(ctx context.Context, memoRel ...@@ -111,12 +123,12 @@ func (s *APIV1Service) convertMemoRelationFromStore(ctx context.Context, memoRel
} }
return &v1pb.MemoRelation{ return &v1pb.MemoRelation{
Memo: &v1pb.MemoRelation_Memo{ Memo: &v1pb.MemoRelation_Memo{
Name: fmt.Sprintf("%s%d", MemoNamePrefix, memo.ID), Name: fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID),
Uid: memo.UID, Uid: memo.UID,
Snippet: memoSnippet, Snippet: memoSnippet,
}, },
RelatedMemo: &v1pb.MemoRelation_Memo{ RelatedMemo: &v1pb.MemoRelation_Memo{
Name: fmt.Sprintf("%s%d", MemoNamePrefix, relatedMemo.ID), Name: fmt.Sprintf("%s%s", MemoNamePrefix, relatedMemo.UID),
Uid: relatedMemo.UID, Uid: relatedMemo.UID,
Snippet: relatedMemoSnippet, Snippet: relatedMemoSnippet,
}, },
......
...@@ -18,8 +18,12 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe ...@@ -18,8 +18,12 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &memoID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo")
}
resources, err := s.Store.ListResources(ctx, &store.FindResource{ resources, err := s.Store.ListResources(ctx, &store.FindResource{
MemoID: &memoID, MemoID: &memo.ID,
}) })
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list resources") return nil, status.Errorf(codes.Internal, "failed to list resources")
...@@ -37,7 +41,7 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe ...@@ -37,7 +41,7 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe
if !found { if !found {
if err = s.Store.DeleteResource(ctx, &store.DeleteResource{ if err = s.Store.DeleteResource(ctx, &store.DeleteResource{
ID: int32(resource.ID), ID: int32(resource.ID),
MemoID: &memoID, MemoID: &memo.ID,
}); err != nil { }); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete resource") return nil, status.Errorf(codes.Internal, "failed to delete resource")
} }
...@@ -54,7 +58,7 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe ...@@ -54,7 +58,7 @@ func (s *APIV1Service) SetMemoResources(ctx context.Context, request *v1pb.SetMe
updatedTs := time.Now().Unix() + int64(index) updatedTs := time.Now().Unix() + int64(index)
if err := s.Store.UpdateResource(ctx, &store.UpdateResource{ if err := s.Store.UpdateResource(ctx, &store.UpdateResource{
ID: id, ID: id,
MemoID: &memoID, MemoID: &memo.ID,
UpdatedTs: &updatedTs, UpdatedTs: &updatedTs,
}); err != nil { }); err != nil {
return nil, status.Errorf(codes.Internal, "failed to update resource: %v", err) return nil, status.Errorf(codes.Internal, "failed to update resource: %v", err)
...@@ -69,8 +73,12 @@ func (s *APIV1Service) ListMemoResources(ctx context.Context, request *v1pb.List ...@@ -69,8 +73,12 @@ func (s *APIV1Service) ListMemoResources(ctx context.Context, request *v1pb.List
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &id})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo: %v", err)
}
resources, err := s.Store.ListResources(ctx, &store.FindResource{ resources, err := s.Store.ListResources(ctx, &store.FindResource{
MemoID: &id, MemoID: &memo.ID,
}) })
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list resources: %v", err) return nil, status.Errorf(codes.Internal, "failed to list resources: %v", err)
......
...@@ -65,7 +65,7 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR ...@@ -65,7 +65,7 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR
} }
if len(request.Resources) > 0 { if len(request.Resources) > 0 {
_, err := s.SetMemoResources(ctx, &v1pb.SetMemoResourcesRequest{ _, err := s.SetMemoResources(ctx, &v1pb.SetMemoResourcesRequest{
Name: fmt.Sprintf("%s%d", MemoNamePrefix, memo.ID), Name: fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID),
Resources: request.Resources, Resources: request.Resources,
}) })
if err != nil { if err != nil {
...@@ -74,7 +74,7 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR ...@@ -74,7 +74,7 @@ func (s *APIV1Service) CreateMemo(ctx context.Context, request *v1pb.CreateMemoR
} }
if len(request.Relations) > 0 { if len(request.Relations) > 0 {
_, err := s.SetMemoRelations(ctx, &v1pb.SetMemoRelationsRequest{ _, err := s.SetMemoRelations(ctx, &v1pb.SetMemoRelationsRequest{
Name: fmt.Sprintf("%s%d", MemoNamePrefix, memo.ID), Name: fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID),
Relations: request.Relations, Relations: request.Relations,
}) })
if err != nil { if err != nil {
...@@ -155,38 +155,7 @@ func (s *APIV1Service) GetMemo(ctx context.Context, request *v1pb.GetMemoRequest ...@@ -155,38 +155,7 @@ func (s *APIV1Service) GetMemo(ctx context.Context, request *v1pb.GetMemoRequest
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{ memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
ID: &id, UID: &id,
})
if err != nil {
return nil, err
}
if memo == nil {
return nil, status.Errorf(codes.NotFound, "memo not found")
}
if memo.Visibility != store.Public {
user, err := s.GetCurrentUser(ctx)
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get user")
}
if user == nil {
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
if memo.Visibility == store.Private && memo.CreatorID != user.ID {
return nil, status.Errorf(codes.PermissionDenied, "permission denied")
}
}
memoMessage, err := s.convertMemoFromStore(ctx, memo)
if err != nil {
return nil, errors.Wrap(err, "failed to convert memo")
}
return memoMessage, nil
}
//nolint:all
func (s *APIV1Service) GetMemoByUid(ctx context.Context, request *v1pb.GetMemoByUidRequest) (*v1pb.Memo, error) {
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
UID: &request.Uid,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -223,7 +192,7 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR ...@@ -223,7 +192,7 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
return nil, status.Errorf(codes.InvalidArgument, "update mask is required") return nil, status.Errorf(codes.InvalidArgument, "update mask is required")
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{ID: &id}) memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &id})
if err != nil { if err != nil {
return nil, err return nil, err
} }
...@@ -241,7 +210,7 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR ...@@ -241,7 +210,7 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
} }
update := &store.UpdateMemo{ update := &store.UpdateMemo{
ID: id, ID: memo.ID,
} }
for _, path := range request.UpdateMask.Paths { for _, path := range request.UpdateMask.Paths {
if path == "content" { if path == "content" {
...@@ -293,6 +262,10 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR ...@@ -293,6 +262,10 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
} else { } else {
update.CreatedTs = &displayTs update.CreatedTs = &displayTs
} }
} else if path == "location" {
payload := memo.Payload
payload.Location = convertLocationToStore(request.Memo.Location)
update.Payload = payload
} else if path == "resources" { } else if path == "resources" {
_, err := s.SetMemoResources(ctx, &v1pb.SetMemoResourcesRequest{ _, err := s.SetMemoResources(ctx, &v1pb.SetMemoResourcesRequest{
Name: request.Memo.Name, Name: request.Memo.Name,
...@@ -309,10 +282,6 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR ...@@ -309,10 +282,6 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to set memo relations") return nil, errors.Wrap(err, "failed to set memo relations")
} }
} else if path == "location" {
payload := memo.Payload
payload.Location = convertLocationToStore(request.Memo.Location)
update.Payload = payload
} }
} }
...@@ -321,7 +290,7 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR ...@@ -321,7 +290,7 @@ func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoR
} }
memo, err = s.Store.GetMemo(ctx, &store.FindMemo{ memo, err = s.Store.GetMemo(ctx, &store.FindMemo{
ID: &id, ID: &memo.ID,
}) })
if err != nil { if err != nil {
return nil, errors.Wrap(err, "failed to get memo") return nil, errors.Wrap(err, "failed to get memo")
...@@ -344,7 +313,7 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR ...@@ -344,7 +313,7 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{ memo, err := s.Store.GetMemo(ctx, &store.FindMemo{
ID: &id, UID: &id,
}) })
if err != nil { if err != nil {
return nil, err return nil, err
...@@ -369,17 +338,17 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR ...@@ -369,17 +338,17 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR
} }
} }
if err = s.Store.DeleteMemo(ctx, &store.DeleteMemo{ID: id}); err != nil { if err = s.Store.DeleteMemo(ctx, &store.DeleteMemo{ID: memo.ID}); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete memo") return nil, status.Errorf(codes.Internal, "failed to delete memo")
} }
// Delete memo relation // Delete memo relation
if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{MemoID: &id}); err != nil { if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{MemoID: &memo.ID}); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete memo relations") return nil, status.Errorf(codes.Internal, "failed to delete memo relations")
} }
// Delete related resources. // Delete related resources.
resources, err := s.Store.ListResources(ctx, &store.FindResource{MemoID: &id}) resources, err := s.Store.ListResources(ctx, &store.FindResource{MemoID: &memo.ID})
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list resources") return nil, status.Errorf(codes.Internal, "failed to list resources")
} }
...@@ -391,19 +360,19 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR ...@@ -391,19 +360,19 @@ func (s *APIV1Service) DeleteMemo(ctx context.Context, request *v1pb.DeleteMemoR
// Delete memo comments // Delete memo comments
commentType := store.MemoRelationComment commentType := store.MemoRelationComment
relations, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{RelatedMemoID: &id, Type: &commentType}) relations, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{RelatedMemoID: &memo.ID, Type: &commentType})
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list memo comments") return nil, status.Errorf(codes.Internal, "failed to list memo comments")
} }
for _, relation := range relations { for _, relation := range relations {
if _, err := s.DeleteMemo(ctx, &v1pb.DeleteMemoRequest{Name: fmt.Sprintf("%s%d", MemoNamePrefix, relation.MemoID)}); err != nil { if err := s.Store.DeleteMemo(ctx, &store.DeleteMemo{ID: relation.MemoID}); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete memo comment") return nil, status.Errorf(codes.Internal, "failed to delete memo comment")
} }
} }
// Delete memo references // Delete memo references
referenceType := store.MemoRelationReference referenceType := store.MemoRelationReference
if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{RelatedMemoID: &id, Type: &referenceType}); err != nil { if err := s.Store.DeleteMemoRelation(ctx, &store.DeleteMemoRelation{RelatedMemoID: &memo.ID, Type: &referenceType}); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete memo references") return nil, status.Errorf(codes.Internal, "failed to delete memo references")
} }
...@@ -415,7 +384,7 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea ...@@ -415,7 +384,7 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
relatedMemo, err := s.Store.GetMemo(ctx, &store.FindMemo{ID: &id}) relatedMemo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &id})
if err != nil { if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo") return nil, status.Errorf(codes.Internal, "failed to get memo")
} }
...@@ -427,12 +396,8 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea ...@@ -427,12 +396,8 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea
} }
// Build the relation between the comment memo and the original memo. // Build the relation between the comment memo and the original memo.
memoID, err := ExtractMemoIDFromName(memo.Name)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
}
_, err = s.Store.UpsertMemoRelation(ctx, &store.MemoRelation{ _, err = s.Store.UpsertMemoRelation(ctx, &store.MemoRelation{
MemoID: memoID, MemoID: memo.Uid,
RelatedMemoID: relatedMemo.ID, RelatedMemoID: relatedMemo.ID,
Type: store.MemoRelationComment, Type: store.MemoRelationComment,
}) })
...@@ -450,7 +415,7 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea ...@@ -450,7 +415,7 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea
Level: store.ActivityLevelInfo, Level: store.ActivityLevelInfo,
Payload: &storepb.ActivityPayload{ Payload: &storepb.ActivityPayload{
MemoComment: &storepb.ActivityMemoCommentPayload{ MemoComment: &storepb.ActivityMemoCommentPayload{
MemoId: memoID, MemoId: memo.Uid,
RelatedMemoId: relatedMemo.ID, RelatedMemoId: relatedMemo.ID,
}, },
}, },
...@@ -475,13 +440,17 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea ...@@ -475,13 +440,17 @@ func (s *APIV1Service) CreateMemoComment(ctx context.Context, request *v1pb.Crea
} }
func (s *APIV1Service) ListMemoComments(ctx context.Context, request *v1pb.ListMemoCommentsRequest) (*v1pb.ListMemoCommentsResponse, error) { func (s *APIV1Service) ListMemoComments(ctx context.Context, request *v1pb.ListMemoCommentsRequest) (*v1pb.ListMemoCommentsResponse, error) {
id, err := ExtractMemoIDFromName(request.Name) memoID, err := ExtractMemoIDFromName(request.Name)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &memoID})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to get memo")
}
memoRelationComment := store.MemoRelationComment memoRelationComment := store.MemoRelationComment
memoRelations, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{ memoRelations, err := s.Store.ListMemoRelations(ctx, &store.FindMemoRelation{
RelatedMemoID: &id, RelatedMemoID: &memo.ID,
Type: &memoRelationComment, Type: &memoRelationComment,
}) })
if err != nil { if err != nil {
...@@ -527,7 +496,7 @@ func (s *APIV1Service) RenameMemoTag(ctx context.Context, request *v1pb.RenameMe ...@@ -527,7 +496,7 @@ func (s *APIV1Service) RenameMemoTag(ctx context.Context, request *v1pb.RenameMe
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memoFind.ID = &memoID memoFind.UID = &memoID
} }
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
...@@ -578,7 +547,7 @@ func (s *APIV1Service) DeleteMemoTag(ctx context.Context, request *v1pb.DeleteMe ...@@ -578,7 +547,7 @@ func (s *APIV1Service) DeleteMemoTag(ctx context.Context, request *v1pb.DeleteMe
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
memoFind.ID = &memoID memoFind.UID = &memoID
} }
memos, err := s.Store.ListMemos(ctx, memoFind) memos, err := s.Store.ListMemos(ctx, memoFind)
......
...@@ -26,10 +26,10 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem ...@@ -26,10 +26,10 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
displayTs = memo.UpdatedTs displayTs = memo.UpdatedTs
} }
name := fmt.Sprintf("%s%d", MemoNamePrefix, memo.ID) name := fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID)
memoMessage := &v1pb.Memo{ memoMessage := &v1pb.Memo{
Name: name, Name: name,
Uid: memo.UID, Uid: memo.ID,
State: convertStateFromStore(memo.RowStatus), State: convertStateFromStore(memo.RowStatus),
Creator: fmt.Sprintf("%s%d", UserNamePrefix, memo.CreatorID), Creator: fmt.Sprintf("%s%d", UserNamePrefix, memo.CreatorID),
CreateTime: timestamppb.New(time.Unix(memo.CreatedTs, 0)), CreateTime: timestamppb.New(time.Unix(memo.CreatedTs, 0)),
...@@ -45,8 +45,15 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem ...@@ -45,8 +45,15 @@ func (s *APIV1Service) convertMemoFromStore(ctx context.Context, memo *store.Mem
memoMessage.Location = convertLocationFromStore(memo.Payload.Location) memoMessage.Location = convertLocationFromStore(memo.Payload.Location)
} }
if memo.ParentID != nil { if memo.ParentID != nil {
parent := fmt.Sprintf("%s%d", MemoNamePrefix, *memo.ParentID) parent, err := s.Store.GetMemo(ctx, &store.FindMemo{
memoMessage.Parent = &parent ID: memo.ParentID,
ExcludeContent: true,
})
if err != nil {
return nil, errors.Wrap(err, "failed to get parent memo")
}
parentName := fmt.Sprintf("%s%s", MemoNamePrefix, parent.UID)
memoMessage.Parent = &parentName
} }
listMemoRelationsResponse, err := s.ListMemoRelations(ctx, &v1pb.ListMemoRelationsRequest{Name: name}) listMemoRelationsResponse, err := s.ListMemoRelations(ctx, &v1pb.ListMemoRelationsRequest{Name: name})
......
...@@ -62,15 +62,12 @@ func ExtractUserIDFromName(name string) (int32, error) { ...@@ -62,15 +62,12 @@ func ExtractUserIDFromName(name string) (int32, error) {
} }
// ExtractMemoIDFromName returns the memo ID from a resource name. // ExtractMemoIDFromName returns the memo ID from a resource name.
func ExtractMemoIDFromName(name string) (int32, error) { func ExtractMemoIDFromName(name string) (string, error) {
tokens, err := GetNameParentTokens(name, MemoNamePrefix) tokens, err := GetNameParentTokens(name, MemoNamePrefix)
if err != nil { if err != nil {
return 0, err return "", err
}
id, err := util.ConvertStringToInt32(tokens[0])
if err != nil {
return 0, errors.Errorf("invalid memo ID %q", tokens[0])
} }
id := tokens[0]
return id, nil return id, nil
} }
......
...@@ -76,11 +76,15 @@ func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateR ...@@ -76,11 +76,15 @@ func (s *APIV1Service) CreateResource(ctx context.Context, request *v1pb.CreateR
} }
if request.Resource.Memo != nil { if request.Resource.Memo != nil {
memoID, err := ExtractMemoIDFromName(*request.Resource.Memo) id, err := ExtractMemoIDFromName(*request.Resource.Memo)
if err != nil { if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo id: %v", err) return nil, status.Errorf(codes.InvalidArgument, "invalid memo name: %v", err)
} }
create.MemoID = &memoID memo, err := s.Store.GetMemo(ctx, &store.FindMemo{UID: &id})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to find memo: %v", err)
}
create.MemoID = &memo.ID
} }
resource, err := s.Store.CreateResource(ctx, create) resource, err := s.Store.CreateResource(ctx, create)
if err != nil { if err != nil {
...@@ -227,15 +231,6 @@ func (s *APIV1Service) UpdateResource(ctx context.Context, request *v1pb.UpdateR ...@@ -227,15 +231,6 @@ func (s *APIV1Service) UpdateResource(ctx context.Context, request *v1pb.UpdateR
for _, field := range request.UpdateMask.Paths { for _, field := range request.UpdateMask.Paths {
if field == "filename" { if field == "filename" {
update.Filename = &request.Resource.Filename update.Filename = &request.Resource.Filename
} else if field == "memo" {
if request.Resource.Memo == nil {
return nil, status.Errorf(codes.InvalidArgument, "memo is required")
}
memoID, err := ExtractMemoIDFromName(*request.Resource.Memo)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid memo id: %v", err)
}
update.MemoID = &memoID
} }
} }
...@@ -292,7 +287,7 @@ func (s *APIV1Service) convertResourceFromStore(ctx context.Context, resource *s ...@@ -292,7 +287,7 @@ func (s *APIV1Service) convertResourceFromStore(ctx context.Context, resource *s
ID: resource.MemoID, ID: resource.MemoID,
}) })
if memo != nil { if memo != nil {
memoName := fmt.Sprintf("%s%d", MemoNamePrefix, memo.ID) memoName := fmt.Sprintf("%s%s", MemoNamePrefix, memo.UID)
resourceMessage.Memo = &memoName resourceMessage.Memo = &memoName
} }
} }
......
...@@ -11,6 +11,7 @@ import { Inbox, Inbox_Status } from "@/types/proto/api/v1/inbox_service"; ...@@ -11,6 +11,7 @@ import { Inbox, Inbox_Status } from "@/types/proto/api/v1/inbox_service";
import { Memo } from "@/types/proto/api/v1/memo_service"; import { Memo } from "@/types/proto/api/v1/memo_service";
import { User } from "@/types/proto/api/v1/user_service"; import { User } from "@/types/proto/api/v1/user_service";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import { memoLink } from "@/utils/memo";
interface Props { interface Props {
inbox: Inbox; inbox: Inbox;
...@@ -51,7 +52,7 @@ const MemoCommentMessage = ({ inbox }: Props) => { ...@@ -51,7 +52,7 @@ const MemoCommentMessage = ({ inbox }: Props) => {
return; return;
} }
navigateTo(`/m/${relatedMemo.uid}`); navigateTo(memoLink(relatedMemo.name));
if (inbox.status === Inbox_Status.UNREAD) { if (inbox.status === Inbox_Status.UNREAD) {
handleArchiveMessage(true); handleArchiveMessage(true);
} }
...@@ -111,7 +112,7 @@ const MemoCommentMessage = ({ inbox }: Props) => { ...@@ -111,7 +112,7 @@ const MemoCommentMessage = ({ inbox }: Props) => {
> >
{t("inbox.memo-comment", { {t("inbox.memo-comment", {
user: sender?.nickname || sender?.username, user: sender?.nickname || sender?.username,
memo: `memos/${relatedMemo?.uid}`, memo: relatedMemo?.name,
interpolation: { escapeValue: false }, interpolation: { escapeValue: false },
})} })}
</p> </p>
......
...@@ -21,6 +21,7 @@ import { State } from "@/types/proto/api/v1/common"; ...@@ -21,6 +21,7 @@ import { State } from "@/types/proto/api/v1/common";
import { NodeType } from "@/types/proto/api/v1/markdown_service"; import { NodeType } from "@/types/proto/api/v1/markdown_service";
import { Memo } from "@/types/proto/api/v1/memo_service"; import { Memo } from "@/types/proto/api/v1/memo_service";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import { memoLink } from "@/utils/memo";
interface Props { interface Props {
memo: Memo; memo: Memo;
...@@ -51,7 +52,7 @@ const MemoActionMenu = (props: Props) => { ...@@ -51,7 +52,7 @@ const MemoActionMenu = (props: Props) => {
const userStatsStore = useUserStatsStore(); const userStatsStore = useUserStatsStore();
const isArchived = memo.state === State.ARCHIVED; const isArchived = memo.state === State.ARCHIVED;
const hasCompletedTaskList = checkHasCompletedTaskList(memo); const hasCompletedTaskList = checkHasCompletedTaskList(memo);
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`); const isInMemoDetailPage = location.pathname.startsWith(memoLink(memo.name));
const memoUpdatedCallback = () => { const memoUpdatedCallback = () => {
// Refresh user stats. // Refresh user stats.
...@@ -114,7 +115,7 @@ const MemoActionMenu = (props: Props) => { ...@@ -114,7 +115,7 @@ const MemoActionMenu = (props: Props) => {
}; };
const handleCopyLink = () => { const handleCopyLink = () => {
copy(`${window.location.origin}/m/${memo.uid}`); copy(`${window.location.origin}${memoLink(memo.name)}`);
toast.success(t("message.succeed-copy-link")); toast.success(t("message.succeed-copy-link"));
}; };
......
...@@ -6,7 +6,8 @@ import toast from "react-hot-toast"; ...@@ -6,7 +6,8 @@ import toast from "react-hot-toast";
import { Link } from "react-router-dom"; import { Link } from "react-router-dom";
import MemoResourceListView from "@/components/MemoResourceListView"; import MemoResourceListView from "@/components/MemoResourceListView";
import useLoading from "@/hooks/useLoading"; import useLoading from "@/hooks/useLoading";
import { useMemoStore } from "@/store/v1"; import { extractMemoIdFromName, useMemoStore } from "@/store/v1";
import { memoLink } from "@/utils/memo";
import MemoContent from ".."; import MemoContent from "..";
import { RendererContext } from "../types"; import { RendererContext } from "../types";
import Error from "./Error"; import Error from "./Error";
...@@ -20,12 +21,12 @@ const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => { ...@@ -20,12 +21,12 @@ const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
const context = useContext(RendererContext); const context = useContext(RendererContext);
const loadingState = useLoading(); const loadingState = useLoading();
const memoStore = useMemoStore(); const memoStore = useMemoStore();
const memo = memoStore.getMemoByUid(uid); const memoName = `memos/${uid}`;
const resourceName = `memos/${uid}`; const memo = memoStore.getMemoByName(memoName);
useEffect(() => { useEffect(() => {
memoStore.fetchMemoByUid(uid).finally(() => loadingState.setFinish()); memoStore.getOrFetchMemoByName(memoName).finally(() => loadingState.setFinish());
}, [uid]); }, [memoName]);
if (loadingState.isLoading) { if (loadingState.isLoading) {
return null; return null;
...@@ -37,12 +38,12 @@ const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => { ...@@ -37,12 +38,12 @@ const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
const params = new URLSearchParams(paramsStr); const params = new URLSearchParams(paramsStr);
const useSnippet = params.has("snippet"); const useSnippet = params.has("snippet");
const inlineMode = params.has("inline"); const inlineMode = params.has("inline");
if (!useSnippet && (memo.name === context.memoName || context.embeddedMemos.has(resourceName))) { if (!useSnippet && (memo.name === context.memoName || context.embeddedMemos.has(memoName))) {
return <Error message={`Nested Rendering Error: ![[${resourceName}]]`} />; return <Error message={`Nested Rendering Error: ![[${memoName}]]`} />;
} }
// Add the memo to the set of embedded memos. This is used to prevent infinite loops when a memo embeds itself. // Add the memo to the set of embedded memos. This is used to prevent infinite loops when a memo embeds itself.
context.embeddedMemos.add(resourceName); context.embeddedMemos.add(memoName);
const contentNode = useSnippet ? ( const contentNode = useSnippet ? (
<div className={clsx("text-gray-800 dark:text-gray-400", inlineMode ? "" : "line-clamp-3")}>{memo.snippet}</div> <div className={clsx("text-gray-800 dark:text-gray-400", inlineMode ? "" : "line-clamp-3")}>{memo.snippet}</div>
) : ( ) : (
...@@ -72,10 +73,13 @@ const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => { ...@@ -72,10 +73,13 @@ const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
<relative-time datetime={memo.displayTime?.toISOString()} format="datetime"></relative-time> <relative-time datetime={memo.displayTime?.toISOString()} format="datetime"></relative-time>
</div> </div>
<div className="flex justify-end items-center gap-1"> <div className="flex justify-end items-center gap-1">
<span className="text-xs opacity-60 leading-5 cursor-pointer hover:opacity-80" onClick={() => copyMemoUid(memo.uid)}> <span
{memo.uid.slice(0, 6)} className="text-xs opacity-60 leading-5 cursor-pointer hover:opacity-80"
onClick={() => copyMemoUid(extractMemoIdFromName(memo.name))}
>
{extractMemoIdFromName(memo.name).slice(0, 6)}
</span> </span>
<Link className="opacity-60 hover:opacity-80" to={`/m/${memo.uid}`} state={{ from: context.parentPage }} viewTransition> <Link className="opacity-60 hover:opacity-80" to={memoLink(memo.name)} state={{ from: context.parentPage }} viewTransition>
<ArrowUpRightIcon className="w-5 h-auto" /> <ArrowUpRightIcon className="w-5 h-auto" />
</Link> </Link>
</div> </div>
......
import { useContext, useEffect } from "react"; import { useContext, useEffect } from "react";
import useLoading from "@/hooks/useLoading"; import useLoading from "@/hooks/useLoading";
import useNavigateTo from "@/hooks/useNavigateTo"; import useNavigateTo from "@/hooks/useNavigateTo";
import { useMemoStore } from "@/store/v1"; import { memoNamePrefix, useMemoStore } from "@/store/v1";
import { memoLink } from "@/utils/memo";
import { RendererContext } from "../types"; import { RendererContext } from "../types";
import Error from "./Error"; import Error from "./Error";
...@@ -14,13 +15,14 @@ const ReferencedMemo = ({ resourceId: uid, params: paramsStr }: Props) => { ...@@ -14,13 +15,14 @@ const ReferencedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
const navigateTo = useNavigateTo(); const navigateTo = useNavigateTo();
const loadingState = useLoading(); const loadingState = useLoading();
const memoStore = useMemoStore(); const memoStore = useMemoStore();
const memo = memoStore.getMemoByUid(uid); const memoName = `${memoNamePrefix}${uid}`;
const memo = memoStore.getMemoByName(memoName);
const params = new URLSearchParams(paramsStr); const params = new URLSearchParams(paramsStr);
const context = useContext(RendererContext); const context = useContext(RendererContext);
useEffect(() => { useEffect(() => {
memoStore.fetchMemoByUid(uid).finally(() => loadingState.setFinish()); memoStore.getOrFetchMemoByName(memoName).finally(() => loadingState.setFinish());
}, [uid]); }, [memoName]);
if (loadingState.isLoading) { if (loadingState.isLoading) {
return null; return null;
...@@ -33,7 +35,7 @@ const ReferencedMemo = ({ resourceId: uid, params: paramsStr }: Props) => { ...@@ -33,7 +35,7 @@ const ReferencedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
const displayContent = paramsText || (memo.snippet.length > 12 ? `${memo.snippet.slice(0, 12)}...` : memo.snippet); const displayContent = paramsText || (memo.snippet.length > 12 ? `${memo.snippet.slice(0, 12)}...` : memo.snippet);
const handleGotoMemoDetailPage = () => { const handleGotoMemoDetailPage = () => {
navigateTo(`/m/${memo.uid}`, { navigateTo(memoLink(memo.name), {
state: { state: {
from: context.parentPage, from: context.parentPage,
}, },
......
...@@ -9,6 +9,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/Popover ...@@ -9,6 +9,7 @@ import { Popover, PopoverContent, PopoverTrigger } from "@/components/ui/Popover
import { memoServiceClient } from "@/grpcweb"; import { memoServiceClient } from "@/grpcweb";
import { DEFAULT_LIST_MEMOS_PAGE_SIZE } from "@/helpers/consts"; import { DEFAULT_LIST_MEMOS_PAGE_SIZE } from "@/helpers/consts";
import useCurrentUser from "@/hooks/useCurrentUser"; import useCurrentUser from "@/hooks/useCurrentUser";
import { extractMemoIdFromName } from "@/store/v1";
import { MemoRelation_Memo, MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service"; import { MemoRelation_Memo, MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
import { Memo } from "@/types/proto/api/v1/memo_service"; import { Memo } from "@/types/proto/api/v1/memo_service";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
...@@ -101,7 +102,7 @@ const AddMemoRelationPopover = (props: Props) => { ...@@ -101,7 +102,7 @@ const AddMemoRelationPopover = (props: Props) => {
editorRef.current.insertText("\n"); editorRef.current.insertText("\n");
} }
for (const memo of selectedMemos) { for (const memo of selectedMemos) {
editorRef.current.insertText(`![[memos/${memo.uid}]]\n`); editorRef.current.insertText(`![[memos/${extractMemoIdFromName(memo.name)}]]\n`);
} }
setTimeout(() => { setTimeout(() => {
editorRef.current?.scrollToCursor(); editorRef.current?.scrollToCursor();
......
...@@ -5,6 +5,7 @@ import ForceGraph2D, { ForceGraphMethods, LinkObject, NodeObject } from "react-f ...@@ -5,6 +5,7 @@ import ForceGraph2D, { ForceGraphMethods, LinkObject, NodeObject } from "react-f
import useNavigateTo from "@/hooks/useNavigateTo"; import useNavigateTo from "@/hooks/useNavigateTo";
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service"; import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
import { Memo } from "@/types/proto/api/v1/memo_service"; import { Memo } from "@/types/proto/api/v1/memo_service";
import { memoLink } from "@/utils/memo";
import { LinkType, NodeType } from "./types"; import { LinkType, NodeType } from "./types";
import { convertMemoRelationsToGraphData } from "./utils"; import { convertMemoRelationsToGraphData } from "./utils";
...@@ -30,8 +31,8 @@ const MemoRelationForceGraph = ({ className, memo, parentPage }: Props) => { ...@@ -30,8 +31,8 @@ const MemoRelationForceGraph = ({ className, memo, parentPage }: Props) => {
}, []); }, []);
const onNodeClick = (node: NodeObject<NodeType>) => { const onNodeClick = (node: NodeObject<NodeType>) => {
if (node.memo.uid === memo.uid) return; if (node.memo.name === memo.name) return;
navigateTo(`/m/${node.memo.uid}`, { navigateTo(memoLink(memo.name), {
state: { state: {
from: parentPage, from: parentPage,
}, },
......
...@@ -13,7 +13,7 @@ import { Memo, Visibility } from "@/types/proto/api/v1/memo_service"; ...@@ -13,7 +13,7 @@ import { Memo, Visibility } from "@/types/proto/api/v1/memo_service";
import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service"; import { WorkspaceMemoRelatedSetting } from "@/types/proto/api/v1/workspace_setting_service";
import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting"; import { WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import { convertVisibilityToString } from "@/utils/memo"; import { convertVisibilityToString, memoLink } from "@/utils/memo";
import { isSuperUser } from "@/utils/user"; import { isSuperUser } from "@/utils/user";
import MemoActionMenu from "./MemoActionMenu"; import MemoActionMenu from "./MemoActionMenu";
import MemoContent from "./MemoContent"; import MemoContent from "./MemoContent";
...@@ -61,7 +61,7 @@ const MemoView: React.FC<Props> = (props: Props) => { ...@@ -61,7 +61,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto"; const relativeTimeFormat = Date.now() - memo.displayTime!.getTime() > 1000 * 60 * 60 * 24 ? "datetime" : "auto";
const isArchived = memo.state === State.ARCHIVED; const isArchived = memo.state === State.ARCHIVED;
const readonly = memo.creator !== user?.name && !isSuperUser(user); const readonly = memo.creator !== user?.name && !isSuperUser(user);
const isInMemoDetailPage = location.pathname.startsWith(`/m/${memo.uid}`); const isInMemoDetailPage = location.pathname.startsWith(memoLink(memo.name));
const parentPage = props.parentPage || location.pathname; const parentPage = props.parentPage || location.pathname;
// Initial related data: creator. // Initial related data: creator.
...@@ -71,12 +71,12 @@ const MemoView: React.FC<Props> = (props: Props) => { ...@@ -71,12 +71,12 @@ const MemoView: React.FC<Props> = (props: Props) => {
}, []); }, []);
const handleGotoMemoDetailPage = useCallback(() => { const handleGotoMemoDetailPage = useCallback(() => {
navigateTo(`/m/${memo.uid}`, { navigateTo(memoLink(memo.name), {
state: { state: {
from: parentPage, from: parentPage,
}, },
}); });
}, [memo.uid, parentPage]); }, [memo.name, parentPage]);
const handleMemoContentClick = useCallback(async (e: React.MouseEvent) => { const handleMemoContentClick = useCallback(async (e: React.MouseEvent) => {
const targetEl = e.target as HTMLElement; const targetEl = e.target as HTMLElement;
...@@ -192,7 +192,7 @@ const MemoView: React.FC<Props> = (props: Props) => { ...@@ -192,7 +192,7 @@ const MemoView: React.FC<Props> = (props: Props) => {
"flex flex-row justify-start items-center hover:opacity-70", "flex flex-row justify-start items-center hover:opacity-70",
commentAmount === 0 && "invisible group-hover:visible", commentAmount === 0 && "invisible group-hover:visible",
)} )}
to={`/m/${memo.uid}#comments`} to={`${memoLink(memo.name)}#comments`}
viewTransition viewTransition
state={{ state={{
from: parentPage, from: parentPage,
......
...@@ -12,11 +12,12 @@ import MobileHeader from "@/components/MobileHeader"; ...@@ -12,11 +12,12 @@ import MobileHeader from "@/components/MobileHeader";
import useCurrentUser from "@/hooks/useCurrentUser"; import useCurrentUser from "@/hooks/useCurrentUser";
import useNavigateTo from "@/hooks/useNavigateTo"; import useNavigateTo from "@/hooks/useNavigateTo";
import useResponsiveWidth from "@/hooks/useResponsiveWidth"; import useResponsiveWidth from "@/hooks/useResponsiveWidth";
import { useMemoStore, useWorkspaceSettingStore } from "@/store/v1"; import { memoNamePrefix, useMemoStore, useWorkspaceSettingStore } from "@/store/v1";
import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service"; import { MemoRelation_Type } from "@/types/proto/api/v1/memo_relation_service";
import { Memo } from "@/types/proto/api/v1/memo_service"; import { Memo } from "@/types/proto/api/v1/memo_service";
import { WorkspaceMemoRelatedSetting, WorkspaceSettingKey } from "@/types/proto/store/workspace_setting"; import { WorkspaceMemoRelatedSetting, WorkspaceSettingKey } from "@/types/proto/store/workspace_setting";
import { useTranslate } from "@/utils/i18n"; import { useTranslate } from "@/utils/i18n";
import { memoLink } from "@/utils/memo";
const MemoDetail = () => { const MemoDetail = () => {
const t = useTranslate(); const t = useTranslate();
...@@ -28,7 +29,8 @@ const MemoDetail = () => { ...@@ -28,7 +29,8 @@ const MemoDetail = () => {
const currentUser = useCurrentUser(); const currentUser = useCurrentUser();
const memoStore = useMemoStore(); const memoStore = useMemoStore();
const uid = params.uid; const uid = params.uid;
const memo = memoStore.getMemoByUid(uid || ""); const memoName = `${memoNamePrefix}${uid}`;
const memo = memoStore.getMemoByName(memoName);
const workspaceMemoRelatedSetting = WorkspaceMemoRelatedSetting.fromPartial( const workspaceMemoRelatedSetting = WorkspaceMemoRelatedSetting.fromPartial(
workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting || {}, workspaceSettingStore.getWorkspaceSettingByKey(WorkspaceSettingKey.MEMO_RELATED)?.memoRelatedSetting || {},
); );
...@@ -41,15 +43,15 @@ const MemoDetail = () => { ...@@ -41,15 +43,15 @@ const MemoDetail = () => {
// Prepare memo. // Prepare memo.
useEffect(() => { useEffect(() => {
if (uid) { if (memoName) {
memoStore.fetchMemoByUid(uid).catch((error: ClientError) => { memoStore.getOrFetchMemoByName(memoName).catch((error: ClientError) => {
toast.error(error.details); toast.error(error.details);
navigateTo("/403"); navigateTo("/403");
}); });
} else { } else {
navigateTo("/404"); navigateTo("/404");
} }
}, [uid]); }, [memoName]);
// Prepare memo comments. // Prepare memo comments.
useEffect(() => { useEffect(() => {
...@@ -96,7 +98,7 @@ const MemoDetail = () => { ...@@ -96,7 +98,7 @@ const MemoDetail = () => {
<div className="w-auto inline-block mb-2"> <div className="w-auto inline-block mb-2">
<Link <Link
className="px-3 py-1 border rounded-lg max-w-xs w-auto text-sm flex flex-row justify-start items-center flex-nowrap text-gray-600 dark:text-gray-400 dark:border-gray-500 hover:shadow hover:opacity-80" className="px-3 py-1 border rounded-lg max-w-xs w-auto text-sm flex flex-row justify-start items-center flex-nowrap text-gray-600 dark:text-gray-400 dark:border-gray-500 hover:shadow hover:opacity-80"
to={`/m/${parentMemo.uid}`} to={memoLink(parentMemo.name)}
state={locationState} state={locationState}
viewTransition viewTransition
> >
......
...@@ -78,19 +78,6 @@ export const useMemoStore = create( ...@@ -78,19 +78,6 @@ export const useMemoStore = create(
getMemoByName: (name: string) => { getMemoByName: (name: string) => {
return get().memoMapByName[name]; return get().memoMapByName[name];
}, },
fetchMemoByUid: async (uid: string) => {
const memo = await memoServiceClient.getMemoByUid({
uid,
});
const memoMap = get().memoMapByName;
memoMap[memo.name] = memo;
set({ stateId: uniqueId(), memoMapByName: memoMap });
return memo;
},
getMemoByUid: (uid: string) => {
const memoMap = get().memoMapByName;
return Object.values(memoMap).find((memo) => memo.uid === uid);
},
createMemo: async (request: CreateMemoRequest) => { createMemo: async (request: CreateMemoRequest) => {
const memo = await memoServiceClient.createMemo(request); const memo = await memoServiceClient.createMemo(request);
const memoMap = get().memoMapByName; const memoMap = get().memoMapByName;
......
...@@ -9,7 +9,7 @@ export const extractUserIdFromName = (name: string) => { ...@@ -9,7 +9,7 @@ export const extractUserIdFromName = (name: string) => {
}; };
export const extractMemoIdFromName = (name: string) => { export const extractMemoIdFromName = (name: string) => {
return parseInt(name.split(memoNamePrefix).pop() || "", 10); return name.split(memoNamePrefix).pop() || "";
}; };
export const extractIdentityProviderIdFromName = (name: string) => { export const extractIdentityProviderIdFromName = (name: string) => {
......
import { extractMemoIdFromName } from "@/store/v1";
import { Visibility } from "@/types/proto/api/v1/memo_service"; import { Visibility } from "@/types/proto/api/v1/memo_service";
export const convertVisibilityFromString = (visibility: string) => { export const convertVisibilityFromString = (visibility: string) => {
...@@ -25,3 +26,5 @@ export const convertVisibilityToString = (visibility: Visibility) => { ...@@ -25,3 +26,5 @@ export const convertVisibilityToString = (visibility: Visibility) => {
return "PRIVATE"; return "PRIVATE";
} }
}; };
export const memoLink = (memo: string) => `/m/${extractMemoIdFromName(memo)}`;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment