
- 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
33 lines
708 B
Go
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
|
|
}
|