mirror of
https://github.com/aykhans/slash-e.git
synced 2025-04-20 22:07:15 +00:00
chore: combine v2 services
This commit is contained in:
parent
82ac6ab985
commit
015336b8c3
@ -13,22 +13,7 @@ import (
|
|||||||
"github.com/boojack/slash/store"
|
"github.com/boojack/slash/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type ShortcutService struct {
|
func (s *APIV2Service) ListShortcuts(ctx context.Context, _ *apiv2pb.ListShortcutsRequest) (*apiv2pb.ListShortcutsResponse, error) {
|
||||||
apiv2pb.UnimplementedShortcutServiceServer
|
|
||||||
|
|
||||||
Secret string
|
|
||||||
Store *store.Store
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewShortcutService creates a new Shortcut service.
|
|
||||||
func NewShortcutService(secret string, store *store.Store) *ShortcutService {
|
|
||||||
return &ShortcutService{
|
|
||||||
Secret: secret,
|
|
||||||
Store: store,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *ShortcutService) ListShortcuts(ctx context.Context, _ *apiv2pb.ListShortcutsRequest) (*apiv2pb.ListShortcutsResponse, error) {
|
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
find := &store.FindShortcut{}
|
find := &store.FindShortcut{}
|
||||||
find.VisibilityList = []store.Visibility{store.VisibilityWorkspace, store.VisibilityPublic}
|
find.VisibilityList = []store.Visibility{store.VisibilityWorkspace, store.VisibilityPublic}
|
||||||
@ -56,7 +41,7 @@ func (s *ShortcutService) ListShortcuts(ctx context.Context, _ *apiv2pb.ListShor
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShortcutService) GetShortcut(ctx context.Context, request *apiv2pb.GetShortcutRequest) (*apiv2pb.GetShortcutResponse, error) {
|
func (s *APIV2Service) GetShortcut(ctx context.Context, request *apiv2pb.GetShortcutRequest) (*apiv2pb.GetShortcutResponse, error) {
|
||||||
shortcut, err := s.Store.GetShortcut(ctx, &store.FindShortcut{
|
shortcut, err := s.Store.GetShortcut(ctx, &store.FindShortcut{
|
||||||
Name: &request.Name,
|
Name: &request.Name,
|
||||||
})
|
})
|
||||||
@ -78,7 +63,7 @@ func (s *ShortcutService) GetShortcut(ctx context.Context, request *apiv2pb.GetS
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShortcutService) CreateShortcut(ctx context.Context, request *apiv2pb.CreateShortcutRequest) (*apiv2pb.CreateShortcutResponse, error) {
|
func (s *APIV2Service) CreateShortcut(ctx context.Context, request *apiv2pb.CreateShortcutRequest) (*apiv2pb.CreateShortcutResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
shortcut := &storepb.Shortcut{
|
shortcut := &storepb.Shortcut{
|
||||||
CreatorId: userID,
|
CreatorId: userID,
|
||||||
@ -111,7 +96,7 @@ func (s *ShortcutService) CreateShortcut(ctx context.Context, request *apiv2pb.C
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShortcutService) DeleteShortcut(ctx context.Context, request *apiv2pb.DeleteShortcutRequest) (*apiv2pb.DeleteShortcutResponse, error) {
|
func (s *APIV2Service) DeleteShortcut(ctx context.Context, request *apiv2pb.DeleteShortcutRequest) (*apiv2pb.DeleteShortcutResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
currentUser, err := s.Store.GetUser(ctx, &store.FindUser{
|
currentUser, err := s.Store.GetUser(ctx, &store.FindUser{
|
||||||
ID: &userID,
|
ID: &userID,
|
||||||
@ -142,7 +127,7 @@ func (s *ShortcutService) DeleteShortcut(ctx context.Context, request *apiv2pb.D
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *ShortcutService) createShortcutCreateActivity(ctx context.Context, shortcut *storepb.Shortcut) error {
|
func (s *APIV2Service) createShortcutCreateActivity(ctx context.Context, shortcut *storepb.Shortcut) error {
|
||||||
payload := &storepb.ActivityShorcutCreatePayload{
|
payload := &storepb.ActivityShorcutCreatePayload{
|
||||||
ShortcutId: shortcut.Id,
|
ShortcutId: shortcut.Id,
|
||||||
}
|
}
|
||||||
|
@ -7,29 +7,9 @@ import (
|
|||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
apiv2pb "github.com/boojack/slash/proto/gen/api/v2"
|
apiv2pb "github.com/boojack/slash/proto/gen/api/v2"
|
||||||
"github.com/boojack/slash/server/profile"
|
|
||||||
"github.com/boojack/slash/server/service/license"
|
|
||||||
"github.com/boojack/slash/store"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type SubscriptionService struct {
|
func (s *APIV2Service) GetSubscription(ctx context.Context, _ *apiv2pb.GetSubscriptionRequest) (*apiv2pb.GetSubscriptionResponse, error) {
|
||||||
apiv2pb.UnimplementedSubscriptionServiceServer
|
|
||||||
|
|
||||||
Profile *profile.Profile
|
|
||||||
Store *store.Store
|
|
||||||
LicenseService *license.LicenseService
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewSubscriptionService creates a new SubscriptionService.
|
|
||||||
func NewSubscriptionService(profile *profile.Profile, store *store.Store, licenseService *license.LicenseService) *SubscriptionService {
|
|
||||||
return &SubscriptionService{
|
|
||||||
Profile: profile,
|
|
||||||
Store: store,
|
|
||||||
LicenseService: licenseService,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *SubscriptionService) GetSubscription(ctx context.Context, _ *apiv2pb.GetSubscriptionRequest) (*apiv2pb.GetSubscriptionResponse, error) {
|
|
||||||
subscription, err := s.LicenseService.LoadSubscription(ctx)
|
subscription, err := s.LicenseService.LoadSubscription(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
|
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
|
||||||
@ -39,7 +19,7 @@ func (s *SubscriptionService) GetSubscription(ctx context.Context, _ *apiv2pb.Ge
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *SubscriptionService) UpdateSubscription(ctx context.Context, request *apiv2pb.UpdateSubscriptionRequest) (*apiv2pb.UpdateSubscriptionResponse, error) {
|
func (s *APIV2Service) UpdateSubscription(ctx context.Context, request *apiv2pb.UpdateSubscriptionRequest) (*apiv2pb.UpdateSubscriptionResponse, error) {
|
||||||
subscription, err := s.LicenseService.UpdateSubscription(ctx, request.LicenseKey)
|
subscription, err := s.LicenseService.UpdateSubscription(ctx, request.LicenseKey)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
|
return nil, status.Errorf(codes.Internal, "failed to load subscription: %v", err)
|
||||||
|
@ -19,24 +19,7 @@ import (
|
|||||||
"github.com/boojack/slash/store"
|
"github.com/boojack/slash/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserService struct {
|
func (s *APIV2Service) ListUsers(ctx context.Context, _ *apiv2pb.ListUsersRequest) (*apiv2pb.ListUsersResponse, error) {
|
||||||
apiv2pb.UnimplementedUserServiceServer
|
|
||||||
|
|
||||||
Secret string
|
|
||||||
Store *store.Store
|
|
||||||
LicenseService *license.LicenseService
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUserService creates a new UserService.
|
|
||||||
func NewUserService(secret string, store *store.Store, licenseService *license.LicenseService) *UserService {
|
|
||||||
return &UserService{
|
|
||||||
Secret: secret,
|
|
||||||
Store: store,
|
|
||||||
LicenseService: licenseService,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UserService) ListUsers(ctx context.Context, _ *apiv2pb.ListUsersRequest) (*apiv2pb.ListUsersResponse, error) {
|
|
||||||
users, err := s.Store.ListUsers(ctx, &store.FindUser{})
|
users, err := s.Store.ListUsers(ctx, &store.FindUser{})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to list users: %v", err)
|
return nil, status.Errorf(codes.Internal, "failed to list users: %v", err)
|
||||||
@ -52,7 +35,7 @@ func (s *UserService) ListUsers(ctx context.Context, _ *apiv2pb.ListUsersRequest
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) GetUser(ctx context.Context, request *apiv2pb.GetUserRequest) (*apiv2pb.GetUserResponse, error) {
|
func (s *APIV2Service) GetUser(ctx context.Context, request *apiv2pb.GetUserRequest) (*apiv2pb.GetUserResponse, error) {
|
||||||
user, err := s.Store.GetUser(ctx, &store.FindUser{
|
user, err := s.Store.GetUser(ctx, &store.FindUser{
|
||||||
ID: &request.Id,
|
ID: &request.Id,
|
||||||
})
|
})
|
||||||
@ -70,7 +53,7 @@ func (s *UserService) GetUser(ctx context.Context, request *apiv2pb.GetUserReque
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) CreateUser(ctx context.Context, request *apiv2pb.CreateUserRequest) (*apiv2pb.CreateUserResponse, error) {
|
func (s *APIV2Service) CreateUser(ctx context.Context, request *apiv2pb.CreateUserRequest) (*apiv2pb.CreateUserResponse, error) {
|
||||||
passwordHash, err := bcrypt.GenerateFromPassword([]byte(request.User.Password), bcrypt.DefaultCost)
|
passwordHash, err := bcrypt.GenerateFromPassword([]byte(request.User.Password), bcrypt.DefaultCost)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to hash password: %v", err)
|
return nil, status.Errorf(codes.Internal, "failed to hash password: %v", err)
|
||||||
@ -101,7 +84,7 @@ func (s *UserService) CreateUser(ctx context.Context, request *apiv2pb.CreateUse
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) UpdateUser(ctx context.Context, request *apiv2pb.UpdateUserRequest) (*apiv2pb.UpdateUserResponse, error) {
|
func (s *APIV2Service) UpdateUser(ctx context.Context, request *apiv2pb.UpdateUserRequest) (*apiv2pb.UpdateUserResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
if userID != request.User.Id {
|
if userID != request.User.Id {
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||||
@ -129,7 +112,7 @@ func (s *UserService) UpdateUser(ctx context.Context, request *apiv2pb.UpdateUse
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) DeleteUser(ctx context.Context, request *apiv2pb.DeleteUserRequest) (*apiv2pb.DeleteUserResponse, error) {
|
func (s *APIV2Service) DeleteUser(ctx context.Context, request *apiv2pb.DeleteUserRequest) (*apiv2pb.DeleteUserResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
if userID == request.Id {
|
if userID == request.Id {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "cannot delete yourself")
|
return nil, status.Errorf(codes.InvalidArgument, "cannot delete yourself")
|
||||||
@ -145,7 +128,7 @@ func (s *UserService) DeleteUser(ctx context.Context, request *apiv2pb.DeleteUse
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) ListUserAccessTokens(ctx context.Context, request *apiv2pb.ListUserAccessTokensRequest) (*apiv2pb.ListUserAccessTokensResponse, error) {
|
func (s *APIV2Service) ListUserAccessTokens(ctx context.Context, request *apiv2pb.ListUserAccessTokensRequest) (*apiv2pb.ListUserAccessTokensResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
if userID != request.Id {
|
if userID != request.Id {
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||||
@ -196,7 +179,7 @@ func (s *UserService) ListUserAccessTokens(ctx context.Context, request *apiv2pb
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) CreateUserAccessToken(ctx context.Context, request *apiv2pb.CreateUserAccessTokenRequest) (*apiv2pb.CreateUserAccessTokenResponse, error) {
|
func (s *APIV2Service) CreateUserAccessToken(ctx context.Context, request *apiv2pb.CreateUserAccessTokenRequest) (*apiv2pb.CreateUserAccessTokenResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
if userID != request.Id {
|
if userID != request.Id {
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||||
@ -256,7 +239,7 @@ func (s *UserService) CreateUserAccessToken(ctx context.Context, request *apiv2p
|
|||||||
return response, nil
|
return response, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) DeleteUserAccessToken(ctx context.Context, request *apiv2pb.DeleteUserAccessTokenRequest) (*apiv2pb.DeleteUserAccessTokenResponse, error) {
|
func (s *APIV2Service) DeleteUserAccessToken(ctx context.Context, request *apiv2pb.DeleteUserAccessTokenRequest) (*apiv2pb.DeleteUserAccessTokenResponse, error) {
|
||||||
userID := ctx.Value(userIDContextKey).(int32)
|
userID := ctx.Value(userIDContextKey).(int32)
|
||||||
if userID != request.Id {
|
if userID != request.Id {
|
||||||
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
return nil, status.Errorf(codes.PermissionDenied, "Permission denied")
|
||||||
@ -288,7 +271,7 @@ func (s *UserService) DeleteUserAccessToken(ctx context.Context, request *apiv2p
|
|||||||
return &apiv2pb.DeleteUserAccessTokenResponse{}, nil
|
return &apiv2pb.DeleteUserAccessTokenResponse{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserService) UpsertAccessTokenToStore(ctx context.Context, user *store.User, accessToken, description string) error {
|
func (s *APIV2Service) UpsertAccessTokenToStore(ctx context.Context, user *store.User, accessToken, description string) error {
|
||||||
userAccessTokens, err := s.Store.GetUserAccessTokens(ctx, user.ID)
|
userAccessTokens, err := s.Store.GetUserAccessTokens(ctx, user.ID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "failed to get user access tokens")
|
return errors.Wrap(err, "failed to get user access tokens")
|
||||||
|
@ -12,20 +12,7 @@ import (
|
|||||||
"github.com/boojack/slash/store"
|
"github.com/boojack/slash/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserSettingService struct {
|
func (s *APIV2Service) GetUserSetting(ctx context.Context, request *apiv2pb.GetUserSettingRequest) (*apiv2pb.GetUserSettingResponse, error) {
|
||||||
apiv2pb.UnimplementedUserSettingServiceServer
|
|
||||||
|
|
||||||
Store *store.Store
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewUserSettingService creates a new UserSettingService.
|
|
||||||
func NewUserSettingService(store *store.Store) *UserSettingService {
|
|
||||||
return &UserSettingService{
|
|
||||||
Store: store,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *UserSettingService) GetUserSetting(ctx context.Context, request *apiv2pb.GetUserSettingRequest) (*apiv2pb.GetUserSettingResponse, error) {
|
|
||||||
userSetting, err := getUserSetting(ctx, s.Store, request.Id)
|
userSetting, err := getUserSetting(ctx, s.Store, request.Id)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Internal, "failed to get user setting: %v", err)
|
return nil, status.Errorf(codes.Internal, "failed to get user setting: %v", err)
|
||||||
@ -35,7 +22,7 @@ func (s *UserSettingService) GetUserSetting(ctx context.Context, request *apiv2p
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *UserSettingService) UpdateUserSetting(ctx context.Context, request *apiv2pb.UpdateUserSettingRequest) (*apiv2pb.UpdateUserSettingResponse, error) {
|
func (s *APIV2Service) UpdateUserSetting(ctx context.Context, request *apiv2pb.UpdateUserSettingRequest) (*apiv2pb.UpdateUserSettingResponse, error) {
|
||||||
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
|
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "update mask is empty")
|
return nil, status.Errorf(codes.InvalidArgument, "update mask is empty")
|
||||||
}
|
}
|
||||||
|
24
api/v2/v2.go
24
api/v2/v2.go
@ -18,6 +18,12 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type APIV2Service struct {
|
type APIV2Service struct {
|
||||||
|
apiv2pb.UnimplementedWorkspaceServiceServer
|
||||||
|
apiv2pb.UnimplementedSubscriptionServiceServer
|
||||||
|
apiv2pb.UnimplementedUserServiceServer
|
||||||
|
apiv2pb.UnimplementedUserSettingServiceServer
|
||||||
|
apiv2pb.UnimplementedShortcutServiceServer
|
||||||
|
|
||||||
Secret string
|
Secret string
|
||||||
Profile *profile.Profile
|
Profile *profile.Profile
|
||||||
Store *store.Store
|
Store *store.Store
|
||||||
@ -34,14 +40,7 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
|
|||||||
authProvider.AuthenticationInterceptor,
|
authProvider.AuthenticationInterceptor,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
apiv2pb.RegisterSubscriptionServiceServer(grpcServer, NewSubscriptionService(profile, store, licenseService))
|
apiV2Service := &APIV2Service{
|
||||||
apiv2pb.RegisterWorkspaceServiceServer(grpcServer, NewWorkspaceService(profile, store, licenseService))
|
|
||||||
apiv2pb.RegisterUserServiceServer(grpcServer, NewUserService(secret, store, licenseService))
|
|
||||||
apiv2pb.RegisterUserSettingServiceServer(grpcServer, NewUserSettingService(store))
|
|
||||||
apiv2pb.RegisterShortcutServiceServer(grpcServer, NewShortcutService(secret, store))
|
|
||||||
reflection.Register(grpcServer)
|
|
||||||
|
|
||||||
return &APIV2Service{
|
|
||||||
Secret: secret,
|
Secret: secret,
|
||||||
Profile: profile,
|
Profile: profile,
|
||||||
Store: store,
|
Store: store,
|
||||||
@ -49,6 +48,15 @@ func NewAPIV2Service(secret string, profile *profile.Profile, store *store.Store
|
|||||||
grpcServer: grpcServer,
|
grpcServer: grpcServer,
|
||||||
grpcServerPort: grpcServerPort,
|
grpcServerPort: grpcServerPort,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
apiv2pb.RegisterSubscriptionServiceServer(grpcServer, apiV2Service)
|
||||||
|
apiv2pb.RegisterWorkspaceServiceServer(grpcServer, apiV2Service)
|
||||||
|
apiv2pb.RegisterUserServiceServer(grpcServer, apiV2Service)
|
||||||
|
apiv2pb.RegisterUserSettingServiceServer(grpcServer, apiV2Service)
|
||||||
|
apiv2pb.RegisterShortcutServiceServer(grpcServer, apiV2Service)
|
||||||
|
reflection.Register(grpcServer)
|
||||||
|
|
||||||
|
return apiV2Service
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *APIV2Service) GetGRPCServer() *grpc.Server {
|
func (s *APIV2Service) GetGRPCServer() *grpc.Server {
|
||||||
|
@ -8,29 +8,10 @@ import (
|
|||||||
|
|
||||||
apiv2pb "github.com/boojack/slash/proto/gen/api/v2"
|
apiv2pb "github.com/boojack/slash/proto/gen/api/v2"
|
||||||
storepb "github.com/boojack/slash/proto/gen/store"
|
storepb "github.com/boojack/slash/proto/gen/store"
|
||||||
"github.com/boojack/slash/server/profile"
|
|
||||||
"github.com/boojack/slash/server/service/license"
|
|
||||||
"github.com/boojack/slash/store"
|
"github.com/boojack/slash/store"
|
||||||
)
|
)
|
||||||
|
|
||||||
type WorkspaceService struct {
|
func (s *APIV2Service) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
|
||||||
apiv2pb.UnimplementedWorkspaceServiceServer
|
|
||||||
|
|
||||||
Profile *profile.Profile
|
|
||||||
Store *store.Store
|
|
||||||
LicenseService *license.LicenseService
|
|
||||||
}
|
|
||||||
|
|
||||||
// NewWorkspaceService creates a new WorkspaceService.
|
|
||||||
func NewWorkspaceService(profile *profile.Profile, store *store.Store, licenseService *license.LicenseService) *WorkspaceService {
|
|
||||||
return &WorkspaceService{
|
|
||||||
Profile: profile,
|
|
||||||
Store: store,
|
|
||||||
LicenseService: licenseService,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *WorkspaceService) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.GetWorkspaceProfileRequest) (*apiv2pb.GetWorkspaceProfileResponse, error) {
|
|
||||||
profile := &apiv2pb.WorkspaceProfile{
|
profile := &apiv2pb.WorkspaceProfile{
|
||||||
Mode: s.Profile.Mode,
|
Mode: s.Profile.Mode,
|
||||||
Plan: apiv2pb.PlanType_FREE,
|
Plan: apiv2pb.PlanType_FREE,
|
||||||
@ -58,7 +39,7 @@ func (s *WorkspaceService) GetWorkspaceProfile(ctx context.Context, _ *apiv2pb.G
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WorkspaceService) GetWorkspaceSetting(ctx context.Context, _ *apiv2pb.GetWorkspaceSettingRequest) (*apiv2pb.GetWorkspaceSettingResponse, error) {
|
func (s *APIV2Service) GetWorkspaceSetting(ctx context.Context, _ *apiv2pb.GetWorkspaceSettingRequest) (*apiv2pb.GetWorkspaceSettingResponse, error) {
|
||||||
isAdmin := false
|
isAdmin := false
|
||||||
userID, ok := ctx.Value(userIDContextKey).(int32)
|
userID, ok := ctx.Value(userIDContextKey).(int32)
|
||||||
if ok {
|
if ok {
|
||||||
@ -96,7 +77,7 @@ func (s *WorkspaceService) GetWorkspaceSetting(ctx context.Context, _ *apiv2pb.G
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *WorkspaceService) UpdateWorkspaceSetting(ctx context.Context, request *apiv2pb.UpdateWorkspaceSettingRequest) (*apiv2pb.UpdateWorkspaceSettingResponse, error) {
|
func (s *APIV2Service) UpdateWorkspaceSetting(ctx context.Context, request *apiv2pb.UpdateWorkspaceSettingRequest) (*apiv2pb.UpdateWorkspaceSettingResponse, error) {
|
||||||
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
|
if request.UpdateMask == nil || len(request.UpdateMask.Paths) == 0 {
|
||||||
return nil, status.Errorf(codes.InvalidArgument, "update mask is empty")
|
return nil, status.Errorf(codes.InvalidArgument, "update mask is empty")
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user