mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-16 04:13:12 +00:00
chore: fix collection service
This commit is contained in:
parent
8f982c5695
commit
8f608dc522
@ -100,7 +100,9 @@ func (s *APIV2Service) UpdateCollection(ctx context.Context, request *apiv2pb.Up
|
||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||
}
|
||||
|
||||
update := &store.UpdateCollection{}
|
||||
update := &store.UpdateCollection{
|
||||
ID: collection.Id,
|
||||
}
|
||||
for _, path := range request.UpdateMask.Paths {
|
||||
switch path {
|
||||
case "name":
|
||||
@ -112,7 +114,7 @@ func (s *APIV2Service) UpdateCollection(ctx context.Context, request *apiv2pb.Up
|
||||
case "shortcut_ids":
|
||||
update.ShortcutIDs = request.Collection.ShortcutIds
|
||||
case "visibility":
|
||||
visibility := store.Visibility(request.Collection.Visibility)
|
||||
visibility := store.Visibility(request.Collection.Visibility.String())
|
||||
update.Visibility = &visibility
|
||||
}
|
||||
}
|
||||
|
@ -149,7 +149,7 @@ func (s *APIV2Service) UpdateShortcut(ctx context.Context, request *apiv2pb.Upda
|
||||
case "description":
|
||||
update.Description = &request.Shortcut.Description
|
||||
case "visibility":
|
||||
visibility := store.Visibility(request.Shortcut.Visibility)
|
||||
visibility := store.Visibility(request.Shortcut.Visibility.String())
|
||||
update.Visibility = &visibility
|
||||
case "og_metadata":
|
||||
if request.Shortcut.OgMetadata != nil {
|
||||
|
@ -23,6 +23,7 @@ type APIV2Service struct {
|
||||
apiv2pb.UnimplementedUserServiceServer
|
||||
apiv2pb.UnimplementedUserSettingServiceServer
|
||||
apiv2pb.UnimplementedShortcutServiceServer
|
||||
apiv2pb.UnimplementedCollectionServiceServer
|
||||
|
||||
Secret string
|
||||
Profile *profile.Profile
|
||||
@ -54,6 +55,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
|
||||
apiv2pb.RegisterUserServiceServer(grpcServer, apiV2Service)
|
||||
apiv2pb.RegisterUserSettingServiceServer(grpcServer, apiV2Service)
|
||||
apiv2pb.RegisterShortcutServiceServer(grpcServer, apiV2Service)
|
||||
apiv2pb.RegisterCollectionServiceServer(grpcServer, apiV2Service)
|
||||
reflection.Register(grpcServer)
|
||||
|
||||
return apiV2Service
|
||||
@ -92,6 +94,9 @@ func (s *APIV2Service) RegisterGateway(ctx context.Context, e *echo.Echo) error
|
||||
if err := apiv2pb.RegisterShortcutServiceHandler(context.Background(), gwMux, conn); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := apiv2pb.RegisterCollectionServiceHandler(context.Background(), gwMux, conn); err != nil {
|
||||
return err
|
||||
}
|
||||
e.Any("/api/v2/*", echo.WrapHandler(gwMux))
|
||||
|
||||
// GRPC web proxy.
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { createChannel, createClientFactory, FetchTransport } from "nice-grpc-web";
|
||||
import { CollectionServiceDefinition } from "./types/proto/api/v2/collection_service";
|
||||
import { ShortcutServiceDefinition } from "./types/proto/api/v2/shortcut_service";
|
||||
import { SubscriptionServiceDefinition } from "./types/proto/api/v2/subscription_service";
|
||||
import { UserServiceDefinition } from "./types/proto/api/v2/user_service";
|
||||
@ -25,3 +26,5 @@ export const userServiceClient = clientFactory.create(UserServiceDefinition, cha
|
||||
export const userSettingServiceClient = clientFactory.create(UserSettingServiceDefinition, channel);
|
||||
|
||||
export const shortcutServiceClient = clientFactory.create(ShortcutServiceDefinition, channel);
|
||||
|
||||
export const collectionServiceClient = clientFactory.create(CollectionServiceDefinition, channel);
|
||||
|
@ -30,12 +30,15 @@ func TestCollectionStore(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, 1, len(collections))
|
||||
require.Equal(t, collection, collections[0])
|
||||
newTitle := "My new collection"
|
||||
newShortcutIds := []int32{101, 103}
|
||||
updatedCollection, err := ts.UpdateCollection(ctx, &store.UpdateCollection{
|
||||
ID: collection.Id,
|
||||
Title: &newTitle,
|
||||
ShortcutIDs: newShortcutIds,
|
||||
})
|
||||
require.NoError(t, err)
|
||||
require.Equal(t, newTitle, updatedCollection.Title)
|
||||
require.Equal(t, newShortcutIds, updatedCollection.ShortcutIds)
|
||||
err = ts.DeleteCollection(ctx, &store.DeleteCollection{
|
||||
ID: collection.Id,
|
||||
|
Loading…
x
Reference in New Issue
Block a user