chore(dashboard version service): make method sigs more consistent (#60736)

The DashboardVersion struct is the database object; the DashboardVersionDTO is the object that should be sent to the API layer.

In the future I'd like to move DashboardVersion to dashverimpl and un-export it, but there are a few places that Insert directly into that table, not all of which are test fixtures, so that should wait until we clean up at least the DashboardService's use of it.
This commit is contained in:
Kristin Laemmert
2022-12-27 11:17:24 -05:00
committed by GitHub
parent 29276581d2
commit 6e9419ea80
9 changed files with 67 additions and 37 deletions
@@ -26,13 +26,15 @@ func ProvideService(db db.DB) dashver.Service {
}
}
func (s *Service) Get(ctx context.Context, query *dashver.GetDashboardVersionQuery) (*dashver.DashboardVersion, error) {
func (s *Service) Get(ctx context.Context, query *dashver.GetDashboardVersionQuery) (*dashver.DashboardVersionDTO, error) {
version, err := s.store.Get(ctx, query)
if err != nil {
return nil, err
}
version.Data.Set("id", version.DashboardID)
return version, nil
// FIXME: the next PR will add the dashboardService so we can grab the DashboardUID
return version.ToDTO(""), nil
}
func (s *Service) DeleteExpired(ctx context.Context, cmd *dashver.DeleteExpiredVersionsCommand) error {
@@ -70,5 +72,14 @@ func (s *Service) List(ctx context.Context, query *dashver.ListDashboardVersions
if query.Limit == 0 {
query.Limit = 1000
}
return s.store.List(ctx, query)
dvs, err := s.store.List(ctx, query)
if err != nil {
return nil, err
}
dtos := make([]*dashver.DashboardVersionDTO, len(dvs))
for i, v := range dvs {
// FIXME: the next PR will add the dashboardService so we can grab the DashboardUID
dtos[i] = v.ToDTO("")
}
return dtos, nil
}