generated from broadinstitute/golang-project-template
/
pagerduty_integration.go
90 lines (78 loc) · 2.72 KB
/
pagerduty_integration.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
package v2controllers
import (
"github.com/broadinstitute/sherlock/internal/config"
"github.com/broadinstitute/sherlock/internal/models/v2models"
"gorm.io/gorm"
)
type PagerdutyIntegration struct {
ReadableBaseType
PagerdutyID string `json:"pagerdutyID" form:"pagerdutyID"`
Name *string `json:"name" form:"name"`
Type *string `json:"type" form:"type"`
}
type CreatablePagerdutyIntegration struct {
PagerdutyID string `json:"pagerdutyID" form:"pagerdutyID"`
EditablePagerdutyIntegration
}
type EditablePagerdutyIntegration struct {
Name *string `json:"name" form:"name"`
Key *string `json:"key" form:"key"`
Type *string `json:"type" form:"type"`
}
//nolint:unused
func (p PagerdutyIntegration) toModel(_ *v2models.StoreSet) (v2models.PagerdutyIntegration, error) {
return v2models.PagerdutyIntegration{
Model: gorm.Model{
ID: p.ID,
CreatedAt: p.CreatedAt,
UpdatedAt: p.UpdatedAt,
},
Name: p.Name,
PagerdutyID: p.PagerdutyID,
Type: p.Type,
}, nil
}
//nolint:unused
func (p CreatablePagerdutyIntegration) toModel(_ *v2models.StoreSet) (v2models.PagerdutyIntegration, error) {
return v2models.PagerdutyIntegration{
Name: p.Name,
PagerdutyID: p.PagerdutyID,
Key: p.Key,
Type: p.Type,
}, nil
}
//nolint:unused
func (p EditablePagerdutyIntegration) toModel(storeSet *v2models.StoreSet) (v2models.PagerdutyIntegration, error) {
return CreatablePagerdutyIntegration{EditablePagerdutyIntegration: p}.toModel(storeSet)
}
type PagerdutyIntegrationController = ModelController[v2models.PagerdutyIntegration, PagerdutyIntegration, CreatablePagerdutyIntegration, EditablePagerdutyIntegration]
func newPagerdutyIntegrationController(stores *v2models.StoreSet) *PagerdutyIntegrationController {
return &PagerdutyIntegrationController{
primaryStore: stores.PagerdutyIntegration,
allStores: stores,
modelToReadable: modelPagerdutyIntegrationToPagerdutyIntegration,
extractPagerdutyIntegrationKey: extractPagerdutyIntegrationKeyFromPagerdutyIntegration,
beehiveUrlFormatString: config.Config.MustString("beehive.pagerdutyIntegrationUrlFormatString"),
}
}
func modelPagerdutyIntegrationToPagerdutyIntegration(model *v2models.PagerdutyIntegration) *PagerdutyIntegration {
if model == nil {
return nil
}
return &PagerdutyIntegration{
ReadableBaseType: ReadableBaseType{
ID: model.ID,
CreatedAt: model.CreatedAt,
UpdatedAt: model.UpdatedAt,
},
Name: model.Name,
PagerdutyID: model.PagerdutyID,
Type: model.Type,
}
}
func extractPagerdutyIntegrationKeyFromPagerdutyIntegration(model *v2models.PagerdutyIntegration) *string {
if model != nil {
return model.Key
}
return nil
}