mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Move SearchOrgs to org service (#55416)
* Chore: Move SearchOrgs to org service * Fix lint * Fix lint 2
This commit is contained in:
@@ -76,6 +76,19 @@ type UpdateOrgCommand struct {
|
||||
OrgId int64
|
||||
}
|
||||
|
||||
type SearchOrgsQuery struct {
|
||||
Query string
|
||||
Name string
|
||||
Limit int
|
||||
Page int
|
||||
IDs []int64
|
||||
}
|
||||
|
||||
type OrgDTO struct {
|
||||
ID int64 `json:"id"`
|
||||
Name string `json:"name"`
|
||||
}
|
||||
|
||||
func (r RoleType) IsValid() bool {
|
||||
return r == RoleViewer || r == RoleAdmin || r == RoleEditor
|
||||
}
|
||||
|
@@ -9,5 +9,6 @@ type Service interface {
|
||||
InsertOrgUser(context.Context, *OrgUser) (int64, error)
|
||||
DeleteUserFromAll(context.Context, int64) error
|
||||
GetUserOrgList(context.Context, *GetUserOrgListQuery) ([]*UserOrgDTO, error)
|
||||
UpdateOrg(ctx context.Context, cmd *UpdateOrgCommand) error
|
||||
UpdateOrg(context.Context, *UpdateOrgCommand) error
|
||||
Search(context.Context, *SearchOrgsQuery) ([]*OrgDTO, error)
|
||||
}
|
||||
|
@@ -108,3 +108,27 @@ func (s *Service) GetUserOrgList(ctx context.Context, query *org.GetUserOrgListQ
|
||||
func (s *Service) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgCommand) error {
|
||||
return s.store.Update(ctx, cmd)
|
||||
}
|
||||
|
||||
// TODO: remove wrapper around sqlstore
|
||||
func (s *Service) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*org.OrgDTO, error) {
|
||||
var res []*org.OrgDTO
|
||||
q := &models.SearchOrgsQuery{
|
||||
Query: query.Query,
|
||||
Name: query.Name,
|
||||
Limit: query.Limit,
|
||||
Page: query.Page,
|
||||
Ids: query.IDs,
|
||||
}
|
||||
err := s.sqlStore.SearchOrgs(ctx, q)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
for _, r := range q.Result {
|
||||
res = append(res, &org.OrgDTO{
|
||||
ID: r.Id,
|
||||
Name: r.Name,
|
||||
})
|
||||
}
|
||||
return res, nil
|
||||
}
|
||||
|
@@ -10,6 +10,7 @@ type FakeOrgService struct {
|
||||
ExpectedOrgUserID int64
|
||||
ExpectedError error
|
||||
ExpectedUserOrgDTO []*org.UserOrgDTO
|
||||
ExpectedOrgs []*org.OrgDTO
|
||||
}
|
||||
|
||||
func NewOrgServiceFake() *FakeOrgService {
|
||||
@@ -39,3 +40,7 @@ func (f *FakeOrgService) GetUserOrgList(ctx context.Context, query *org.GetUserO
|
||||
func (f *FakeOrgService) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgCommand) error {
|
||||
return f.ExpectedError
|
||||
}
|
||||
|
||||
func (f *FakeOrgService) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*org.OrgDTO, error) {
|
||||
return f.ExpectedOrgs, f.ExpectedError
|
||||
}
|
||||
|
Reference in New Issue
Block a user