dataloaders

package
v0.0.0-...-64a628e Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 20, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CTXWithLoaders

func CTXWithLoaders(ctx context.Context, buildDataloaders BuildDataloaders) context.Context

CTXWithLoaders sets the given dataloaders onto given context

func FetchUserInfoByEUAUserID

func FetchUserInfoByEUAUserID(ctx context.Context, euaUserID string) (*models.UserInfo, error)

func GetBusinessCaseLifecycleCostsByBizCaseID

func GetBusinessCaseLifecycleCostsByBizCaseID(ctx context.Context, businessCaseID uuid.UUID) ([]*models.EstimatedLifecycleCost, error)

func GetCedarSystemByID

func GetCedarSystemByID(ctx context.Context, cedarSystemID string) (*models.CedarSystem, error)

func GetCedarSystemIsBookmarked

func GetCedarSystemIsBookmarked(ctx context.Context, cedarSystemID string, euaUserID string) (bool, error)

func GetCedarSystemLinkedSystemIntakes

func GetCedarSystemLinkedSystemIntakes(ctx context.Context, cedarSystemID string, state models.SystemIntakeState) ([]*models.SystemIntake, error)

func GetCedarSystemLinkedTRBRequests

func GetCedarSystemLinkedTRBRequests(ctx context.Context, cedarSystemID string, state models.TRBRequestState) ([]*models.TRBRequest, error)

func GetNewestTRBRequestFeedbackByTRBRequestID

func GetNewestTRBRequestFeedbackByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) (*models.TRBRequestFeedback, error)

func GetRelatedSystemIntakesBySystemIntakeID

func GetRelatedSystemIntakesBySystemIntakeID(ctx context.Context, intakeID uuid.UUID) ([]*models.SystemIntake, error)

GetRelatedSystemIntakesBySystemIntakeID gets related intakes by intake ID

func GetRelatedSystemIntakesByTRBRequestID

func GetRelatedSystemIntakesByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.SystemIntake, error)

GetRelatedSystemIntakesByTRBRequestID gets related system intakes by TRB Request ID

func GetRelatedTRBRequestsBySystemIntakeID

func GetRelatedTRBRequestsBySystemIntakeID(ctx context.Context, intakeID uuid.UUID) ([]*models.TRBRequest, error)

GetRelatedTRBRequestsBySystemIntakeID gets related TRB Requests by system intake ID

func GetRelatedTRBRequestsByTRBRequestID

func GetRelatedTRBRequestsByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBRequest, error)

GetRelatedTRBRequestsByTRBRequestID gets related TRB Requests by TRB Request ID

func GetSystemIntakeActionsBySystemIntakeID

func GetSystemIntakeActionsBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.Action, error)

func GetSystemIntakeBusinessCaseBySystemIntakeID

func GetSystemIntakeBusinessCaseBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) (*models.BusinessCase, error)

func GetSystemIntakeContractNumbersBySystemIntakeID

func GetSystemIntakeContractNumbersBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeContractNumber, error)

func GetSystemIntakeDocumentsBySystemIntakeID

func GetSystemIntakeDocumentsBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeDocument, error)

func GetSystemIntakeFundingSourceBySystemIntakeID

func GetSystemIntakeFundingSourceBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeFundingSource, error)

func GetSystemIntakeGRBReviewersBySystemIntakeID

func GetSystemIntakeGRBReviewersBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeGRBReviewer, error)

func GetSystemIntakeGovReqFeedbackByIntakeID

func GetSystemIntakeGovReqFeedbackByIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.GovernanceRequestFeedback, error)

func GetSystemIntakeNotesBySystemIntakeID

func GetSystemIntakeNotesBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeNote, error)

func GetSystemIntakeSystemsBySystemIntakeID

func GetSystemIntakeSystemsBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeSystem, error)

func GetTRBAdminNotesByTRBRequestID

func GetTRBAdminNotesByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBAdminNote, error)

func GetTRBAttendeeByEUAIDAndTRBRequestID

