Add people data model

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-01-30 14:48:04 -08:00
parent 2b42da722e
commit 95649a0849
8 changed files with 1231 additions and 3 deletions

View File

@@ -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

View 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,
}
}

View File

@@ -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"`

View File

@@ -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() {