Preload credentials endpoint and remove extra code
Signed-off-by: Gabriel Adrian Samfira <gsamfira@cloudbasesolutions.com>
This commit is contained in:
parent
032d40f5f9
commit
3e60a48ca8
8 changed files with 41 additions and 34 deletions
|
|
@ -96,7 +96,7 @@ func (s *sqlDatabase) GetEnterpriseByID(ctx context.Context, enterpriseID string
|
|||
|
||||
func (s *sqlDatabase) ListEnterprises(_ context.Context) ([]params.Enterprise, error) {
|
||||
var enterprises []Enterprise
|
||||
q := s.conn.Preload("Credentials").Find(&enterprises)
|
||||
q := s.conn.Preload("Credentials").Preload("Credentials.Endpoint").Find(&enterprises)
|
||||
if q.Error != nil {
|
||||
return []params.Enterprise{}, errors.Wrap(q.Error, "fetching enterprises")
|
||||
}
|
||||
|
|
@ -183,6 +183,7 @@ func (s *sqlDatabase) getEnterprise(_ context.Context, name string) (Enterprise,
|
|||
|
||||
q := s.conn.Where("name = ? COLLATE NOCASE", name).
|
||||
Preload("Credentials").
|
||||
Preload("Credentials.Endpoint").
|
||||
Preload("Endpoint").
|
||||
First(&enterprise)
|
||||
if q.Error != nil {
|
||||
|
|
|
|||
|
|
@ -1,3 +1,17 @@
|
|||
// Copyright 2024 Cloudbase Solutions SRL
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License"); you may
|
||||
// not use this file except in compliance with the License. You may obtain
|
||||
// a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
// License for the specific language governing permissions and limitations
|
||||
// under the License.
|
||||
|
||||
package sql
|
||||
|
||||
import (
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ func (s *sqlDatabase) GetOrganization(ctx context.Context, name string) (params.
|
|||
|
||||
func (s *sqlDatabase) ListOrganizations(_ context.Context) ([]params.Organization, error) {
|
||||
var orgs []Organization
|
||||
q := s.conn.Preload("Credentials").Find(&orgs)
|
||||
q := s.conn.Preload("Credentials").Preload("Credentials.Endpoint").Find(&orgs)
|
||||
if q.Error != nil {
|
||||
return []params.Organization{}, errors.Wrap(q.Error, "fetching org from database")
|
||||
}
|
||||
|
|
@ -213,6 +213,7 @@ func (s *sqlDatabase) getOrg(_ context.Context, name string) (Organization, erro
|
|||
|
||||
q := s.conn.Where("name = ? COLLATE NOCASE", name).
|
||||
Preload("Credentials").
|
||||
Preload("Credentials.Endpoint").
|
||||
Preload("Endpoint").
|
||||
First(&org)
|
||||
if q.Error != nil {
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ func (s *sqlDatabase) GetRepository(ctx context.Context, owner, name string) (pa
|
|||
|
||||
func (s *sqlDatabase) ListRepositories(_ context.Context) ([]params.Repository, error) {
|
||||
var repos []Repository
|
||||
q := s.conn.Preload("Credentials").Find(&repos)
|
||||
q := s.conn.Preload("Credentials").Preload("Credentials.Endpoint").Find(&repos)
|
||||
if q.Error != nil {
|
||||
return []params.Repository{}, errors.Wrap(q.Error, "fetching user from database")
|
||||
}
|
||||
|
|
@ -186,6 +186,7 @@ func (s *sqlDatabase) getRepo(_ context.Context, owner, name string) (Repository
|
|||
|
||||
q := s.conn.Where("name = ? COLLATE NOCASE and owner = ? COLLATE NOCASE", name, owner).
|
||||
Preload("Credentials").
|
||||
Preload("Credentials.Endpoint").
|
||||
Preload("Endpoint").
|
||||
First(&repo)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue