Files
identity-provider-api/repositories/api-key.go
Björn Benouarets 6f4e929959 feat: add data access layer (repositories)
- Add user repository with CRUD operations and authentication methods
- Add session repository for session management and validation
- Add API key repository for API key management
- Include proper error handling and database transaction support
- Implement search and filtering capabilities
2025-09-25 23:24:28 +02:00

33 lines
708 B
Go

package repositories
import (
"git.secnex.io/secnex/idp-api/models"
"gorm.io/gorm"
)
type ApiKeyRepository struct {
db *gorm.DB
}
func NewApiKeyRepository(db *gorm.DB) *ApiKeyRepository {
return &ApiKeyRepository{db: db}
}
func (r *ApiKeyRepository) GetApiKeyByID(id string) (*models.ApiKey, error) {
var apiKey models.ApiKey
err := r.db.First(&apiKey, "id = ?", id).Error
if err != nil {
return nil, err
}
return &apiKey, nil
}
func (r *ApiKeyRepository) CreateApiKey(apiKey *models.ApiKey) (*models.ApiKey, error) {
// Create and return the api key and return the database object
result := r.db.Create(apiKey)
if result.Error != nil {
return nil, result.Error
}
return apiKey, nil
}