-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_integration_features_all.go
56 lines (44 loc) · 1.59 KB
/
get_integration_features_all.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
48
49
50
51
52
53
54
55
56
package queries
import (
"context"
"fmt"
"github.com/DIMO-Network/device-definitions-api/internal/core/mediator"
coremodels "github.com/DIMO-Network/device-definitions-api/internal/core/models"
"github.com/DIMO-Network/device-definitions-api/internal/infrastructure/db/models"
"github.com/DIMO-Network/device-definitions-api/internal/infrastructure/exceptions"
"github.com/DIMO-Network/shared/db"
)
type GetAllIntegrationFeatureQuery struct {
}
func (*GetAllIntegrationFeatureQuery) Key() string { return "GetAllIntegrationFeatureQuery" }
type GetAllIntegrationFeatureQueryHandler struct {
DBS func() *db.ReaderWriter
}
func NewGetAllIntegrationFeatureQuery(dbs func() *db.ReaderWriter) GetAllIntegrationFeatureQueryHandler {
return GetAllIntegrationFeatureQueryHandler{DBS: dbs}
}
func (ch GetAllIntegrationFeatureQueryHandler) Handle(ctx context.Context, _ mediator.Message) (interface{}, error) {
all, err := models.IntegrationFeatures().All(ctx, ch.DBS().Reader)
if err != nil {
return nil, &exceptions.InternalError{
Err: fmt.Errorf("failed to get integration features"),
}
}
result := make([]coremodels.GetIntegrationFeatureQueryResult, len(all))
for i, v := range all {
result[i] = coremodels.GetIntegrationFeatureQueryResult{
FeatureKey: v.FeatureKey,
ElasticProperty: v.ElasticProperty,
DisplayName: v.DisplayName,
CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt,
}
if v.CSSIcon.Valid {
result[i].CSSIcon = v.CSSIcon.String
}
if v.FeatureWeight.Valid {
result[i].FeatureWeight = v.FeatureWeight.Float64
}
}
return result, nil
}