mirror of
https://github.com/aykhans/slash-e.git
synced 2025-07-04 20:28:00 +00:00
chore: tweak collection service response
This commit is contained in:
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
"google.golang.org/protobuf/types/known/emptypb"
|
||||
"google.golang.org/protobuf/types/known/timestamppb"
|
||||
|
||||
v1pb "github.com/yourselfhosted/slash/proto/gen/api/v1"
|
||||
@ -52,7 +53,7 @@ func (s *APIV1Service) ListCollections(ctx context.Context, _ *v1pb.ListCollecti
|
||||
return response, nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) GetCollection(ctx context.Context, request *v1pb.GetCollectionRequest) (*v1pb.GetCollectionResponse, error) {
|
||||
func (s *APIV1Service) GetCollection(ctx context.Context, request *v1pb.GetCollectionRequest) (*v1pb.Collection, error) {
|
||||
collection, err := s.Store.GetCollection(ctx, &store.FindCollection{
|
||||
ID: &request.Id,
|
||||
})
|
||||
@ -70,13 +71,10 @@ func (s *APIV1Service) GetCollection(ctx context.Context, request *v1pb.GetColle
|
||||
if collection.Visibility == storepb.Visibility_PRIVATE && collection.CreatorId != user.ID {
|
||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||
}
|
||||
response := &v1pb.GetCollectionResponse{
|
||||
Collection: convertCollectionFromStore(collection),
|
||||
}
|
||||
return response, nil
|
||||
return convertCollectionFromStore(collection), nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) GetCollectionByName(ctx context.Context, request *v1pb.GetCollectionByNameRequest) (*v1pb.GetCollectionByNameResponse, error) {
|
||||
func (s *APIV1Service) GetCollectionByName(ctx context.Context, request *v1pb.GetCollectionByNameRequest) (*v1pb.Collection, error) {
|
||||
collection, err := s.Store.GetCollection(ctx, &store.FindCollection{
|
||||
Name: &request.Name,
|
||||
})
|
||||
@ -97,13 +95,10 @@ func (s *APIV1Service) GetCollectionByName(ctx context.Context, request *v1pb.Ge
|
||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||
}
|
||||
}
|
||||
response := &v1pb.GetCollectionByNameResponse{
|
||||
Collection: convertCollectionFromStore(collection),
|
||||
}
|
||||
return response, nil
|
||||
return convertCollectionFromStore(collection), nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) CreateCollection(ctx context.Context, request *v1pb.CreateCollectionRequest) (*v1pb.CreateCollectionResponse, error) {
|
||||
func (s *APIV1Service) CreateCollection(ctx context.Context, request *v1pb.CreateCollectionRequest) (*v1pb.Collection, error) {
|
||||
if request.Collection.Name == "" || request.Collection.Title == "" {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "name and title are required")
|
||||
}
|
||||
@ -136,14 +131,11 @@ func (s *APIV1Service) CreateCollection(ctx context.Context, request *v1pb.Creat
|
||||
return nil, status.Errorf(codes.Internal, "failed to create collection, err: %v", err)
|
||||
}
|
||||
|
||||
response := &v1pb.CreateCollectionResponse{
|
||||
Collection: convertCollectionFromStore(collection),
|
||||
}
|
||||
metric.Enqueue("collection create")
|
||||
return response, nil
|
||||
return convertCollectionFromStore(collection), nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) UpdateCollection(ctx context.Context, request *v1pb.UpdateCollectionRequest) (*v1pb.UpdateCollectionResponse, error) {
|
||||
func (s *APIV1Service) UpdateCollection(ctx context.Context, request *v1pb.UpdateCollectionRequest) (*v1pb.Collection, error) {
|
||||
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
|
||||
return nil, status.Errorf(codes.InvalidArgument, "updateMask is required")
|
||||
}
|
||||
@ -188,13 +180,10 @@ func (s *APIV1Service) UpdateCollection(ctx context.Context, request *v1pb.Updat
|
||||
return nil, status.Errorf(codes.Internal, "failed to update collection, err: %v", err)
|
||||
}
|
||||
|
||||
response := &v1pb.UpdateCollectionResponse{
|
||||
Collection: convertCollectionFromStore(collection),
|
||||
}
|
||||
return response, nil
|
||||
return convertCollectionFromStore(collection), nil
|
||||
}
|
||||
|
||||
func (s *APIV1Service) DeleteCollection(ctx context.Context, request *v1pb.DeleteCollectionRequest) (*v1pb.DeleteCollectionResponse, error) {
|
||||
func (s *APIV1Service) DeleteCollection(ctx context.Context, request *v1pb.DeleteCollectionRequest) (*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)
|
||||
@ -218,8 +207,7 @@ func (s *APIV1Service) DeleteCollection(ctx context.Context, request *v1pb.Delet
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Internal, "failed to delete collection, err: %v", err)
|
||||
}
|
||||
response := &v1pb.DeleteCollectionResponse{}
|
||||
return response, nil
|
||||
return &emptypb.Empty{}, nil
|
||||
}
|
||||
|
||||
func convertCollectionFromStore(collection *storepb.Collection) *v1pb.Collection {
|
||||
|
Reference in New Issue
Block a user