func GetTRBAttendeeByEUAIDAndTRBRequestID(ctx context.Context, euaID string, trbRequestID uuid.UUID) (*models.TRBRequestAttendee, error)

func GetTRBAttendeesByTRBRequestID

func GetTRBAttendeesByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBRequestAttendee, error)

func GetTRBFundingSourcesByRequestID

func GetTRBFundingSourcesByRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBFundingSource, error)

func GetTRBGuidanceLetterByTRBRequestID

func GetTRBGuidanceLetterByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) (*models.TRBGuidanceLetter, error)

func GetTRBRequestContractNumbersByTRBRequestID

func GetTRBRequestContractNumbersByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBRequestContractNumber, error)

func GetTRBRequestDocumentsByRequestID

func GetTRBRequestDocumentsByRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBRequestDocument, error)

func GetTRBRequestFeedbackByTRBRequestID

func GetTRBRequestFeedbackByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBRequestFeedback, error)

func GetTRBRequestFormByTRBRequestID

func GetTRBRequestFormByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) (*models.TRBRequestForm, error)

func GetTRBRequestFormSystemIntakesByTRBRequestID

func GetTRBRequestFormSystemIntakesByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.SystemIntake, error)

func GetTRBRequestSystemsByTRBRequestID

func GetTRBRequestSystemsByTRBRequestID(ctx context.Context, trbRequestID uuid.UUID) ([]*models.TRBRequestSystem, error)

func GetUserAccountByID

func GetUserAccountByID(ctx context.Context, userID uuid.UUID) (*authentication.UserAccount, error)

func NewDataloaderMiddleware

func NewDataloaderMiddleware(buildDataloaders BuildDataloaders) mux.MiddlewareFunc

Types

type BuildDataloaders

type BuildDataloaders func() *Dataloaders

BuildDataloaders builds and returns a set of dataloaders - useful for supplying each new HTTP request with its own set of dataloaders

type Dataloaders

type Dataloaders struct {
	BusinessCaseLifecycleCosts       *dataloadgen.Loader[uuid.UUID, []*models.EstimatedLifecycleCost]
	CedarSystemBookmark              *dataloadgen.Loader[models.BookmarkRequest, bool]
	CedarSystemLinkedSystemIntakes   *dataloadgen.Loader[models.SystemIntakesByCedarSystemIDsRequest, []*models.SystemIntake]
	CedarSystemLinkedTRBRequests     *dataloadgen.Loader[models.TRBRequestsByCedarSystemIDsRequest, []*models.TRBRequest]
	FetchUserInfo                    *dataloadgen.Loader[string, *models.UserInfo]
	GetUserAccount                   *dataloadgen.Loader[uuid.UUID, *authentication.UserAccount]
	GetCedarSystem                   *dataloadgen.Loader[string, *models.CedarSystem]
	SystemIntakeActions              *dataloadgen.Loader[uuid.UUID, []*models.Action]
	SystemIntakeBusinessCase         *dataloadgen.Loader[uuid.UUID, *models.BusinessCase]
	SystemIntakeContractNumbers      *dataloadgen.Loader[uuid.UUID, []*models.SystemIntakeContractNumber]
	SystemIntakeDocuments            *dataloadgen.Loader[uuid.UUID, []*models.SystemIntakeDocument]
	SystemIntakeFundingSources       *dataloadgen.Loader[uuid.UUID, []*models.SystemIntakeFundingSource]
	SystemIntakeGovReqFeedback       *dataloadgen.Loader[uuid.UUID, []*models.GovernanceRequestFeedback]
	SystemIntakeGRBReviewers         *dataloadgen.Loader[uuid.UUID, []*models.SystemIntakeGRBReviewer]
	SystemIntakeNotes                *dataloadgen.Loader[uuid.UUID, []*models.SystemIntakeNote]
	SystemIntakeRelatedSystemIntakes *dataloadgen.Loader[uuid.UUID, []*models.SystemIntake]
	SystemIntakeRelatedTRBRequests   *dataloadgen.Loader[uuid.UUID, []*models.TRBRequest]
	SystemIntakeSystems              *dataloadgen.Loader[uuid.UUID, []*models.SystemIntakeSystem]
	TRBFundingSources                *dataloadgen.Loader[uuid.UUID, []*models.TRBFundingSource]
	TRBRequestAdminNotes             *dataloadgen.Loader[uuid.UUID, []*models.TRBAdminNote]
	TRBRequestGuidanceLetter         *dataloadgen.Loader[uuid.UUID, *models.TRBGuidanceLetter]
	TRBRequestAttendees              *dataloadgen.Loader[uuid.UUID, []*models.TRBRequestAttendee]
	TRBRequestAttendeeByEUA          *dataloadgen.Loader[models.TRBAttendeeByTRBAndEUAIDRequest, *models.TRBRequestAttendee]
	TRBRequestContractNumbers        *dataloadgen.Loader[uuid.UUID, []*models.TRBRequestContractNumber]
	TRBRequestDocuments              *dataloadgen.Loader[uuid.UUID, []*models.TRBRequestDocument]
	TRBRequestForm                   *dataloadgen.Loader[uuid.UUID, *models.TRBRequestForm]
	TRBRequestFeedback               *dataloadgen.Loader[uuid.UUID, []*models.TRBRequestFeedback]
	TRBRequestFeedbackNewest         *dataloadgen.Loader[uuid.UUID, *models.TRBRequestFeedback]
	TRBRequestRelatedSystemIntakes   *dataloadgen.Loader[uuid.UUID, []*models.SystemIntake]
	TRBRequestRelatedTRBRequests     *dataloadgen.Loader[uuid.UUID, []*models.TRBRequest]
	TRBRequestSystems                *dataloadgen.Loader[uuid.UUID, []*models.TRBRequestSystem]
	TRBRequestFormSystemIntakes      *dataloadgen.Loader[uuid.UUID, []*models.SystemIntake]
}

