Add total count to vendors connection

Signed-off-by: Émile Ré <emile@getprobo.com>
This commit is contained in:
Émile Ré
2026-01-27 18:48:29 +04:00
parent b2b52318f5
commit 34a6ed1223
9 changed files with 198 additions and 17 deletions

View File

@@ -18,10 +18,10 @@ import (
"context"
"fmt"
"go.gearno.de/kit/pg"
"go.probo.inc/probo/pkg/coredata"
"go.probo.inc/probo/pkg/gid"
"go.probo.inc/probo/pkg/page"
"go.gearno.de/kit/pg"
)
type VendorService struct {
@@ -82,3 +82,37 @@ func (s VendorService) ListForOrganizationId(
return page.NewPage(vendors, cursor), nil
}
func (s VendorService) CountForTrustCenterId(
ctx context.Context,
trustCenterID gid.GID,
) (int, error) {
var count int
err := s.svc.pg.WithConn(
ctx,
func(conn pg.Conn) (err error) {
trustCenter, _, err := s.svc.TrustCenters.Get(ctx, trustCenterID)
if err != nil {
return fmt.Errorf("cannot load trust center: %w", err)
}
vendors := &coredata.Vendors{}
showOnTrustCenter := true
var nilSnapshotID *gid.GID = nil
filter := coredata.NewVendorFilter(&nilSnapshotID, &showOnTrustCenter)
count, err = vendors.CountByOrganizationID(ctx, conn, s.svc.scope, trustCenter.OrganizationID, filter)
if err != nil {
return fmt.Errorf("cannot count vendors: %w", err)
}
return nil
},
)
if err != nil {
return 0, err
}
return count, nil
}