diff --git a/api/v2/collection_service.go b/api/v2/collection_service.go index 2f26c42..129dd87 100644 --- a/api/v2/collection_service.go +++ b/api/v2/collection_service.go @@ -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 } } diff --git a/api/v2/shortcut_service.go b/api/v2/shortcut_service.go index c3d6b40..53217a6 100644 --- a/api/v2/shortcut_service.go +++ b/api/v2/shortcut_service.go @@ -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 { diff --git a/api/v2/v2.go b/api/v2/v2.go index 8e33560..bb8cf3c 100644 --- a/api/v2/v2.go +++ b/api/v2/v2.go @@ -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. diff --git a/frontend/web/src/grpcweb.ts b/frontend/web/src/grpcweb.ts index e3ef191..cb60a36 100644 --- a/frontend/web/src/grpcweb.ts +++ b/frontend/web/src/grpcweb.ts @@ -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); diff --git a/test/store/collection_test.go b/test/store/collection_test.go index 01ea466..5c9d5dd 100644 --- a/test/store/collection_test.go +++ b/test/store/collection_test.go @@ -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,