Commit f1308ddd authored by johnnyjoy's avatar johnnyjoy

refactor: update part of resource identifier

parent cda18a37
...@@ -116,8 +116,8 @@ service MemoService { ...@@ -116,8 +116,8 @@ service MemoService {
} }
// DeleteMemoReaction deletes a reaction for a memo. // DeleteMemoReaction deletes a reaction for a memo.
rpc DeleteMemoReaction(DeleteMemoReactionRequest) returns (google.protobuf.Empty) { rpc DeleteMemoReaction(DeleteMemoReactionRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {delete: "/api/v1/reactions/{reaction_id}"}; option (google.api.http) = {delete: "/api/v1/reactions/{id}"};
option (google.api.method_signature) = "reaction_id"; option (google.api.method_signature) = "id";
} }
} }
...@@ -336,5 +336,7 @@ message UpsertMemoReactionRequest { ...@@ -336,5 +336,7 @@ message UpsertMemoReactionRequest {
} }
message DeleteMemoReactionRequest { message DeleteMemoReactionRequest {
int32 reaction_id = 1; // The id of the reaction.
// Refer to the `Reaction.id`.
int32 id = 1;
} }
...@@ -11,6 +11,8 @@ message Reaction { ...@@ -11,6 +11,8 @@ message Reaction {
// Format: users/{user} // Format: users/{user}
string creator = 2; string creator = 2;
// The content identifier.
// For memo, it should be the `Memo.name`.
string content_id = 3; string content_id = 3;
string reaction_type = 4; string reaction_type = 4;
......
This diff is collapsed.
...@@ -703,13 +703,13 @@ func request_MemoService_DeleteMemoReaction_0(ctx context.Context, marshaler run ...@@ -703,13 +703,13 @@ func request_MemoService_DeleteMemoReaction_0(ctx context.Context, marshaler run
metadata runtime.ServerMetadata metadata runtime.ServerMetadata
err error err error
) )
val, ok := pathParams["reaction_id"] val, ok := pathParams["id"]
if !ok { if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "reaction_id") return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
} }
protoReq.ReactionId, err = runtime.Int32(val) protoReq.Id, err = runtime.Int32(val)
if err != nil { if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "reaction_id", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
} }
msg, err := client.DeleteMemoReaction(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD)) msg, err := client.DeleteMemoReaction(ctx, &protoReq, grpc.Header(&metadata.HeaderMD), grpc.Trailer(&metadata.TrailerMD))
return msg, metadata, err return msg, metadata, err
...@@ -721,13 +721,13 @@ func local_request_MemoService_DeleteMemoReaction_0(ctx context.Context, marshal ...@@ -721,13 +721,13 @@ func local_request_MemoService_DeleteMemoReaction_0(ctx context.Context, marshal
metadata runtime.ServerMetadata metadata runtime.ServerMetadata
err error err error
) )
val, ok := pathParams["reaction_id"] val, ok := pathParams["id"]
if !ok { if !ok {
return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "reaction_id") return nil, metadata, status.Errorf(codes.InvalidArgument, "missing parameter %s", "id")
} }
protoReq.ReactionId, err = runtime.Int32(val) protoReq.Id, err = runtime.Int32(val)
if err != nil { if err != nil {
return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "reaction_id", err) return nil, metadata, status.Errorf(codes.InvalidArgument, "type mismatch, parameter: %s, error: %v", "id", err)
} }
msg, err := server.DeleteMemoReaction(ctx, &protoReq) msg, err := server.DeleteMemoReaction(ctx, &protoReq)
return msg, metadata, err return msg, metadata, err
...@@ -1065,7 +1065,7 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux ...@@ -1065,7 +1065,7 @@ func RegisterMemoServiceHandlerServer(ctx context.Context, mux *runtime.ServeMux
var stream runtime.ServerTransportStream var stream runtime.ServerTransportStream
ctx = grpc.NewContextWithServerTransportStream(ctx, &stream) ctx = grpc.NewContextWithServerTransportStream(ctx, &stream)
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/DeleteMemoReaction", runtime.WithHTTPPathPattern("/api/v1/reactions/{reaction_id}")) annotatedContext, err := runtime.AnnotateIncomingContext(ctx, mux, req, "/memos.api.v1.MemoService/DeleteMemoReaction", runtime.WithHTTPPathPattern("/api/v1/reactions/{id}"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
...@@ -1395,7 +1395,7 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux ...@@ -1395,7 +1395,7 @@ func RegisterMemoServiceHandlerClient(ctx context.Context, mux *runtime.ServeMux
ctx, cancel := context.WithCancel(req.Context()) ctx, cancel := context.WithCancel(req.Context())
defer cancel() defer cancel()
inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req) inboundMarshaler, outboundMarshaler := runtime.MarshalerForRequest(mux, req)
annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/DeleteMemoReaction", runtime.WithHTTPPathPattern("/api/v1/reactions/{reaction_id}")) annotatedContext, err := runtime.AnnotateContext(ctx, mux, req, "/memos.api.v1.MemoService/DeleteMemoReaction", runtime.WithHTTPPathPattern("/api/v1/reactions/{id}"))
if err != nil { if err != nil {
runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err) runtime.HTTPError(ctx, mux, outboundMarshaler, w, req, err)
return return
...@@ -1428,7 +1428,7 @@ var ( ...@@ -1428,7 +1428,7 @@ var (
pattern_MemoService_ListMemoComments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "comments"}, "")) pattern_MemoService_ListMemoComments_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "comments"}, ""))
pattern_MemoService_ListMemoReactions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, "")) pattern_MemoService_ListMemoReactions_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, ""))
pattern_MemoService_UpsertMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, "")) pattern_MemoService_UpsertMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 2, 5, 3, 2, 4}, []string{"api", "v1", "memos", "name", "reactions"}, ""))
pattern_MemoService_DeleteMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "reactions", "reaction_id"}, "")) pattern_MemoService_DeleteMemoReaction_0 = runtime.MustPattern(runtime.NewPattern(1, []int{2, 0, 2, 1, 2, 2, 1, 0, 4, 1, 5, 3}, []string{"api", "v1", "reactions", "id"}, ""))
) )
var ( var (
......
...@@ -26,6 +26,8 @@ type Reaction struct { ...@@ -26,6 +26,8 @@ type Reaction struct {
// The name of the creator. // The name of the creator.
// Format: users/{user} // 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"`
// The content identifier.
// For memo, it should be the `Memo.name`.
ContentId string `protobuf:"bytes,3,opt,name=content_id,json=contentId,proto3" json:"content_id,omitempty"` ContentId string `protobuf:"bytes,3,opt,name=content_id,json=contentId,proto3" json:"content_id,omitempty"`
ReactionType string `protobuf:"bytes,4,opt,name=reaction_type,json=reactionType,proto3" json:"reaction_type,omitempty"` ReactionType string `protobuf:"bytes,4,opt,name=reaction_type,json=reactionType,proto3" json:"reaction_type,omitempty"`
unknownFields protoimpl.UnknownFields unknownFields protoimpl.UnknownFields
......
...@@ -367,7 +367,7 @@ paths: ...@@ -367,7 +367,7 @@ paths:
type: string type: string
tags: tags:
- MemoService - MemoService
/api/v1/reactions/{reactionId}: /api/v1/reactions/{id}:
delete: delete:
summary: DeleteMemoReaction deletes a reaction for a memo. summary: DeleteMemoReaction deletes a reaction for a memo.
operationId: MemoService_DeleteMemoReaction operationId: MemoService_DeleteMemoReaction
...@@ -382,7 +382,10 @@ paths: ...@@ -382,7 +382,10 @@ paths:
schema: schema:
$ref: '#/definitions/googlerpcStatus' $ref: '#/definitions/googlerpcStatus'
parameters: parameters:
- name: reactionId - name: id
description: |-
The id of the reaction.
Refer to the `Reaction.id`.
in: path in: path
required: true required: true
type: integer type: integer
...@@ -2911,6 +2914,9 @@ definitions: ...@@ -2911,6 +2914,9 @@ definitions:
Format: users/{user} Format: users/{user}
contentId: contentId:
type: string type: string
description: |-
The content identifier.
For memo, it should be the `Memo.name`.
reactionType: reactionType:
type: string type: string
v1ReferencedContentNode: v1ReferencedContentNode:
......
...@@ -56,7 +56,7 @@ func (s *APIV1Service) UpsertMemoReaction(ctx context.Context, request *v1pb.Ups ...@@ -56,7 +56,7 @@ func (s *APIV1Service) UpsertMemoReaction(ctx context.Context, request *v1pb.Ups
func (s *APIV1Service) DeleteMemoReaction(ctx context.Context, request *v1pb.DeleteMemoReactionRequest) (*emptypb.Empty, error) { func (s *APIV1Service) DeleteMemoReaction(ctx context.Context, request *v1pb.DeleteMemoReactionRequest) (*emptypb.Empty, error) {
if err := s.Store.DeleteReaction(ctx, &store.DeleteReaction{ if err := s.Store.DeleteReaction(ctx, &store.DeleteReaction{
ID: request.ReactionId, ID: request.Id,
}); err != nil { }); err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete reaction") return nil, status.Errorf(codes.Internal, "failed to delete reaction")
} }
......
...@@ -41,7 +41,7 @@ const ReactionSelector = (props: Props) => { ...@@ -41,7 +41,7 @@ const ReactionSelector = (props: Props) => {
(reaction) => reaction.reactionType === reactionType && reaction.creator === currentUser.name, (reaction) => reaction.reactionType === reactionType && reaction.creator === currentUser.name,
); );
for (const reaction of reactions) { for (const reaction of reactions) {
await memoServiceClient.deleteMemoReaction({ reactionId: reaction.id }); await memoServiceClient.deleteMemoReaction({ id: reaction.id });
} }
} else { } else {
await memoServiceClient.upsertMemoReaction({ await memoServiceClient.upsertMemoReaction({
......
...@@ -55,7 +55,7 @@ const ReactionView = (props: Props) => { ...@@ -55,7 +55,7 @@ const ReactionView = (props: Props) => {
(reaction) => reaction.reactionType === reactionType && reaction.creator === currentUser.name, (reaction) => reaction.reactionType === reactionType && reaction.creator === currentUser.name,
); );
for (const reaction of reactions) { for (const reaction of reactions) {
await memoServiceClient.deleteMemoReaction({ reactionId: reaction.id }); await memoServiceClient.deleteMemoReaction({ id: reaction.id });
} }
} }
} catch (error) { } catch (error) {
......
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