Chore: Copy org sqlstore methods to org store (#55825)
* Chore: Copy org sqlstore methods to org store * Remove GetByName, add some tests * Rename GetByNameHandler to GetByName * Fix fake name
This commit is contained in:
@@ -6,7 +6,6 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/models"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"github.com/grafana/grafana/pkg/services/sqlstore"
|
||||
"github.com/grafana/grafana/pkg/setting"
|
||||
@@ -103,69 +102,12 @@ func (s *Service) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*or
|
||||
return s.store.Search(ctx, query)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) GetByID(ctx context.Context, query *org.GetOrgByIdQuery) (*org.Org, error) {
|
||||
q := &models.GetOrgByIdQuery{Id: query.ID}
|
||||
err := s.sqlStore.GetOrgById(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &org.Org{
|
||||
ID: q.Result.Id,
|
||||
Version: q.Result.Version,
|
||||
Name: q.Result.Name,
|
||||
Address1: q.Result.Address1,
|
||||
Address2: q.Result.Address2,
|
||||
City: q.Result.City,
|
||||
ZipCode: q.Result.ZipCode,
|
||||
State: q.Result.State,
|
||||
Country: q.Result.Country,
|
||||
Created: q.Result.Created,
|
||||
Updated: q.Result.Updated,
|
||||
}, nil
|
||||
return s.store.GetByID(ctx, query)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) GetByNameHandler(ctx context.Context, query *org.GetOrgByNameQuery) (*org.Org, error) {
|
||||
q := &models.GetOrgByNameQuery{Name: query.Name}
|
||||
err := s.sqlStore.GetOrgByNameHandler(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &org.Org{
|
||||
ID: q.Result.Id,
|
||||
Version: q.Result.Version,
|
||||
Name: q.Result.Name,
|
||||
Address1: q.Result.Address1,
|
||||
Address2: q.Result.Address2,
|
||||
City: q.Result.City,
|
||||
ZipCode: q.Result.ZipCode,
|
||||
State: q.Result.State,
|
||||
Country: q.Result.Country,
|
||||
Created: q.Result.Created,
|
||||
Updated: q.Result.Updated,
|
||||
}, nil
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) GetByName(name string) (*org.Org, error) {
|
||||
orga, err := s.sqlStore.GetOrgByName(name)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &org.Org{
|
||||
ID: orga.Id,
|
||||
Version: orga.Version,
|
||||
Name: orga.Name,
|
||||
Address1: orga.Address1,
|
||||
Address2: orga.Address2,
|
||||
City: orga.City,
|
||||
ZipCode: orga.ZipCode,
|
||||
State: orga.State,
|
||||
Country: orga.Country,
|
||||
Created: orga.Created,
|
||||
Updated: orga.Updated,
|
||||
}, nil
|
||||
func (s *Service) GetByName(ctx context.Context, query *org.GetOrgByNameQuery) (*org.Org, error) {
|
||||
return s.store.GetByName(ctx, query)
|
||||
}
|
||||
|
||||
// TODO: refactor service to call store CRUD method
|
||||
|
||||
Reference in New Issue
Block a user