feat(api): implement get memo by uid

This commit is contained in:
Steven 2024-07-11 23:31:50 +08:00
parent 34e938a1e3
commit 1ab2c89408
10 changed files with 1023 additions and 608 deletions

View File

@ -301,12 +301,16 @@ paths:
type: integer
format: int32
- name: pageToken
description: "A page token, received from a previous `ListMemos` call.\r\nProvide this to retrieve the subsequent page."
description: |-
A page token, received from a previous `ListMemos` call.
Provide this to retrieve the subsequent page.
in: query
required: false
type: string
- name: filter
description: "Filter is used to filter memos returned in the list.\r\nFormat: \"creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']\""
description: |-
Filter is used to filter memos returned in the list.
Format: "creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']"
in: query
required: false
type: string
@ -347,12 +351,17 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "name is the name of the user to get stats for.\r\nFormat: users/{id}"
description: |-
name is the name of the user to get stats for.
Format: users/{id}
in: query
required: false
type: string
- name: timezone
description: "timezone location\r\nFormat: uses tz identifier\r\nhttps://en.wikipedia.org/wiki/List_of_tz_database_time_zones"
description: |-
timezone location
Format: uses tz identifier
https://en.wikipedia.org/wiki/List_of_tz_database_time_zones
in: query
required: false
type: string
@ -363,6 +372,27 @@ paths:
type: string
tags:
- MemoService
/api/v1/memos:by-uid/{uid}:
get:
summary: GetMemoByUid gets a memo by uid
operationId: MemoService_GetMemoByUid
responses:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1Memo'
default:
description: An unexpected error response.
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: uid
description: The uid of the memo.
in: path
required: true
type: string
tags:
- MemoService
/api/v1/memos:export:
post:
summary: ExportMemos exports memos.
@ -399,7 +429,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: filter
description: "Filter is used to filter memos returned.\r\nFormat: \"creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']\""
description: |-
Filter is used to filter memos returned.
Format: "creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']"
in: query
required: false
type: string
@ -532,7 +564,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: filter
description: "Filter is used to filter users returned in the list.\r\nFormat: \"username == 'frank'\""
description: |-
Filter is used to filter users returned in the list.
Format: "username == 'frank'"
in: query
required: false
type: string
@ -693,7 +727,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The resource name of the workspace setting.\r\nFormat: settings/{setting}"
description: |-
The resource name of the workspace setting.
Format: settings/{setting}
in: path
required: true
type: string
@ -715,7 +751,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: setting.name
description: "name is the name of the setting.\r\nFormat: settings/{setting}"
description: |-
name is the name of the setting.
Format: settings/{setting}
in: path
required: true
type: string
@ -751,7 +789,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: identityProvider.name
description: "The name of the identityProvider.\r\nFormat: identityProviders/{id}"
description: |-
The name of the identityProvider.
Format: identityProviders/{id}
in: path
required: true
type: string
@ -789,7 +829,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: inbox.name
description: "The name of the inbox.\r\nFormat: inboxes/{id}"
description: |-
The name of the inbox.
Format: inboxes/{id}
in: path
required: true
type: string
@ -833,7 +875,10 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: memo.name
description: "The name of the memo.\r\nFormat: memos/{id}\r\nid is the system generated id."
description: |-
The name of the memo.
Format: memos/{id}
id is the system generated id.
in: path
required: true
type: string
@ -851,7 +896,9 @@ paths:
$ref: '#/definitions/v1RowStatus'
creator:
type: string
title: "The name of the creator.\r\nFormat: users/{id}"
title: |-
The name of the creator.
Format: users/{id}
createTime:
type: string
format: date-time
@ -904,7 +951,9 @@ paths:
readOnly: true
parent:
type: string
title: "The name of the parent memo.\r\nFormat: memos/{id}"
title: |-
The name of the parent memo.
Format: memos/{id}
readOnly: true
tags:
- MemoService
@ -923,7 +972,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_1
description: "The name of the identityProvider to get.\r\nFormat: identityProviders/{id}"
description: |-
The name of the identityProvider to get.
Format: identityProviders/{id}
in: path
required: true
type: string
@ -945,7 +996,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_1
description: "The name of the identityProvider to delete.\r\nFormat: identityProviders/{id}"
description: |-
The name of the identityProvider to delete.
Format: identityProviders/{id}
in: path
required: true
type: string
@ -967,7 +1020,10 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_2
description: "The name of the resource.\r\nFormat: resources/{id}\r\nid is the system generated unique identifier."
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
@ -989,7 +1045,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_2
description: "The name of the inbox to delete.\r\nFormat: inboxes/{id}"
description: |-
The name of the inbox to delete.
Format: inboxes/{id}
in: path
required: true
type: string
@ -1011,7 +1069,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_3
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1033,7 +1093,10 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_3
description: "The name of the resource.\r\nFormat: resources/{id}\r\nid is the system generated unique identifier."
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
@ -1056,7 +1119,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name_4
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1078,7 +1143,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1100,7 +1167,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1122,7 +1191,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1143,7 +1214,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1171,7 +1244,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1198,7 +1273,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1219,7 +1296,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1246,7 +1325,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}. Use \"memos/-\" to list all properties."
description: |-
The name of the memo.
Format: memos/{id}. Use "memos/-" to list all properties.
in: path
required: true
type: string
@ -1269,7 +1350,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}. Use \"memos/-\" to rebuild all memos."
description: |-
The name of the memo.
Format: memos/{id}. Use "memos/-" to rebuild all memos.
in: path
required: true
type: string
@ -1296,7 +1379,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1317,7 +1402,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1344,7 +1431,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1366,7 +1455,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1393,7 +1484,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1415,7 +1508,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the memo.\r\nFormat: memos/{id}"
description: |-
The name of the memo.
Format: memos/{id}
in: path
required: true
type: string
@ -1442,7 +1537,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1464,13 +1561,17 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: parent
description: "The parent, who owns the tags.\r\nFormat: memos/{id}. Use \"memos/-\" to list all tags."
description: |-
The parent, who owns the tags.
Format: memos/{id}. Use "memos/-" to list all tags.
in: path
required: true
type: string
pattern: memos/[^/]+
- name: filter
description: "Filter is used to filter memos.\r\nFormat: \"creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']\""
description: |-
Filter is used to filter memos.
Format: "creator == 'users/{uid}' && visibilities == ['PUBLIC', 'PROTECTED']"
in: query
required: false
type: string
@ -1492,7 +1593,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: parent
description: "The parent, who owns the tags.\r\nFormat: memos/{id}. Use \"memos/-\" to delete all tags."
description: |-
The parent, who owns the tags.
Format: memos/{id}. Use "memos/-" to delete all tags.
in: path
required: true
type: string
@ -1523,7 +1626,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: parent
description: "The parent, who owns the tags.\r\nFormat: memos/{id}. Use \"memos/-\" to rename all tags."
description: |-
The parent, who owns the tags.
Format: memos/{id}. Use "memos/-" to rename all tags.
in: path
required: true
type: string
@ -1550,7 +1655,10 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: resource.name
description: "The name of the resource.\r\nFormat: resources/{id}\r\nid is the system generated unique identifier."
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
@ -1582,7 +1690,9 @@ paths:
format: int64
memo:
type: string
title: "The related memo.\r\nFormat: memos/{id}"
title: |-
The related memo.
Format: memos/{id}
tags:
- ResourceService
/api/v1/{setting.name}:
@ -1600,7 +1710,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: setting.name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1637,7 +1749,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: user.name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1691,7 +1805,9 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the user.\r\nFormat: users/{id}"
description: |-
The name of the user.
Format: users/{id}
in: path
required: true
type: string
@ -1724,7 +1840,10 @@ paths:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: name
description: "The name of the resource.\r\nFormat: resources/{id}\r\nid is the system generated unique identifier."
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
in: path
required: true
type: string
@ -1905,7 +2024,9 @@ definitions:
properties:
name:
type: string
title: "The name of the identityProvider.\r\nFormat: identityProviders/{id}"
title: |-
The name of the identityProvider.
Format: identityProviders/{id}
type:
$ref: '#/definitions/apiv1IdentityProviderType'
title:
@ -1949,7 +2070,9 @@ definitions:
properties:
name:
type: string
title: "The name of the user.\r\nFormat: users/{id}"
title: |-
The name of the user.
Format: users/{id}
locale:
type: string
description: The preferred locale of the user.
@ -2011,7 +2134,9 @@ definitions:
properties:
name:
type: string
title: "name is the name of the setting.\r\nFormat: settings/{setting}"
title: |-
name is the name of the setting.
Format: settings/{setting}
generalSetting:
$ref: '#/definitions/apiv1WorkspaceGeneralSetting'
storageSetting:
@ -2026,7 +2151,9 @@ definitions:
description: storage_type is the storage type.
filepathTemplate:
type: string
title: "The template of file path.\r\ne.g. assets/{timestamp}_{filename}"
title: |-
The template of file path.
e.g. assets/{timestamp}_{filename}
uploadSizeLimitMb:
type: string
format: int64
@ -2295,7 +2422,9 @@ definitions:
additionalProperties:
type: integer
format: int32
description: "stats is the stats of memo creating/updating activities.\r\nkey is the year-month-day string. e.g. \"2020-01-01\"."
description: |-
stats is the stats of memo creating/updating activities.
key is the year-month-day string. e.g. "2020-01-01".
v1HeadingNode:
type: object
properties:
@ -2329,7 +2458,9 @@ definitions:
properties:
name:
type: string
title: "The name of the inbox.\r\nFormat: inboxes/{id}"
title: |-
The name of the inbox.
Format: inboxes/{id}
sender:
type: string
title: 'Format: users/{id}'
@ -2449,7 +2580,10 @@ definitions:
additionalProperties:
type: integer
format: int32
description: "tag_amounts is the amount of tags.\r\nkey is the tag name. e.g. \"tag1\".\r\nvalue is the amount of the tag."
description: |-
tag_amounts is the amount of tags.
key is the tag name. e.g. "tag1".
value is the amount of the tag.
v1ListMemosResponse:
type: object
properties:
@ -2460,7 +2594,9 @@ definitions:
$ref: '#/definitions/v1Memo'
nextPageToken:
type: string
description: "A token, which can be sent as `page_token` to retrieve the next page.\r\nIf this field is omitted, there are no subsequent pages."
description: |-
A token, which can be sent as `page_token` to retrieve the next page.
If this field is omitted, there are no subsequent pages.
v1ListResourcesResponse:
type: object
properties:
@ -2508,7 +2644,10 @@ definitions:
properties:
name:
type: string
description: "The name of the memo.\r\nFormat: memos/{id}\r\nid is the system generated id."
description: |-
The name of the memo.
Format: memos/{id}
id is the system generated id.
uid:
type: string
description: The user defined id of the memo.
@ -2516,7 +2655,9 @@ definitions:
$ref: '#/definitions/v1RowStatus'
creator:
type: string
title: "The name of the creator.\r\nFormat: users/{id}"
title: |-
The name of the creator.
Format: users/{id}
createTime:
type: string
format: date-time
@ -2569,7 +2710,9 @@ definitions:
readOnly: true
parent:
type: string
title: "The name of the parent memo.\r\nFormat: memos/{id}"
title: |-
The name of the parent memo.
Format: memos/{id}
readOnly: true
v1MemoProperty:
type: object
@ -2591,10 +2734,14 @@ definitions:
properties:
memo:
type: string
title: "The name of memo.\r\nFormat: \"memos/{uid}\""
title: |-
The name of memo.
Format: "memos/{uid}"
relatedMemo:
type: string
title: "The name of related memo.\r\nFormat: \"memos/{uid}\""
title: |-
The name of related memo.
Format: "memos/{uid}"
type:
$ref: '#/definitions/v1MemoRelationType'
v1MemoRelationType:
@ -2743,7 +2890,9 @@ definitions:
format: int32
creator:
type: string
title: "The name of the creator.\r\nFormat: users/{id}"
title: |-
The name of the creator.
Format: users/{id}
contentId:
type: string
reactionType:
@ -2777,7 +2926,10 @@ definitions:
properties:
name:
type: string
description: "The name of the resource.\r\nFormat: resources/{id}\r\nid is the system generated unique identifier."
description: |-
The name of the resource.
Format: resources/{id}
id is the system generated unique identifier.
uid:
type: string
description: The user defined id of the resource.
@ -2799,7 +2951,9 @@ definitions:
format: int64
memo:
type: string
title: "The related memo.\r\nFormat: memos/{id}"
title: |-
The related memo.
Format: memos/{id}
v1RestoreMarkdownRequest:
type: object
properties:
@ -2923,7 +3077,9 @@ definitions:
properties:
name:
type: string
title: "The name of the user.\r\nFormat: users/{id}"
title: |-
The name of the user.
Format: users/{id}
id:
type: integer
format: int32
@ -2997,7 +3153,9 @@ definitions:
properties:
owner:
type: string
title: "The name of instance owner.\r\nFormat: \"users/{id}\""
title: |-
The name of instance owner.
Format: "users/{id}"
version:
type: string
title: version is the current version of instance

