Commit 5ff8ab9a authored by Steven's avatar Steven

chore: polish creator definition

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