Chore: Copy methods from sqlstore to org store (#55615)

* Chore: Copy methods from sqlstore to org store

* Rename method, add test

* Add comments of tests
This commit is contained in:
idafurjes
2022-09-22 19:02:55 +02:00
committed by GitHub
parent e981848026
commit 591df92265
7 changed files with 246 additions and 98 deletions
+8 -82
View File
@@ -85,52 +85,19 @@ func (s *Service) DeleteUserFromAll(ctx context.Context, userID int64) error {
return s.store.DeleteUserFromAll(ctx, userID)
}
// TODO: remove wrapper around sqlstore
// TODO: refactor service to call store CRUD method
func (s *Service) GetUserOrgList(ctx context.Context, query *org.GetUserOrgListQuery) ([]*org.UserOrgDTO, error) {
q := &models.GetUserOrgListQuery{
UserId: query.UserID,
}
err := s.sqlStore.GetUserOrgList(ctx, q)
if err != nil {
return nil, err
}
var result []*org.UserOrgDTO
for _, orga := range q.Result {
result = append(result, &org.UserOrgDTO{
OrgID: orga.OrgId,
Name: orga.Name,
Role: orga.Role,
})
}
return result, nil
return s.store.GetUserOrgList(ctx, query)
}
// TODO: refactor service to call store CRUD method
func (s *Service) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgCommand) error {
return s.store.Update(ctx, cmd)
}
// TODO: remove wrapper around sqlstore
// TODO: refactor service to call store CRUD method
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
return s.store.Search(ctx, query)
}
// TODO: remove wrapper around sqlstore
@@ -198,50 +165,9 @@ func (s *Service) GetByName(name string) (*org.Org, error) {
}, nil
}
// TODO: remove wrapper around sqlstore
func (s *Service) CreateWithMember(name string, userID int64) (*org.Org, error) {
orga, err := s.sqlStore.CreateOrgWithMember(name, userID)
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
}
// TODO: remove wrapper around sqlstore
func (s *Service) Create(ctx context.Context, cmd *org.CreateOrgCommand) (*org.Org, error) {
q := &models.CreateOrgCommand{
Name: cmd.Name,
UserId: cmd.UserID,
}
err := s.sqlStore.CreateOrg(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: refactor service to call store CRUD method
func (s *Service) CreateWithMember(ctx context.Context, cmd *org.CreateOrgCommand) (*org.Org, error) {
return s.store.CreateWithMember(ctx, cmd)
}
// TODO: refactor service to call store CRUD method