-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard_controller.go
83 lines (64 loc) · 1.94 KB
/
dashboard_controller.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
package main
import (
"errors"
"github.com/abjrcode/swervo/favorites"
"github.com/abjrcode/swervo/internal/app"
"github.com/abjrcode/swervo/providers"
awsidc "github.com/abjrcode/swervo/providers/aws_idc"
)
type Provider struct {
Code string `json:"code"`
Name string `json:"name"`
IconSvgBase64 string `json:"iconSvgBase64"`
}
type FavoriteInstance struct {
ProviderCode string `json:"providerCode"`
InstanceId string `json:"instanceId"`
}
type CompatibleSink struct {
Code string `json:"code"`
Name string `json:"name"`
}
var ProviderCompatibleSinksMap = map[string][]CompatibleSink{
awsidc.ProviderCode: {},
}
type DashboardController struct {
favoritesRepo favorites.FavoritesRepo
}
var supportedProviders []Provider
func NewDashboardController(favoritesRepo favorites.FavoritesRepo) *DashboardController {
supportedProviders = make([]Provider, 0, len(providers.SupportedProviders))
for _, provider := range providers.SupportedProviders {
supportedProviders = append(supportedProviders, Provider{
Code: provider.Code,
Name: provider.Name,
})
}
return &DashboardController{
favoritesRepo: favoritesRepo,
}
}
func (c *DashboardController) ListFavorites(ctx app.Context) ([]FavoriteInstance, error) {
favorites, err := c.favoritesRepo.ListAll(ctx)
if err != nil {
return nil, errors.Join(err, app.ErrFatal)
}
favoriteInstances := make([]FavoriteInstance, 0, len(favorites))
for _, favorite := range favorites {
favoriteInstances = append(favoriteInstances, FavoriteInstance{
ProviderCode: favorite.ProviderCode,
InstanceId: favorite.InstanceId,
})
}
return favoriteInstances, nil
}
func (c *DashboardController) ListProviders() []Provider {
return supportedProviders
}
func (c *DashboardController) ListCompatibleSinks(ctx app.Context, providerCode string) []CompatibleSink {
sinkCodes, ok := ProviderCompatibleSinksMap[providerCode]
if !ok {
return []CompatibleSink{}
}
return sinkCodes
}