Dataloaders houses all dataloader-capable functionality to create a new dataloader, create a new property in this struct and give it the request type and return type for ONE item (i.e., even though you can pass a dataloader a list of UUIDs to get a list of UserAccounts, the definition must be one-one (request-response) - in this example [uuid.UUID, UserAccount])

then, create a file in this package and create two functions in there

  1. a method on the `dataReader` type - this is our batching function - this function will take a slice of the request type (in the example above, it would take []uuid.UUID) - this function will return a slice of the response type (in this example, []UserAccount)
  2. an exported function which takes/returns the one-one relationship defined below

example of this:

// take in a slice of inputs (uuids) and returns a slice of outputs (each uuid gets its own slice of `*models.SystemIntakeSystem`)
func (d *dataReader) batchSystemIntakeSystemsBySystemIntakeIDs(ctx context.Context, systemIntakeIDs []uuid.UUID) ([][]*models.SystemIntakeSystem, []error) {
	data, err := d.db.SystemIntakeSystemsBySystemIntakeIDs(ctx, systemIntakeIDs)
	if err != nil {
		return nil, []error{err}
	}

	return helpers.OneToMany[*models.SystemIntakeSystem](systemIntakeIDs, data), nil
}

// take in a one-one relationship (a single uuid gets a single slice)
func GetSystemIntakeSystemsBySystemIntakeID(ctx context.Context, systemIntakeID uuid.UUID) ([]*models.SystemIntakeSystem, error) {
	loaders, ok := loadersFromCTX(ctx)
	if !ok {
		return nil, errors.New("unexpected nil loaders in GetSystemIntakeSystemsBySystemIntakeID")
	}

	return loaders.SystemIntakeSystems.Load(ctx, systemIntakeID)
}

you can then edit NewDataloaders below to include your new dataloader in the return

func NewDataloaders

func NewDataloaders(store *storage.Store, fetchUserInfos fetchUserInfosFunc, getCedarSystems getCedarSystemsFunc) *Dataloaders

NewDataloaders returns a new set of dataloaders

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL