Add some org methods to org service interface (#55449)

* Add some org methods to org service interface

* Fix fake method name
pull/55465/head
idafurjes 3 years ago committed by GitHub
parent dbbab6e95c
commit 43a1d1484d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      pkg/services/org/model.go
  2. 5
      pkg/services/org/org.go
  3. 111
      pkg/services/org/orgimpl/org.go
  4. 20
      pkg/services/org/orgtest/fake.go

@ -89,6 +89,14 @@ type OrgDTO struct {
Name string `json:"name"`
}
type GetOrgByIdQuery struct {
ID int64
}
type GetOrgByNameQuery struct {
Name string
}
func (r RoleType) IsValid() bool {
return r == RoleViewer || r == RoleAdmin || r == RoleEditor
}

@ -11,4 +11,9 @@ type Service interface {
GetUserOrgList(context.Context, *GetUserOrgListQuery) ([]*UserOrgDTO, error)
UpdateOrg(context.Context, *UpdateOrgCommand) error
Search(context.Context, *SearchOrgsQuery) ([]*OrgDTO, error)
GetByID(context.Context, *GetOrgByIdQuery) (*Org, error)
GetByNameHandler(context.Context, *GetOrgByNameQuery) (*Org, error)
GetByName(string) (*Org, error)
CreateWithMember(name string, userID int64) (*Org, error)
Create(ctx context.Context, cmd *CreateOrgCommand) (*Org, error)
}

@ -132,3 +132,114 @@ func (s *Service) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*or
}
return res, nil
}
// 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
}
// 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
}
// 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
}

@ -11,6 +11,7 @@ type FakeOrgService struct {
ExpectedError error
ExpectedUserOrgDTO []*org.UserOrgDTO
ExpectedOrgs []*org.OrgDTO
ExpectedOrg *org.Org
}
func NewOrgServiceFake() *FakeOrgService {
@ -44,3 +45,22 @@ func (f *FakeOrgService) UpdateOrg(ctx context.Context, cmd *org.UpdateOrgComman
func (f *FakeOrgService) Search(ctx context.Context, query *org.SearchOrgsQuery) ([]*org.OrgDTO, error) {
return f.ExpectedOrgs, f.ExpectedError
}
func (f *FakeOrgService) GetByID(ctx context.Context, query *org.GetOrgByIdQuery) (*org.Org, error) {
return f.ExpectedOrg, f.ExpectedError
}
func (f *FakeOrgService) GetByNameHandler(ctx context.Context, query *org.GetOrgByNameQuery) (*org.Org, error) {
return f.ExpectedOrg, f.ExpectedError
}
func (f *FakeOrgService) GetByName(name string) (*org.Org, error) {
return f.ExpectedOrg, f.ExpectedError
}
func (f *FakeOrgService) CreateWithMember(name string, userID int64) (*org.Org, error) {
return f.ExpectedOrg, f.ExpectedError
}
func (f *FakeOrgService) Create(ctx context.Context, cmd *org.CreateOrgCommand) (*org.Org, error) {
return f.ExpectedOrg, f.ExpectedError
}

Loading…
Cancel
Save