chore: tweak shortcut service response

This commit is contained in:
johnnyjoy 2024-08-17 21:18:43 +08:00
parent da94907913
commit c356bc03e5
7 changed files with 433 additions and 886 deletions

View File

@ -26,12 +26,9 @@ const useShortcutStore = create(
return shortcuts;
},
fetchShortcutByName: async (name: string) => {
const { shortcut } = await shortcutServiceClient.getShortcutByName({
const shortcut = await shortcutServiceClient.getShortcutByName({
name,
});
if (!shortcut) {
throw new Error(`Shortcut with name ${name} not found`);
}
return shortcut;
},
getOrFetchShortcutById: async (id: number) => {
@ -40,13 +37,9 @@ const useShortcutStore = create(
return shortcutMap[id] as Shortcut;
}
const { shortcut } = await shortcutServiceClient.getShortcut({
const shortcut = await shortcutServiceClient.getShortcut({
id,
});
if (!shortcut) {
throw new Error(`Shortcut with id ${id} not found`);
}
shortcutMap[id] = shortcut;
set({ shortcutMapById: shortcutMap });
return shortcut;
@ -59,25 +52,19 @@ const useShortcutStore = create(
return Object.values(get().shortcutMapById);
},
createShortcut: async (shortcut: Shortcut) => {
const { shortcut: createdShortcut } = await shortcutServiceClient.createShortcut({
const createdShortcut = await shortcutServiceClient.createShortcut({
shortcut: shortcut,
});
if (!createdShortcut) {
throw new Error(`Failed to create shortcut`);
}
const shortcutMap = get().shortcutMapById;
shortcutMap[createdShortcut.id] = createdShortcut;
set({ shortcutMapById: shortcutMap });
return createdShortcut;
},
updateShortcut: async (shortcut: Partial<Shortcut>, updateMask: string[]) => {
const { shortcut: updatedShortcut } = await shortcutServiceClient.updateShortcut({
const updatedShortcut = await shortcutServiceClient.updateShortcut({
shortcut: shortcut,
updateMask,
});
if (!updatedShortcut) {
throw new Error(`Failed to update shortcut`);
}
const shortcutMap = get().shortcutMapById;
shortcutMap[updatedShortcut.id] = updatedShortcut;
set({ shortcutMapById: shortcutMap });

View File

@ -5,6 +5,7 @@ package slash.api.v1;
import "api/v1/common.proto";
import "google/api/annotations.proto";
import "google/api/client.proto";
import "google/protobuf/empty.proto";
import "google/protobuf/field_mask.proto";
import "google/protobuf/timestamp.proto";
@ -16,21 +17,21 @@ service ShortcutService {
option (google.api.http) = {get: "/api/v1/shortcuts"};
}
// GetShortcut returns a shortcut by id.
rpc GetShortcut(GetShortcutRequest) returns (GetShortcutResponse) {
rpc GetShortcut(GetShortcutRequest) returns (Shortcut) {
option (google.api.http) = {get: "/api/v1/shortcuts/{id}"};
option (google.api.method_signature) = "id";
}
// GetShortcutByName returns a shortcut by name.
rpc GetShortcutByName(GetShortcutByNameRequest) returns (GetShortcutByNameResponse) {}
rpc GetShortcutByName(GetShortcutByNameRequest) returns (Shortcut) {}
// CreateShortcut creates a shortcut.
rpc CreateShortcut(CreateShortcutRequest) returns (CreateShortcutResponse) {
rpc CreateShortcut(CreateShortcutRequest) returns (Shortcut) {
option (google.api.http) = {
post: "/api/v1/shortcuts"
body: "shortcut"
};
}
// UpdateShortcut updates a shortcut.
rpc UpdateShortcut(UpdateShortcutRequest) returns (UpdateShortcutResponse) {
rpc UpdateShortcut(UpdateShortcutRequest) returns (Shortcut) {
option (google.api.http) = {
put: "/api/v1/shortcuts/{shortcut.id}"
body: "shortcut"
@ -38,7 +39,7 @@ service ShortcutService {
option (google.api.method_signature) = "shortcut,update_mask";
}
// DeleteShortcut deletes a shortcut by name.
rpc DeleteShortcut(DeleteShortcutRequest) returns (DeleteShortcutResponse) {
rpc DeleteShortcut(DeleteShortcutRequest) returns (google.protobuf.Empty) {
option (google.api.http) = {delete: "/api/v1/shortcuts/{id}"};
option (google.api.method_signature) = "id";
}
@ -75,15 +76,16 @@ message Shortcut {
int32 view_count = 12;
OpenGraphMetadata og_metadata = 13;
message OpenGraphMetadata {
string title = 1;
string description = 2;
string image = 3;
}
}
message OpenGraphMetadata {
string title = 1;
string description = 2;
string image = 3;
}
message ListShortcutsRequest {}
@ -95,42 +97,24 @@ message GetShortcutRequest {
int32 id = 1;
}
message GetShortcutResponse {
Shortcut shortcut = 1;
}
message GetShortcutByNameRequest {
string name = 1;
}
message GetShortcutByNameResponse {
Shortcut shortcut = 1;
}
message CreateShortcutRequest {
Shortcut shortcut = 1;
}
message CreateShortcutResponse {
Shortcut shortcut = 1;
}
message UpdateShortcutRequest {
Shortcut shortcut = 1;
google.protobuf.FieldMask update_mask = 2;
}
message UpdateShortcutResponse {
Shortcut shortcut = 1;
}
message DeleteShortcutRequest {
int32 id = 1;
}
message DeleteShortcutResponse {}
message GetShortcutAnalyticsRequest {
int32 id = 1;
}

View File

@ -59,22 +59,17 @@
- [api/v1/shortcut_service.proto](#api_v1_shortcut_service-proto)
- [CreateShortcutRequest](#slash-api-v1-CreateShortcutRequest)
- [CreateShortcutResponse](#slash-api-v1-CreateShortcutResponse)
- [DeleteShortcutRequest](#slash-api-v1-DeleteShortcutRequest)
- [DeleteShortcutResponse](#slash-api-v1-DeleteShortcutResponse)
- [GetShortcutAnalyticsRequest](#slash-api-v1-GetShortcutAnalyticsRequest)
- [GetShortcutAnalyticsResponse](#slash-api-v1-GetShortcutAnalyticsResponse)
- [GetShortcutAnalyticsResponse.AnalyticsItem](#slash-api-v1-GetShortcutAnalyticsResponse-AnalyticsItem)
- [GetShortcutByNameRequest](#slash-api-v1-GetShortcutByNameRequest)
- [GetShortcutByNameResponse](#slash-api-v1-GetShortcutByNameResponse)
- [GetShortcutRequest](#slash-api-v1-GetShortcutRequest)
- [GetShortcutResponse](#slash-api-v1-GetShortcutResponse)
- [ListShortcutsRequest](#slash-api-v1-ListShortcutsRequest)
- [ListShortcutsResponse](#slash-api-v1-ListShortcutsResponse)
- [OpenGraphMetadata](#slash-api-v1-OpenGraphMetadata)
- [Shortcut](#slash-api-v1-Shortcut)
- [Shortcut.OpenGraphMetadata](#slash-api-v1-Shortcut-OpenGraphMetadata)
- [UpdateShortcutRequest](#slash-api-v1-UpdateShortcutRequest)
- [UpdateShortcutResponse](#slash-api-v1-UpdateShortcutResponse)
- [ShortcutService](#slash-api-v1-ShortcutService)
@ -824,21 +819,6 @@
<a name="slash-api-v1-CreateShortcutResponse"></a>
### CreateShortcutResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| shortcut | [Shortcut](#slash-api-v1-Shortcut) | | |
<a name="slash-api-v1-DeleteShortcutRequest"></a>
### DeleteShortcutRequest
@ -854,16 +834,6 @@
<a name="slash-api-v1-DeleteShortcutResponse"></a>
### DeleteShortcutResponse
<a name="slash-api-v1-GetShortcutAnalyticsRequest"></a>
### GetShortcutAnalyticsRequest
@ -927,21 +897,6 @@
<a name="slash-api-v1-GetShortcutByNameResponse"></a>
### GetShortcutByNameResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| shortcut | [Shortcut](#slash-api-v1-Shortcut) | | |
<a name="slash-api-v1-GetShortcutRequest"></a>
### GetShortcutRequest
@ -957,21 +912,6 @@
<a name="slash-api-v1-GetShortcutResponse"></a>
### GetShortcutResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| shortcut | [Shortcut](#slash-api-v1-Shortcut) | | |
<a name="slash-api-v1-ListShortcutsRequest"></a>
### ListShortcutsRequest
@ -997,23 +937,6 @@
<a name="slash-api-v1-OpenGraphMetadata"></a>
### OpenGraphMetadata
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| title | [string](#string) | | |
| description | [string](#string) | | |
| image | [string](#string) | | |
<a name="slash-api-v1-Shortcut"></a>
### Shortcut
@ -1034,7 +957,24 @@
| description | [string](#string) | | |
| visibility | [Visibility](#slash-api-v1-Visibility) | | |
| view_count | [int32](#int32) | | |
| og_metadata | [OpenGraphMetadata](#slash-api-v1-OpenGraphMetadata) | | |
| og_metadata | [Shortcut.OpenGraphMetadata](#slash-api-v1-Shortcut-OpenGraphMetadata) | | |
<a name="slash-api-v1-Shortcut-OpenGraphMetadata"></a>
### Shortcut.OpenGraphMetadata
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| title | [string](#string) | | |
| description | [string](#string) | | |
| image | [string](#string) | | |
@ -1056,21 +996,6 @@
<a name="slash-api-v1-UpdateShortcutResponse"></a>
### UpdateShortcutResponse
| Field | Type | Label | Description |
| ----- | ---- | ----- | ----------- |
| shortcut | [Shortcut](#slash-api-v1-Shortcut) | | |
@ -1086,11 +1011,11 @@
| Method Name | Request Type | Response Type | Description |
| ----------- | ------------ | ------------- | ------------|
| ListShortcuts | [ListShortcutsRequest](#slash-api-v1-ListShortcutsRequest) | [ListShortcutsResponse](#slash-api-v1-ListShortcutsResponse) | ListShortcuts returns a list of shortcuts. |
| GetShortcut | [GetShortcutRequest](#slash-api-v1-GetShortcutRequest) | [GetShortcutResponse](#slash-api-v1-GetShortcutResponse) | GetShortcut returns a shortcut by id. |
| GetShortcutByName | [GetShortcutByNameRequest](#slash-api-v1-GetShortcutByNameRequest) | [GetShortcutByNameResponse](#slash-api-v1-GetShortcutByNameResponse) | GetShortcutByName returns a shortcut by name. |
| CreateShortcut | [CreateShortcutRequest](#slash-api-v1-CreateShortcutRequest) | [CreateShortcutResponse](#slash-api-v1-CreateShortcutResponse) | CreateShortcut creates a shortcut. |
| UpdateShortcut | [UpdateShortcutRequest](#slash-api-v1-UpdateShortcutRequest) | [UpdateShortcutResponse](#slash-api-v1-UpdateShortcutResponse) | UpdateShortcut updates a shortcut. |
| DeleteShortcut | [DeleteShortcutRequest](#slash-api-v1-DeleteShortcutRequest) | [DeleteShortcutResponse](#slash-api-v1-DeleteShortcutResponse) | DeleteShortcut deletes a shortcut by name. |
| GetShortcut | [GetShortcutRequest](#slash-api-v1-GetShortcutRequest) | [Shortcut](#slash-api-v1-Shortcut) | GetShortcut returns a shortcut by id. |
| GetShortcutByName | [GetShortcutByNameRequest](#slash-api-v1-GetShortcutByNameRequest) | [Shortcut](#slash-api-v1-Shortcut) | GetShortcutByName returns a shortcut by name. |
| CreateShortcut | [CreateShortcutRequest](#slash-api-v1-CreateShortcutRequest) | [Shortcut](#slash-api-v1-Shortcut) | CreateShortcut creates a shortcut. |
| UpdateShortcut | [UpdateShortcutRequest](#slash-api-v1-UpdateShortcutRequest) | [Shortcut](#slash-api-v1-Shortcut) | UpdateShortcut updates a shortcut. |
| DeleteShortcut | [DeleteShortcutRequest](#slash-api-v1-DeleteShortcutRequest) | [.google.protobuf.Empty](#google-protobuf-Empty) | DeleteShortcut deletes a shortcut by name. |
| GetShortcutAnalytics | [GetShortcutAnalyticsRequest](#slash-api-v1-GetShortcutAnalyticsRequest) | [GetShortcutAnalyticsResponse](#slash-api-v1-GetShortcutAnalyticsResponse) | GetShortcutAnalytics returns the analytics for a shortcut. |

File diff suppressed because it is too large Load Diff

View File

@ -11,6 +11,7 @@ import (
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
emptypb "google.golang.org/protobuf/types/known/emptypb"
)
// This is a compile-time assertion to ensure that this generated file
@ -35,15 +36,15 @@ type ShortcutServiceClient interface {
// ListShortcuts returns a list of shortcuts.
ListShortcuts(ctx context.Context, in *ListShortcutsRequest, opts ...grpc.CallOption) (*ListShortcutsResponse, error)
// GetShortcut returns a shortcut by id.
GetShortcut(ctx context.Context, in *GetShortcutRequest, opts ...grpc.CallOption) (*GetShortcutResponse, error)
GetShortcut(ctx context.Context, in *GetShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error)
// GetShortcutByName returns a shortcut by name.
GetShortcutByName(ctx context.Context, in *GetShortcutByNameRequest, opts ...grpc.CallOption) (*GetShortcutByNameResponse, error)
GetShortcutByName(ctx context.Context, in *GetShortcutByNameRequest, opts ...grpc.CallOption) (*Shortcut, error)
// CreateShortcut creates a shortcut.
CreateShortcut(ctx context.Context, in *CreateShortcutRequest, opts ...grpc.CallOption) (*CreateShortcutResponse, error)
CreateShortcut(ctx context.Context, in *CreateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error)
// UpdateShortcut updates a shortcut.
UpdateShortcut(ctx context.Context, in *UpdateShortcutRequest, opts ...grpc.CallOption) (*UpdateShortcutResponse, error)
UpdateShortcut(ctx context.Context, in *UpdateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error)
// DeleteShortcut deletes a shortcut by name.
DeleteShortcut(ctx context.Context, in *DeleteShortcutRequest, opts ...grpc.CallOption) (*DeleteShortcutResponse, error)
DeleteShortcut(ctx context.Context, in *DeleteShortcutRequest, opts ...grpc.CallOption) (*emptypb.Empty, error)
// GetShortcutAnalytics returns the analytics for a shortcut.
GetShortcutAnalytics(ctx context.Context, in *GetShortcutAnalyticsRequest, opts ...grpc.CallOption) (*GetShortcutAnalyticsResponse, error)
}
@ -66,9 +67,9 @@ func (c *shortcutServiceClient) ListShortcuts(ctx context.Context, in *ListShort
return out, nil
}
func (c *shortcutServiceClient) GetShortcut(ctx context.Context, in *GetShortcutRequest, opts ...grpc.CallOption) (*GetShortcutResponse, error) {
func (c *shortcutServiceClient) GetShortcut(ctx context.Context, in *GetShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetShortcutResponse)
out := new(Shortcut)
err := c.cc.Invoke(ctx, ShortcutService_GetShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
@ -76,9 +77,9 @@ func (c *shortcutServiceClient) GetShortcut(ctx context.Context, in *GetShortcut
return out, nil
}
func (c *shortcutServiceClient) GetShortcutByName(ctx context.Context, in *GetShortcutByNameRequest, opts ...grpc.CallOption) (*GetShortcutByNameResponse, error) {
func (c *shortcutServiceClient) GetShortcutByName(ctx context.Context, in *GetShortcutByNameRequest, opts ...grpc.CallOption) (*Shortcut, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(GetShortcutByNameResponse)
out := new(Shortcut)
err := c.cc.Invoke(ctx, ShortcutService_GetShortcutByName_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
@ -86,9 +87,9 @@ func (c *shortcutServiceClient) GetShortcutByName(ctx context.Context, in *GetSh
return out, nil
}
func (c *shortcutServiceClient) CreateShortcut(ctx context.Context, in *CreateShortcutRequest, opts ...grpc.CallOption) (*CreateShortcutResponse, error) {
func (c *shortcutServiceClient) CreateShortcut(ctx context.Context, in *CreateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(CreateShortcutResponse)
out := new(Shortcut)
err := c.cc.Invoke(ctx, ShortcutService_CreateShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
@ -96,9 +97,9 @@ func (c *shortcutServiceClient) CreateShortcut(ctx context.Context, in *CreateSh
return out, nil
}
func (c *shortcutServiceClient) UpdateShortcut(ctx context.Context, in *UpdateShortcutRequest, opts ...grpc.CallOption) (*UpdateShortcutResponse, error) {
func (c *shortcutServiceClient) UpdateShortcut(ctx context.Context, in *UpdateShortcutRequest, opts ...grpc.CallOption) (*Shortcut, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(UpdateShortcutResponse)
out := new(Shortcut)
err := c.cc.Invoke(ctx, ShortcutService_UpdateShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
@ -106,9 +107,9 @@ func (c *shortcutServiceClient) UpdateShortcut(ctx context.Context, in *UpdateSh
return out, nil
}
func (c *shortcutServiceClient) DeleteShortcut(ctx context.Context, in *DeleteShortcutRequest, opts ...grpc.CallOption) (*DeleteShortcutResponse, error) {
func (c *shortcutServiceClient) DeleteShortcut(ctx context.Context, in *DeleteShortcutRequest, opts ...grpc.CallOption) (*emptypb.Empty, error) {
cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...)
out := new(DeleteShortcutResponse)
out := new(emptypb.Empty)
err := c.cc.Invoke(ctx, ShortcutService_DeleteShortcut_FullMethodName, in, out, cOpts...)
if err != nil {
return nil, err
@ -133,15 +134,15 @@ type ShortcutServiceServer interface {
// ListShortcuts returns a list of shortcuts.
ListShortcuts(context.Context, *ListShortcutsRequest) (*ListShortcutsResponse, error)
// GetShortcut returns a shortcut by id.
GetShortcut(context.Context, *GetShortcutRequest) (*GetShortcutResponse, error)
GetShortcut(context.Context, *GetShortcutRequest) (*Shortcut, error)
// GetShortcutByName returns a shortcut by name.
GetShortcutByName(context.Context, *GetShortcutByNameRequest) (*GetShortcutByNameResponse, error)
GetShortcutByName(context.Context, *GetShortcutByNameRequest) (*Shortcut, error)
// CreateShortcut creates a shortcut.
CreateShortcut(context.Context, *CreateShortcutRequest) (*CreateShortcutResponse, error)
CreateShortcut(context.Context, *CreateShortcutRequest) (*Shortcut, error)
// UpdateShortcut updates a shortcut.
UpdateShortcut(context.Context, *UpdateShortcutRequest) (*UpdateShortcutResponse, error)
UpdateShortcut(context.Context, *UpdateShortcutRequest) (*Shortcut, error)
// DeleteShortcut deletes a shortcut by name.
DeleteShortcut(context.Context, *DeleteShortcutRequest) (*DeleteShortcutResponse, error)
DeleteShortcut(context.Context, *DeleteShortcutRequest) (*emptypb.Empty, error)
// GetShortcutAnalytics returns the analytics for a shortcut.
GetShortcutAnalytics(context.Context, *GetShortcutAnalyticsRequest) (*GetShortcutAnalyticsResponse, error)
mustEmbedUnimplementedShortcutServiceServer()
@ -157,19 +158,19 @@ type UnimplementedShortcutServiceServer struct{}
func (UnimplementedShortcutServiceServer) ListShortcuts(context.Context, *ListShortcutsRequest) (*ListShortcutsResponse, error) {
return nil, status.Errorf(codes.Unimplemented, "method ListShortcuts not implemented")
}
func (UnimplementedShortcutServiceServer) GetShortcut(context.Context, *GetShortcutRequest) (*GetShortcutResponse, error) {
func (UnimplementedShortcutServiceServer) GetShortcut(context.Context, *GetShortcutRequest) (*Shortcut, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetShortcut not implemented")
}
func (UnimplementedShortcutServiceServer) GetShortcutByName(context.Context, *GetShortcutByNameRequest) (*GetShortcutByNameResponse, error) {
func (UnimplementedShortcutServiceServer) GetShortcutByName(context.Context, *GetShortcutByNameRequest) (*Shortcut, error) {
return nil, status.Errorf(codes.Unimplemented, "method GetShortcutByName not implemented")
}
func (UnimplementedShortcutServiceServer) CreateShortcut(context.Context, *CreateShortcutRequest) (*CreateShortcutResponse, error) {
func (UnimplementedShortcutServiceServer) CreateShortcut(context.Context, *CreateShortcutRequest) (*Shortcut, error) {
return nil, status.Errorf(codes.Unimplemented, "method CreateShortcut not implemented")
}
func (UnimplementedShortcutServiceServer) UpdateShortcut(context.Context, *UpdateShortcutRequest) (*UpdateShortcutResponse, error) {
func (UnimplementedShortcutServiceServer) UpdateShortcut(context.Context, *UpdateShortcutRequest) (*Shortcut, error) {
return nil, status.Errorf(codes.Unimplemented, "method UpdateShortcut not implemented")
}
func (UnimplementedShortcutServiceServer) DeleteShortcut(context.Context, *DeleteShortcutRequest) (*DeleteShortcutResponse, error) {
func (UnimplementedShortcutServiceServer) DeleteShortcut(context.Context, *DeleteShortcutRequest) (*emptypb.Empty, error) {
return nil, status.Errorf(codes.Unimplemented, "method DeleteShortcut not implemented")
}
func (UnimplementedShortcutServiceServer) GetShortcutAnalytics(context.Context, *GetShortcutAnalyticsRequest) (*GetShortcutAnalyticsResponse, error) {

View File

@ -280,7 +280,7 @@ paths:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1CreateShortcutResponse'
$ref: '#/definitions/apiv1Shortcut'
default:
description: An unexpected error response.
schema:
@ -301,7 +301,7 @@ paths:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1GetShortcutResponse'
$ref: '#/definitions/apiv1Shortcut'
default:
description: An unexpected error response.
schema:
@ -321,7 +321,8 @@ paths:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1DeleteShortcutResponse'
type: object
properties: {}
default:
description: An unexpected error response.
schema:
@ -363,7 +364,7 @@ paths:
"200":
description: A successful response.
schema:
$ref: '#/definitions/v1UpdateShortcutResponse'
$ref: '#/definitions/apiv1Shortcut'
default:
description: An unexpected error response.
schema:
@ -409,7 +410,7 @@ paths:
type: integer
format: int32
ogMetadata:
$ref: '#/definitions/apiv1OpenGraphMetadata'
$ref: '#/definitions/v1ShortcutOpenGraphMetadata'
- name: updateMask
in: query
required: false
@ -851,15 +852,6 @@ definitions:
- TYPE_UNSPECIFIED
- OAUTH2
default: TYPE_UNSPECIFIED
apiv1OpenGraphMetadata:
type: object
properties:
title:
type: string
description:
type: string
image:
type: string
apiv1RowStatus:
type: string
enum:
@ -902,7 +894,7 @@ definitions:
type: integer
format: int32
ogMetadata:
$ref: '#/definitions/apiv1OpenGraphMetadata'
$ref: '#/definitions/v1ShortcutOpenGraphMetadata'
apiv1UserSetting:
type: object
properties:
@ -995,11 +987,6 @@ definitions:
properties:
collection:
$ref: '#/definitions/apiv1Collection'
v1CreateShortcutResponse:
type: object
properties:
shortcut:
$ref: '#/definitions/apiv1Shortcut'
v1CreateUserAccessTokenResponse:
type: object
properties:
@ -1012,8 +999,6 @@ definitions:
$ref: '#/definitions/v1User'
v1DeleteCollectionResponse:
type: object
v1DeleteShortcutResponse:
type: object
v1DeleteUserAccessTokenResponse:
type: object
v1DeleteUserResponse:
@ -1046,16 +1031,6 @@ definitions:
items:
type: object
$ref: '#/definitions/GetShortcutAnalyticsResponseAnalyticsItem'
v1GetShortcutByNameResponse:
type: object
properties:
shortcut:
$ref: '#/definitions/apiv1Shortcut'
v1GetShortcutResponse:
type: object
properties:
shortcut:
$ref: '#/definitions/apiv1Shortcut'
v1GetUserResponse:
type: object
properties:
@ -1113,6 +1088,15 @@ definitions:
- ADMIN
- USER
default: ROLE_UNSPECIFIED
v1ShortcutOpenGraphMetadata:
type: object
properties:
title:
type: string
description:
type: string
image:
type: string
v1Subscription:
type: object
properties:
@ -1149,11 +1133,6 @@ definitions:
properties:
collection:
$ref: '#/definitions/apiv1Collection'
v1UpdateShortcutResponse:
type: object
properties:
shortcut:
$ref: '#/definitions/apiv1Shortcut'
v1UpdateSubscriptionRequest:
type: object
properties:

View File

@ -14,6 +14,7 @@ import (
"google.golang.org/grpc/peer"
"google.golang.org/grpc/status"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/types/known/emptypb"
"google.golang.org/protobuf/types/known/timestamppb"
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
@ -58,7 +59,7 @@ func (s *APIV1Service) ListShortcuts(ctx context.Context, _ *v1pb.ListShortcutsR
return response, nil
}
func (s *APIV1Service) GetShortcut(ctx context.Context, request *v1pb.GetShortcutRequest) (*v1pb.GetShortcutResponse, error) {
func (s *APIV1Service) GetShortcut(ctx context.Context, request *v1pb.GetShortcutRequest) (*v1pb.Shortcut, error) {
shortcut, err := s.Store.GetShortcut(ctx, &store.FindShortcut{
ID: &request.Id,
})
@ -84,13 +85,10 @@ func (s *APIV1Service) GetShortcut(ctx context.Context, request *v1pb.GetShortcu
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err)
}
response := &v1pb.GetShortcutResponse{
Shortcut: composedShortcut,
}
return response, nil
return composedShortcut, nil
}
func (s *APIV1Service) GetShortcutByName(ctx context.Context, request *v1pb.GetShortcutByNameRequest) (*v1pb.GetShortcutByNameResponse, error) {
func (s *APIV1Service) GetShortcutByName(ctx context.Context, request *v1pb.GetShortcutByNameRequest) (*v1pb.Shortcut, error) {
shortcut, err := s.Store.GetShortcut(ctx, &store.FindShortcut{
Name: &request.Name,
})
@ -121,13 +119,10 @@ func (s *APIV1Service) GetShortcutByName(ctx context.Context, request *v1pb.GetS
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err)
}
response := &v1pb.GetShortcutByNameResponse{
Shortcut: composedShortcut,
}
return response, nil
return composedShortcut, nil
}
func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateShortcutRequest) (*v1pb.CreateShortcutResponse, error) {
func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateShortcutRequest) (*v1pb.Shortcut, error) {
if request.Shortcut.Name == "" || request.Shortcut.Link == "" {
return nil, status.Errorf(codes.InvalidArgument, "name and link are required")
}
@ -187,14 +182,11 @@ func (s *APIV1Service) CreateShortcut(ctx context.Context, request *v1pb.CreateS
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err)
}
response := &v1pb.CreateShortcutResponse{
Shortcut: composedShortcut,
}
metric.Enqueue("shortcut create")
return response, nil
return composedShortcut, nil
}
func (s *APIV1Service) UpdateShortcut(ctx context.Context, request *v1pb.UpdateShortcutRequest) (*v1pb.UpdateShortcutResponse, error) {
func (s *APIV1Service) UpdateShortcut(ctx context.Context, request *v1pb.UpdateShortcutRequest) (*v1pb.Shortcut, error) {
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
return nil, status.Errorf(codes.InvalidArgument, "updateMask is required")
}
@ -254,13 +246,10 @@ func (s *APIV1Service) UpdateShortcut(ctx context.Context, request *v1pb.UpdateS
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to convert shortcut, err: %v", err)
}
response := &v1pb.UpdateShortcutResponse{
Shortcut: composedShortcut,
}
return response, nil
return composedShortcut, nil
}
func (s *APIV1Service) DeleteShortcut(ctx context.Context, request *v1pb.DeleteShortcutRequest) (*v1pb.DeleteShortcutResponse, error) {
func (s *APIV1Service) DeleteShortcut(ctx context.Context, request *v1pb.DeleteShortcutRequest) (*emptypb.Empty, error) {
user, err := getCurrentUser(ctx, s.Store)
if err != nil {
return nil, status.Errorf(codes.Unauthenticated, "failed to get current user: %v", err)
@ -284,8 +273,7 @@ func (s *APIV1Service) DeleteShortcut(ctx context.Context, request *v1pb.DeleteS
if err != nil {
return nil, status.Errorf(codes.Internal, "failed to delete shortcut, err: %v", err)
}
response := &v1pb.DeleteShortcutResponse{}
return response, nil
return &emptypb.Empty{}, nil
}
func (s *APIV1Service) GetShortcutAnalytics(ctx context.Context, request *v1pb.GetShortcutAnalyticsRequest) (*v1pb.GetShortcutAnalyticsResponse, error) {
@ -427,7 +415,7 @@ func (s *APIV1Service) convertShortcutFromStorepb(ctx context.Context, shortcut
Tags: shortcut.Tags,
Description: shortcut.Description,
Visibility: v1pb.Visibility(shortcut.Visibility),
OgMetadata: &v1pb.OpenGraphMetadata{
OgMetadata: &v1pb.Shortcut_OpenGraphMetadata{
Title: shortcut.OgMetadata.Title,
Description: shortcut.OgMetadata.Description,
Image: shortcut.OgMetadata.Image,