@@ -46,11 +46,36 @@ type Organization implements Node {
|
||||
before: CursorKey
|
||||
): VendorConnection! @goField(forceResolver: true)
|
||||
|
||||
peoples(
|
||||
first: Int
|
||||
after: CursorKey
|
||||
last: Int
|
||||
before: CursorKey
|
||||
): PeopleConnection! @goField(forceResolver: true)
|
||||
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type PeopleConnection {
|
||||
edges: [PeopleEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
}
|
||||
|
||||
type PeopleEdge {
|
||||
cursor: CursorKey!
|
||||
node: People!
|
||||
}
|
||||
|
||||
type People implements Node {
|
||||
id: ID!
|
||||
fullName: String!
|
||||
primaryEmailAddress: String!
|
||||
additionalEmailAddresses: [String!]!
|
||||
createdAt: Datetime!
|
||||
updatedAt: Datetime!
|
||||
}
|
||||
|
||||
type VendorConnection {
|
||||
edges: [VendorEdge!]!
|
||||
pageInfo: PageInfo!
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
51
pkg/api/console/v1/types/people.go
Normal file
51
pkg/api/console/v1/types/people.go
Normal file
@@ -0,0 +1,51 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package types
|
||||
|
||||
import (
|
||||
"github.com/getprobo/probo/pkg/probo/coredata"
|
||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||
)
|
||||
|
||||
func NewPeopleConnection(p *page.Page[*coredata.People]) *PeopleConnection {
|
||||
var edges = make([]*PeopleEdge, len(p.Data))
|
||||
|
||||
for i := range edges {
|
||||
edges[i] = NewPeopleEdge(p.Data[i])
|
||||
}
|
||||
|
||||
return &PeopleConnection{
|
||||
Edges: edges,
|
||||
PageInfo: NewPageInfo(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewPeopleEdge(p *coredata.People) *PeopleEdge {
|
||||
return &PeopleEdge{
|
||||
Cursor: p.CursorKey(),
|
||||
Node: NewPeople(p),
|
||||
}
|
||||
}
|
||||
|
||||
func NewPeople(p *coredata.People) *People {
|
||||
return &People{
|
||||
ID: p.ID,
|
||||
FullName: p.FullName,
|
||||
PrimaryEmailAddress: p.PrimaryEmailAddress,
|
||||
AdditionalEmailAddresses: p.AdditionalEmailAddresses,
|
||||
CreatedAt: p.CreatedAt,
|
||||
UpdatedAt: p.UpdatedAt,
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,7 @@ type Organization struct {
|
||||
Name string `json:"name"`
|
||||
Frameworks *FrameworkConnection `json:"frameworks"`
|
||||
Vendors *VendorConnection `json:"vendors"`
|
||||
Peoples *PeopleConnection `json:"peoples"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
@@ -121,6 +122,28 @@ type PageInfo struct {
|
||||
EndCursor *page.CursorKey `json:"endCursor,omitempty"`
|
||||
}
|
||||
|
||||
type People struct {
|
||||
ID gid.GID `json:"id"`
|
||||
FullName string `json:"fullName"`
|
||||
PrimaryEmailAddress string `json:"primaryEmailAddress"`
|
||||
AdditionalEmailAddresses []string `json:"additionalEmailAddresses"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (People) IsNode() {}
|
||||
func (this People) GetID() gid.GID { return this.ID }
|
||||
|
||||
type PeopleConnection struct {
|
||||
Edges []*PeopleEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
}
|
||||
|
||||
type PeopleEdge struct {
|
||||
Cursor page.CursorKey `json:"cursor"`
|
||||
Node *People `json:"node"`
|
||||
}
|
||||
|
||||
type Query struct {
|
||||
}
|
||||
|
||||
@@ -153,6 +176,9 @@ type Vendor struct {
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (Vendor) IsNode() {}
|
||||
func (this Vendor) GetID() gid.GID { return this.ID }
|
||||
|
||||
type VendorConnection struct {
|
||||
Edges []*VendorEdge `json:"edges"`
|
||||
PageInfo *PageInfo `json:"pageInfo"`
|
||||
|
||||
@@ -70,12 +70,24 @@ func (r *organizationResolver) Vendors(ctx context.Context, obj *types.Organizat
|
||||
|
||||
page, err := r.svc.ListOrganizationVendors(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list organization frameworks: %w", err)
|
||||
return nil, fmt.Errorf("cannot list organization vendors: %w", err)
|
||||
}
|
||||
|
||||
return types.NewVendorConnection(page), nil
|
||||
}
|
||||
|
||||
// Peoples is the resolver for the peoples field.
|
||||
func (r *organizationResolver) Peoples(ctx context.Context, obj *types.Organization, first *int, after *page.CursorKey, last *int, before *page.CursorKey) (*types.PeopleConnection, error) {
|
||||
cursor := types.NewCursor(first, after, last, before)
|
||||
|
||||
page, err := r.svc.ListOrganizationPeoples(ctx, obj.ID, cursor)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot list organization peoples: %w", err)
|
||||
}
|
||||
|
||||
return types.NewPeopleConnection(page), nil
|
||||
}
|
||||
|
||||
// Node is the resolver for the node field.
|
||||
func (r *queryResolver) Node(ctx context.Context, id gid.GID) (types.Node, error) {
|
||||
switch id.EntityType() {
|
||||
|
||||
9
pkg/probo/coredata/migrations/20250130T144500Z.sql
Normal file
9
pkg/probo/coredata/migrations/20250130T144500Z.sql
Normal file
@@ -0,0 +1,9 @@
|
||||
CREATE TABLE peoples (
|
||||
id TEXT PRIMARY KEY,
|
||||
organization_id TEXT REFERENCES organizations(id) NOT NULL,
|
||||
full_name TEXT NOT NULL,
|
||||
primary_email_address TEXT NOT NULL,
|
||||
additional_email_addresses TEXT[] NOT NULL,
|
||||
created_at TIMESTAMP WITH TIME ZONE,
|
||||
updated_at TIMESTAMP WITH TIME ZONE
|
||||
);
|
||||
113
pkg/probo/coredata/people.go
Normal file
113
pkg/probo/coredata/people.go
Normal file
@@ -0,0 +1,113 @@
|
||||
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
|
||||
//
|
||||
// Permission to use, copy, modify, and/or distribute this software for any
|
||||
// purpose with or without fee is hereby granted, provided that the above
|
||||
// copyright notice and this permission notice appear in all copies.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
|
||||
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
|
||||
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
|
||||
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
||||
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
|
||||
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
|
||||
// PERFORMANCE OF THIS SOFTWARE.
|
||||
|
||||
package coredata
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"maps"
|
||||
"time"
|
||||
|
||||
"github.com/getprobo/probo/pkg/probo/coredata/gid"
|
||||
"github.com/getprobo/probo/pkg/probo/coredata/page"
|
||||
"github.com/jackc/pgx/v5"
|
||||
"go.gearno.de/crypto/uuid"
|
||||
"go.gearno.de/kit/pg"
|
||||
)
|
||||
|
||||
type (
|
||||
People struct {
|
||||
ID gid.GID
|
||||
OrganizationID gid.GID
|
||||
FullName string
|
||||
PrimaryEmailAddress string
|
||||
AdditionalEmailAddresses []string
|
||||
CreatedAt time.Time
|
||||
UpdatedAt time.Time
|
||||
}
|
||||
|
||||
Peoples []*People
|
||||
)
|
||||
|
||||
func (p People) CursorKey() page.CursorKey {
|
||||
return page.NewCursorKey(uuid.UUID(p.ID), p.CreatedAt)
|
||||
}
|
||||
|
||||
func (p *People) scan(r pgx.Row) error {
|
||||
return r.Scan(
|
||||
&p.ID,
|
||||
&p.OrganizationID,
|
||||
&p.FullName,
|
||||
&p.PrimaryEmailAddress,
|
||||
&p.PrimaryEmailAddress,
|
||||
&p.CreatedAt,
|
||||
&p.UpdatedAt,
|
||||
)
|
||||
}
|
||||
|
||||
func (p *Peoples) LoadByOrganizationID(
|
||||
ctx context.Context,
|
||||
conn pg.Conn,
|
||||
scope *Scope,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
) error {
|
||||
q := `
|
||||
SELECT
|
||||
id,
|
||||
organization_id,
|
||||
full_name,
|
||||
primary_email_address,
|
||||
additional_email_addresses,
|
||||
created_at,
|
||||
updated_at
|
||||
FROM
|
||||
peoples
|
||||
WHERE
|
||||
%s
|
||||
AND organization_id = @organization_id
|
||||
AND %s
|
||||
`
|
||||
|
||||
q = fmt.Sprintf(q, scope.SQLFragment(), cursor.SQLFragment())
|
||||
|
||||
args := pgx.NamedArgs{"organization_id": organizationID}
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
maps.Copy(args, cursor.SQLArguments())
|
||||
|
||||
r, err := conn.Query(ctx, q, args)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
peoples := Peoples{}
|
||||
for r.Next() {
|
||||
people := &People{}
|
||||
if err := people.scan(r); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
peoples = append(peoples, people)
|
||||
}
|
||||
|
||||
if err := r.Err(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
*p = peoples
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -230,3 +230,30 @@ func (s Service) ListOrganizationVendors(
|
||||
|
||||
return page.NewPage(vendors, cursor), nil
|
||||
}
|
||||
|
||||
func (s Service) ListOrganizationPeoples(
|
||||
ctx context.Context,
|
||||
organizationID gid.GID,
|
||||
cursor *page.Cursor,
|
||||
) (*page.Page[*coredata.People], error) {
|
||||
var peoples coredata.Peoples
|
||||
|
||||
err := s.pg.WithConn(
|
||||
ctx,
|
||||
func(conn pg.Conn) error {
|
||||
return peoples.LoadByOrganizationID(
|
||||
ctx,
|
||||
conn,
|
||||
s.scope,
|
||||
organizationID,
|
||||
cursor,
|
||||
)
|
||||
},
|
||||
)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return page.NewPage(peoples, cursor), nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user