View File

@ -37,6 +37,11 @@ service MemoService {
option (google.api.http) = {get: "/api/v1/{name=memos/*}"};
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.
rpc UpdateMemo(UpdateMemoRequest) returns (Memo) {
option (google.api.http) = {
@ -254,6 +259,11 @@ message GetMemoRequest {
string name = 1;
}
message GetMemoByUidRequest {
// The uid of the memo.
string uid = 1;
}
message UpdateMemoRequest {
Memo memo = 1;

File diff suppressed because it is too large Load Diff

View File

@ -181,6 +181,58 @@ func local_request_MemoService_GetMemo_0(ctx context.Context, marshaler runtime.
}
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
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
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
var metadata runtime.ServerMetadata
var (
val string
ok bool
err error
_ = err
)
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}}
)
@ -1333,6 +1385,31 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
})
mux.Handle("GET", 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)
var err error
var annotatedContext context.Context
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("PATCH", pattern_MemoService_UpdateMemo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@ -1912,6 +1989,28 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
})
mux.Handle("GET", 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)
var err error
var annotatedContext context.Context
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("PATCH", pattern_MemoService_UpdateMemo_0, func(w http.ResponseWriter, req *http.Request, pathParams map[string]string) {
ctx, cancel := context.WithCancel(req.Context())
defer cancel()
@ -2320,6 +2419,8 @@ var (
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_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"}, ""))
@ -2366,6 +2467,8 @@ var (
forward_MemoService_GetMemo_0 = runtime.ForwardResponseMessage
forward_MemoService_GetMemoByUid_0 = runtime.ForwardResponseMessage
forward_MemoService_UpdateMemo_0 = runtime.ForwardResponseMessage
forward_MemoService_DeleteMemo_0 = runtime.ForwardResponseMessage

View File

@ -24,6 +24,7 @@ const (
MemoService_ListMemos_FullMethodName = "/memos.api.v1.MemoService/ListMemos"
MemoService_SearchMemos_FullMethodName = "/memos.api.v1.MemoService/SearchMemos"
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_DeleteMemo_FullMethodName = "/memos.api.v1.MemoService/DeleteMemo"
MemoService_ExportMemos_FullMethodName = "/memos.api.v1.MemoService/ExportMemos"
@ -56,6 +57,8 @@ type MemoServiceClient interface {
SearchMemos(ctx context.Context, in *SearchMemosRequest, opts ...grpc.CallOption) (*SearchMemosResponse, error)
// GetMemo gets a memo.
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(ctx context.Context, in *UpdateMemoRequest, opts ...grpc.CallOption) (*Memo, error)
// DeleteMemo deletes a memo.
@ -142,6 +145,16 @@ func (c *memoServiceClient) GetMemo(ctx context.Context, in *GetMemoRequest, opt
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) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(Memo)
@ -334,6 +347,8 @@ type MemoServiceServer interface {
SearchMemos(context.Context, *SearchMemosRequest) (*SearchMemosResponse, error)
// GetMemo gets a memo.
GetMemo(context.Context, *GetMemoRequest) (*Memo, error)
// GetMemoByUid gets a memo by uid
GetMemoByUid(context.Context, *GetMemoByUidRequest) (*Memo, error)
// UpdateMemo updates a memo.
UpdateMemo(context.Context, *UpdateMemoRequest) (*Memo, error)
// DeleteMemo deletes a memo.
@ -389,6 +404,9 @@ func (UnimplementedMemoServiceServer) SearchMemos(context.Context, *SearchMemosR
func (UnimplementedMemoServiceServer) GetMemo(context.Context, *GetMemoRequest) (*Memo, error) {
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) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateMemo not implemented")
}
@ -528,6 +546,24 @@ func _MemoService_GetMemo_Handler(srv interface{}, ctx context.Context, dec func
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) {
in := new(UpdateMemoRequest)
if err := dec(in); err != nil {
@ -875,6 +911,10 @@ var MemoService_ServiceDesc = grpc.ServiceDesc{
MethodName: "GetMemo",
Handler: _MemoService_GetMemo_Handler,
},
{
MethodName: "GetMemoByUid",
Handler: _MemoService_GetMemoByUid_Handler,
},
{
MethodName: "UpdateMemo",
Handler: _MemoService_UpdateMemo_Handler,

View File

@ -205,6 +205,36 @@ func (s *APIV1Service) GetMemo(ctx context.Context, request *v1pb.GetMemoRequest
return memoMessage, nil
}
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 {
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
}
func (s *APIV1Service) UpdateMemo(ctx context.Context, request *v1pb.UpdateMemoRequest) (*v1pb.Memo, error) {
id, err := ExtractMemoIDFromName(request.Memo.Name)
if err != nil {
@ -968,9 +998,6 @@ func (s *APIV1Service) buildMemoFindWithFilter(ctx context.Context, find *store.
}
find.CreatorID = &user.ID
}
if filter.UID != nil {
find.UID = filter.UID
}
if filter.RowStatus != nil {
find.RowStatus = filter.RowStatus
}
@ -1059,7 +1086,6 @@ type SearchMemosFilter struct {
DisplayTimeBefore *int64
DisplayTimeAfter *int64
Creator *string
UID *string
RowStatus *store.RowStatus
Random bool
Limit *int
@ -1122,9 +1148,6 @@ func findSearchMemosField(callExpr *expr.Expr_Call, filter *SearchMemosFilter) {
} else if idExpr.Name == "creator" {
creator := callExpr.Args[1].GetConstExpr().GetStringValue()
filter.Creator = &creator
} else if idExpr.Name == "uid" {
uid := callExpr.Args[1].GetConstExpr().GetStringValue()
filter.UID = &uid
} else if idExpr.Name == "row_status" {
rowStatus := store.RowStatus(callExpr.Args[1].GetConstExpr().GetStringValue())
filter.RowStatus = &rowStatus

View File

@ -13,22 +13,22 @@ interface Props {
params: string;
}
const EmbeddedMemo = ({ resourceId, params: paramsStr }: Props) => {
const EmbeddedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
const context = useContext(RendererContext);
const loadingState = useLoading();
const memoStore = useMemoStore();
const memo = memoStore.getMemoByUid(resourceId);
const resourceName = `memos/${resourceId}`;
const memo = memoStore.getMemoByUid(uid);
const resourceName = `memos/${uid}`;
useEffect(() => {
memoStore.searchMemos(`uid == "${resourceId}" && include_comments == true`).finally(() => loadingState.setFinish());
}, [resourceId]);
memoStore.fetchMemoByUid(uid).finally(() => loadingState.setFinish());
}, [uid]);
if (loadingState.isLoading) {
return null;
}
if (!memo) {
return <Error message={`Memo not found: ${resourceId}`} />;
return <Error message={`Memo not found: ${uid}`} />;
}
if (memo.name === context.memoName || context.embeddedMemos.has(resourceName)) {
return <Error message={`Nested Rendering Error: ![[${resourceName}]]`} />;

View File

@ -9,22 +9,22 @@ interface Props {
params: string;
}
const ReferencedMemo = ({ resourceId, params: paramsStr }: Props) => {
const ReferencedMemo = ({ resourceId: uid, params: paramsStr }: Props) => {
const navigateTo = useNavigateTo();
const loadingState = useLoading();
const memoStore = useMemoStore();
const memo = memoStore.getMemoByUid(resourceId);
const memo = memoStore.getMemoByUid(uid);
const params = new URLSearchParams(paramsStr);
useEffect(() => {
memoStore.searchMemos(`uid == "${resourceId}" && include_comments == true`).finally(() => loadingState.setFinish());
}, [resourceId]);
memoStore.fetchMemoByUid(uid).finally(() => loadingState.setFinish());
}, [uid]);
if (loadingState.isLoading) {
return null;
}
if (!memo) {
return <Error message={`Memo not found: ${resourceId}`} />;
return <Error message={`Memo not found: ${uid}`} />;
}
const paramsText = params.has("text") ? params.get("text") : undefined;

View File

@ -34,7 +34,7 @@ const MemoDetail = () => {
// Prepare memo.
useEffect(() => {
if (uid) {
memoStore.searchMemos(`uid == "${uid}"`).catch((error: ClientError) => {
memoStore.fetchMemoByUid(uid).catch((error: ClientError) => {
toast.error(error.details);
navigateTo("/403");
});

View File

@ -59,6 +59,15 @@ export const useMemoStore = create(
set({ stateId: uniqueId(), memoMapByName: memoMap });
return memos;
},
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);