-
Notifications
You must be signed in to change notification settings - Fork 12
/
postgres_tenant_apikey_repository.go
47 lines (37 loc) · 1.26 KB
/
postgres_tenant_apikey_repository.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package repository
import (
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-postgres-repository/entity"
"github.com/openline-ai/openline-customer-os/packages/server/customer-os-postgres-repository/repository/helper"
"gorm.io/gorm"
)
type TenantWebhookApiKeyRepo struct {
db *gorm.DB
}
type TenantWebhookApiKeyRepository interface {
GetTenantWithApiKey(apiKey string) helper.QueryResult
SaveApiKey(integration entity.TenantWebhookApiKey) helper.QueryResult
}
func NewTenantWebhookApiKeyRepo(db *gorm.DB) *TenantWebhookApiKeyRepo {
return &TenantWebhookApiKeyRepo{db: db}
}
func (r *TenantWebhookApiKeyRepo) GetTenantWithApiKey(apiKey string) helper.QueryResult {
var apiKeyEntity entity.TenantWebhookApiKey
err := r.db.
Where("key = ?", apiKey).
First(&apiKeyEntity).Error
if err != nil {
return helper.QueryResult{Error: err}
}
return helper.QueryResult{Result: &apiKeyEntity}
}
func (r *TenantWebhookApiKeyRepo) SaveApiKey(apiKey entity.TenantWebhookApiKey) helper.QueryResult {
apiKeyEntity := entity.TenantWebhookApiKey{
TenantName: apiKey.TenantName,
Key: apiKey.Key,
}
err := r.db.Create(&apiKeyEntity).Error
if err != nil {
return helper.QueryResult{Error: err}
}
return helper.QueryResult{Result: &apiKeyEntity}
}