snapshot of https://github.com/traggo/server.git (master, 2026-09-16; blobs > 131072B omitted)
Some checks failed
build / build (push) Failing after 3s
Some checks failed
build / build (push) Failing after 3s
This commit is contained in:
37
dashboard/convert/dashboard.go
Normal file
37
dashboard/convert/dashboard.go
Normal file
@@ -0,0 +1,37 @@
|
||||
package convert
|
||||
|
||||
import (
|
||||
"github.com/traggo/server/generated/gqlmodel"
|
||||
"github.com/traggo/server/model"
|
||||
)
|
||||
|
||||
// ToExternalDashboards converts dashboards.
|
||||
func ToExternalDashboards(dashboards []model.Dashboard) ([]*gqlmodel.Dashboard, error) {
|
||||
result := []*gqlmodel.Dashboard{}
|
||||
for _, dashboard := range dashboards {
|
||||
if converted, err := ToExternalDashboard(dashboard); err == nil {
|
||||
result = append(result, converted)
|
||||
} else {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// ToExternalDashboard converts a dashboard.
|
||||
func ToExternalDashboard(dashboard model.Dashboard) (*gqlmodel.Dashboard, error) {
|
||||
entries, err := toExternalEntries(dashboard.Entries)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
ranges, err := toExternalDashboardsRanges(dashboard.Ranges)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &gqlmodel.Dashboard{
|
||||
ID: dashboard.ID,
|
||||
Name: dashboard.Name,
|
||||
Items: entries,
|
||||
Ranges: ranges,
|
||||
}, nil
|
||||
}
|
||||
Reference in New Issue
Block a user