From c85812ddb675cb3af1c1c0e3cd2da10fa5f6fc12 Mon Sep 17 00:00:00 2001 From: Ryan Copley Date: Fri, 22 Aug 2025 19:37:49 -0400 Subject: [PATCH] - --- internal/services/token_service.go | 21 +++++++++++++++++++-- kms-frontend/src/components/Tokens.tsx | 13 ++++++++++++- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/internal/services/token_service.go b/internal/services/token_service.go index 259d4bf..fc40d25 100644 --- a/internal/services/token_service.go +++ b/internal/services/token_service.go @@ -144,8 +144,25 @@ func (s *tokenService) CreateStaticToken(ctx context.Context, req *domain.Create func (s *tokenService) ListByApp(ctx context.Context, appID string, limit, offset int) ([]*domain.StaticToken, error) { s.logger.Debug("Listing tokens for application", zap.String("app_id", appID)) - // TODO: Implement actual token listing - return []*domain.StaticToken{}, nil + tokens, err := s.tokenRepo.GetByAppID(ctx, appID) + if err != nil { + s.logger.Error("Failed to list tokens from repository", zap.Error(err), zap.String("app_id", appID)) + return nil, fmt.Errorf("failed to list tokens: %w", err) + } + + // Apply pagination manually since GetByAppID doesn't support it + start := offset + end := offset + limit + if start > len(tokens) { + tokens = []*domain.StaticToken{} + } else if end > len(tokens) { + tokens = tokens[start:] + } else { + tokens = tokens[start:end] + } + + s.logger.Debug("Listed tokens successfully", zap.String("app_id", appID), zap.Int("count", len(tokens))) + return tokens, nil } // Delete deletes a token diff --git a/kms-frontend/src/components/Tokens.tsx b/kms-frontend/src/components/Tokens.tsx index cdb088d..62c44a2 100644 --- a/kms-frontend/src/components/Tokens.tsx +++ b/kms-frontend/src/components/Tokens.tsx @@ -131,11 +131,21 @@ const Tokens: React.FC = () => { console.log('Form values:', values); console.log('App ID:', values.app_id); - if (!values.app_id) { + // More robust validation for app_id + if (!values.app_id || values.app_id === 'undefined' || values.app_id === undefined) { + console.error('Invalid app_id detected:', values.app_id); message.error('Please select an application'); return; } + // Validate that the app_id exists in our applications list + const selectedApp = applications.find(app => app.app_id === values.app_id); + if (!selectedApp) { + console.error('Selected app_id not found in applications list:', values.app_id); + message.error('Selected application is not valid. Please refresh and try again.'); + return; + } + const requestData: CreateTokenRequest = { owner: { type: values.owner_type, @@ -149,6 +159,7 @@ const Tokens: React.FC = () => { console.log('Request data:', requestData); const response = await apiService.createToken(values.app_id, requestData); + console.log('Token creation response:', response); setNewTokenResponse(response); message.success('Token created successfully'); loadApplications();