ordertrigger

package module
v0.0.0-...-3d84a2e Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2023 License: MIT-0 Imports: 8 Imported by: 0

README

The Order Firestore Trigger Function

The Order Firestore Trigger is a Cloud Function that is invoked in response to Firestore document updates. Specifically, creates/updates of order documents written by the gRPC API order-servce.

Essentially, since orders are only written to Firestore once, and the order-service API is read only, orders will be published as soon as they are added to the order-service and not again thereafter unless a republish is forced.

Documentation

Overview

Package ordertrigger handles Firestore trigger invocations when order documents are updated.

Index

Constants

This section is empty.

Variables

View Source
var (
	// TopicProjectId is a variable so that unit tests can override it to ensures that test requests are not
	// routed to the live project! See https://firebase.google.com/docs/emulator-suite/connect_firestore
	TopicProjectId string

	// TopicId a variable so that unit tests can override it to force errors to occur
	TopicId string
)

Functions

func OrderTrigger

func OrderTrigger(ctx context.Context, e FirestoreEvent) error

OrderTrigger receives a document update Firestore trigger event. The function is deployed with a trigger configuration (see Makefile) that will notify the handler of all updates to the root document of an Order.

Types

type FirestoreEvent

type FirestoreEvent struct {
	OldValue   FirestoreValue `json:"oldValue"`
	Value      FirestoreValue `json:"value"`
	UpdateMask struct {
		FieldPaths []string `json:"fieldPaths"`
	} `json:"updateMask"`
}

FirestoreEvent is the payload of a Firestore event.

type FirestoreOrder

type FirestoreOrder struct {
	Id     StringValue  `json:"id"`
	Status IntegerValue `json:"status"`
}

FirestoreOrder describes the document fields that we need to know about as they will be found in the event data (not as we would prefer them, in the structure that we submitted to the Firestore API to populate the document in the first place :-(

type FirestoreValue

type FirestoreValue struct {
	CreateTime time.Time      `json:"createTime"`
	Fields     FirestoreOrder `json:"fields"`
	Name       string         `json:"name"`
	UpdateTime time.Time      `json:"updateTime"`
}

FirestoreValue holds Firestore document fields.

type IntegerValue

type IntegerValue struct {
	IntegerValue string `json:"integerValue"`
}

type OrderServiceClient

type OrderServiceClient interface {
	GetOrder(ctx context.Context, orderId string) (*pborder.Order, error)
}

OrderServiceClient is a wrapper for the order service that supports lazy loading of the service and unit test error generation.

type OrderServiceClientImpl

type OrderServiceClientImpl struct {
	OrderServiceClient
	// contains filtered or unexported fields
}

OrderServiceClientImpl is the default implementation of the OrderServiceClient interface. error generation.

func (*OrderServiceClientImpl) GetOrder

func (c *OrderServiceClientImpl) GetOrder(ctx context.Context, orderId string) (*pborder.Order, error)

GetOrder loads a fully populated order from Firestore.

type PubSubClient

type PubSubClient interface {
	Publish(ctx context.Context, order *pborder.Order) error
}

PubSubClient is a wrapper for our Google client that supports lazy loading of the client and unit test error generation.

type PubSubClientImpl

type PubSubClientImpl struct {
	PubSubClient
	// contains filtered or unexported fields
}

PubSubClientImpl is the default implementation of the PubSubClient interface.

func (*PubSubClientImpl) Publish

func (c *PubSubClientImpl) Publish(ctx context.Context, order *pborder.Order) error

Publish submits a binary message to our configured Pub/Sub topic.

type StringValue

type StringValue struct {
	StringValue string `json:"stringValue"`
}

Jump to

Keyboard shortcuts

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