Commit 5ff8ab9a authored by Steven's avatar Steven

chore: polish creator definition

parent 8b7e9f54
......@@ -21,8 +21,9 @@ message Activity {
// The name of the activity.
// Format: activities/{id}
string name = 1;
// The uid of the user who created the activity.
int32 creator_id = 2;
// The name of the creator.
// Format: users/{user}
string creator = 2;
// The type of the activity.
string type = 3;
// The level of the activity.
......
......@@ -46,7 +46,9 @@ service WebhookService {
message Webhook {
int32 id = 1;
int32 creator_id = 2;
// The name of the creator.
// Format: users/{user}
string creator = 2;
google.protobuf.Timestamp create_time = 3;
......@@ -68,7 +70,9 @@ message GetWebhookRequest {
}
message ListWebhooksRequest {
int32 creator_id = 1;
// The name of the creator.
// Format: users/{user}
string creator = 2;
}
message ListWebhooksResponse {
......@@ -90,7 +94,9 @@ message WebhookRequestPayload {
string activity_type = 2;
int32 creator_id = 3;
// The name of the creator.
// Format: users/{user}
string creator = 3;
google.protobuf.Timestamp create_time = 4;
......
This diff is collapsed.
This diff is collapsed.
......@@ -531,11 +531,13 @@ paths:
schema:
$ref: '#/definitions/googlerpcStatus'
parameters:
- name: creatorId
- name: creator
description: |-
The name of the creator.
Format: users/{user}
in: query
required: false
type: integer
format: int32
type: string
tags:
- WebhookService
post:
......@@ -625,9 +627,11 @@ paths:
schema:
type: object
properties:
creatorId:
type: integer
format: int32
creator:
type: string
title: |-
The name of the creator.
Format: users/{user}
createTime:
type: string
format: date-time
......@@ -2335,10 +2339,11 @@ definitions:
title: |-
The name of the activity.
Format: activities/{id}
creatorId:
type: integer
format: int32
description: The uid of the user who created the activity.
creator:
type: string
title: |-
The name of the creator.
Format: users/{user}
type:
type: string
description: The type of the activity.
......@@ -3083,9 +3088,11 @@ definitions:
id:
type: integer
format: int32
creatorId:
type: integer
format: int32
creator:
type: string
title: |-
The name of the creator.
Format: users/{user}
createTime:
type: string
format: date-time
......
......@@ -36,7 +36,7 @@ func (s *APIV1Service) GetActivity(ctx context.Context, request *v1pb.GetActivit
func (*APIV1Service) convertActivityFromStore(_ context.Context, activity *store.Activity) (*v1pb.Activity, error) {
return &v1pb.Activity{
Name: fmt.Sprintf("%s%d", ActivityNamePrefix, activity.ID),
CreatorId: activity.CreatorID,
Creator: fmt.Sprintf("%s%d", UserNamePrefix, activity.CreatorID),
Type: activity.Type.String(),
Level: activity.Level.String(),
CreateTime: timestamppb.New(time.Unix(activity.CreatedTs, 0)),
......
......@@ -670,7 +670,7 @@ func convertMemoToWebhookPayload(memo *v1pb.Memo) (*v1pb.WebhookRequestPayload,
return nil, errors.Wrap(err, "invalid memo creator")
}
return &v1pb.WebhookRequestPayload{
CreatorId: creatorID,
Creator: fmt.Sprintf("%s%d", UserNamePrefix, creatorID),
CreateTime: timestamppb.New(time.Now()),
Memo: memo,
}, nil
......
......@@ -2,6 +2,7 @@ package v1
import (
"context"
"fmt"
"time"
"google.golang.org/grpc/codes"
......@@ -31,8 +32,13 @@ func (s *APIV1Service) CreateWebhook(ctx context.Context, request *v1pb.CreateWe
}
func (s *APIV1Service) ListWebhooks(ctx context.Context, request *v1pb.ListWebhooksRequest) (*v1pb.ListWebhooksResponse, error) {
creatorID, err := ExtractUserIDFromName(request.Creator)
if err != nil {
return nil, status.Errorf(codes.InvalidArgument, "invalid creator name: %v", err)
}
webhooks, err := s.Store.ListWebhooks(ctx, &store.FindWebhook{
CreatorID: &request.CreatorId,
CreatorID: &creatorID,
})
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to list webhooks, error: %+v", err)
......@@ -103,7 +109,7 @@ func convertWebhookFromStore(webhook *store.Webhook) *v1pb.Webhook {
Id: webhook.ID,
CreateTime: timestamppb.New(time.Unix(webhook.CreatedTs, 0)),
UpdateTime: timestamppb.New(time.Unix(webhook.UpdatedTs, 0)),
CreatorId: webhook.CreatorID,
Creator: fmt.Sprintf("%s%d", UserNamePrefix, webhook.CreatorID),
Name: webhook.Name,
Url: webhook.URL,
}
......
......@@ -4,14 +4,13 @@ import { useEffect, useState } from "react";
import { Link } from "react-router-dom";
import { webhookServiceClient } from "@/grpcweb";
import useCurrentUser from "@/hooks/useCurrentUser";
import { extractUserIdFromName } from "@/store/v1";
import { Webhook } from "@/types/proto/api/v1/webhook_service";
import { useTranslate } from "@/utils/i18n";
import showCreateWebhookDialog from "../CreateWebhookDialog";
const listWebhooks = async (userId: number) => {
const listWebhooks = async (user: string) => {
const { webhooks } = await webhookServiceClient.listWebhooks({
creatorId: userId,
creator: user,
});
return webhooks;
};
......@@ -22,13 +21,13 @@ const WebhookSection = () => {
const [webhooks, setWebhooks] = useState<Webhook[]>([]);
useEffect(() => {
listWebhooks(extractUserIdFromName(currentUser.name)).then((webhooks) => {
listWebhooks(currentUser.name).then((webhooks) => {
setWebhooks(webhooks);
});
}, []);
const handleCreateAccessTokenDialogConfirm = async () => {
const webhooks = await listWebhooks(extractUserIdFromName(currentUser.name));
const webhooks = await listWebhooks(currentUser.name);
setWebhooks(webhooks);
};
......
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