Chore: Move SearchOrgs to org service (#55416)

* Chore: Move SearchOrgs to org service

* Fix lint

* Fix lint 2
This commit is contained in:
idafurjes
2022-09-20 09:55:40 +02:00
committed by GitHub
parent e25612092b
commit 7ce7c9b64c
17 changed files with 122 additions and 60 deletions

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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
}

View File

@@ -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
}