customer

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jun 19, 2026 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PersonaWhale      = "WHALE"
	PersonaGold       = "GOLD"
	PersonaFrustrated = "FRUSTRATED"
	PersonaRegular    = "REGULAR"
	PersonaNewbie     = "NEWBIE"
)

Personas.

View Source
const (
	TaskCalculatePersona = "customer.calculate_persona"
	TaskUpdatePersona    = "customer.update_persona"
	TaskUpdateDetails    = "customer.update_details"
)

Workflow task names.

View Source
const (
	EventCustomerProfileCreated = "customer.profile_created"
)

Event types.

Variables

This section is empty.

Functions

This section is empty.

Types

type Address

type Address struct {
	ID           string         `gorm:"primaryKey" json:"id"`
	CustomerID   string         `gorm:"index;not null" json:"customerId"`
	ReceiverName string         `json:"receiverName"` // Recipient name
	Phone        string         `json:"phone"`        // Contact number for delivery
	Line1        string         `json:"line1"`
	Line2        string         `json:"line2"`
	City         string         `json:"city"`
	State        string         `json:"state"`
	Zip          string         `json:"zip"`
	Country      string         `json:"country"`
	CreatedAt    time.Time      `json:"createdAt"`
	UpdatedAt    time.Time      `json:"updatedAt"`
	DeletedAt    gorm.DeletedAt `gorm:"index" json:"-"`
}

Address represents a customer's physical shipping or billing location.

type CreateAddressInput added in v0.4.0

type CreateAddressInput struct {
	ReceiverName *string `json:"receiverName"`
	Phone        *string `json:"phone"`
	Line1        string  `json:"line1"`
	Line2        *string `json:"line2"`
	City         string  `json:"city"`
	State        string  `json:"state"`
	Zip          string  `json:"zip"`
	Country      string  `json:"country"`
}

type CreateCustomerInput added in v0.4.0

type CreateCustomerInput struct {
	UserID   *string      `json:"userId"`
	IsGuest  *bool        `json:"isGuest"`
	Name     string       `json:"name"`
	Email    string       `json:"email"`
	Phone    *string      `json:"phone"`
	Metadata mdk.Metadata `json:"metadata"`
}

Input mapping structures for GraphQL endpoints.

type Customer

type Customer struct {
	ID                       string         `gorm:"primaryKey" json:"id"`
	UserID                   string         `gorm:"index" json:"userId"` // Links to user account in 'auth' module (empty for guests)
	IsGuest                  bool           `gorm:"default:false" json:"isGuest"`
	Name                     string         `json:"name"`
	Email                    string         `json:"email"`
	Phone                    string         `json:"phone"`
	DefaultShippingAddressID *string        `json:"defaultShippingAddressId"`
	DefaultBillingAddressID  *string        `json:"defaultBillingAddressId"`
	Addresses                []Address      `gorm:"foreignKey:CustomerID;constraint:OnDelete:CASCADE" json:"addresses"`
	Metadata                 mdk.Metadata   `gorm:"type:text" json:"metadata"`
	CreatedAt                time.Time      `json:"createdAt"`
	UpdatedAt                time.Time      `json:"updatedAt"`
	DeletedAt                gorm.DeletedAt `gorm:"index" json:"-"`
}

Customer represents a customer profile.

type Module

type Module struct {
	// contains filtered or unexported fields
}

Module implements the mdk.Module interface for Customer.

func NewModule

func NewModule() *Module

NewModule creates a new instance of the Customer module.

func (*Module) AddAddressStepHandler added in v0.4.0

func (m *Module) AddAddressStepHandler(sCtx mdk.StepContext) mdk.StepResult

func (*Module) AddCustomerAddress added in v0.4.0

func (m *Module) AddCustomerAddress(ctx context.Context, customerID string, input CreateAddressInput) (*Address, error)

AddCustomerAddress adds a shipping/billing address to a customer profile.

func (*Module) CreateCustomer added in v0.4.0

func (m *Module) CreateCustomer(ctx context.Context, input CreateCustomerInput) (*Customer, error)

CreateCustomer creates a new customer profile.

func (*Module) CreateProfileStep added in v0.4.0

func (m *Module) CreateProfileStep(sCtx mdk.StepContext) mdk.StepResult

func (*Module) DeleteCustomer added in v0.4.0

func (m *Module) DeleteCustomer(ctx context.Context, id string) (bool, error)

DeleteCustomer deletes a customer record.

func (*Module) DeleteCustomerAddress added in v0.4.0

func (m *Module) DeleteCustomerAddress(ctx context.Context, addressID string) (bool, error)

DeleteCustomerAddress deletes an address record.

func (*Module) DeleteCustomerStepHandler added in v0.4.0

func (m *Module) DeleteCustomerStepHandler(sCtx mdk.StepContext) mdk.StepResult

func (*Module) FieldResolvers

func (m *Module) FieldResolvers() map[string]any

FieldResolvers exposes custom field-level resolvers.

func (*Module) GetCustomer

func (m *Module) GetCustomer(ctx context.Context, id string) (*Customer, error)

GetCustomer retrieves an individual customer by ID.

func (*Module) GetCustomerAddresses added in v0.4.0

func (m *Module) GetCustomerAddresses(ctx context.Context, customerID string) ([]*Address, error)

GetCustomerAddresses lists all addresses belonging to a customer.

func (*Module) GetCustomerStep added in v0.4.0

func (m *Module) GetCustomerStep(sCtx mdk.StepContext) mdk.StepResult

func (*Module) ID

func (m *Module) ID() string

ID returns the unique identifier for the customer module.

func (*Module) Init

func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error

Init initializes the customer module, subscribing to identity events to seed customer profiles.

func (*Module) ListCustomers

func (m *Module) ListCustomers(ctx context.Context) ([]*Customer, error)

ListCustomers retrieves a list of all customer profiles.

func (*Module) ListCustomersStep added in v0.4.0

func (m *Module) ListCustomersStep(sCtx mdk.StepContext) mdk.StepResult

func (*Module) ListResources added in v0.4.0

func (m *Module) ListResources(ctx context.Context) ([]mdk.MCPResource, error)

func (*Module) Models

func (m *Module) Models() []any

Models registers GORM database structures for database migrations.

func (*Module) Mutations

func (m *Module) Mutations() map[string]any

Mutations exposes resolver mutation maps.

func (*Module) Queries

func (m *Module) Queries() map[string]any

Queries exposes resolver query maps.

func (*Module) ReadResource added in v0.4.0

func (m *Module) ReadResource(ctx context.Context, uri string) (string, error)

func (*Module) Repo

func (m *Module) Repo() *Repository

Repo returns the customer Repository.

func (*Module) Routes

func (m *Module) Routes() []mdk.Route

Routes returns HTTP endpoints (none for this module).

func (*Module) Shutdown

func (m *Module) Shutdown(ctx context.Context) error

Shutdown cleans up resources.

func (*Module) UpdateCustomer

func (m *Module) UpdateCustomer(ctx context.Context, id string, input UpdateCustomerInput) (*Customer, error)

UpdateCustomer updates customer profile details and dynamically updates default addresses.

func (*Module) UpdateCustomerAddress added in v0.4.0

func (m *Module) UpdateCustomerAddress(ctx context.Context, addressID string, input UpdateAddressInput) (*Address, error)

UpdateCustomerAddress updates address record values.

type Repository

type Repository struct {
	// contains filtered or unexported fields
}

Repository handles database interactions for Customers and Addresses.

func NewRepository

func NewRepository(database *gorm.DB) *Repository

NewRepository creates a new customer Repository.

func (*Repository) Delete added in v0.4.0

func (r *Repository) Delete(ctx context.Context, id string) error

Delete removes a customer profile from the database.

func (*Repository) DeleteAddress added in v0.4.0

func (r *Repository) DeleteAddress(ctx context.Context, id string) error

DeleteAddress deletes an address record.

func (*Repository) GetAddressByID added in v0.4.0

func (r *Repository) GetAddressByID(ctx context.Context, id string) (*Address, error)

GetAddressByID retrieves a specific address by its ID.

func (*Repository) GetAddressesByCustomerID added in v0.4.0

func (r *Repository) GetAddressesByCustomerID(ctx context.Context, customerID string) ([]*Address, error)

GetAddressesByCustomerID lists all addresses registered under a customer.

func (*Repository) GetByID

func (r *Repository) GetByID(ctx context.Context, id string) (*Customer, error)

GetByID retrieves a customer profile by its unique ID.

func (*Repository) GetByUserID

func (r *Repository) GetByUserID(ctx context.Context, userID string) (*Customer, error)

GetByUserID retrieves a customer profile by its user identifier.

func (*Repository) List

func (r *Repository) List(ctx context.Context) ([]*Customer, error)

List lists all customer profiles in the database.

func (*Repository) Save

func (r *Repository) Save(ctx context.Context, c *Customer) error

Save persists a customer record.

func (*Repository) SaveAddress added in v0.4.0

func (r *Repository) SaveAddress(ctx context.Context, addr *Address) error

SaveAddress saves or updates an address record.

type UpdateAddressInput added in v0.4.0

type UpdateAddressInput struct {
	ReceiverName *string `json:"receiverName"`
	Phone        *string `json:"phone"`
	Line1        *string `json:"line1"`
	Line2        *string `json:"line2"`
	City         *string `json:"city"`
	State        *string `json:"state"`
	Zip          *string `json:"zip"`
	Country      *string `json:"country"`
}

type UpdateCustomerInput

type UpdateCustomerInput struct {
	Name                     *string      `json:"name"`
	Email                    *string      `json:"email"`
	Phone                    *string      `json:"phone"`
	DefaultShippingAddressID *string      `json:"defaultShippingAddressId"`
	DefaultBillingAddressID  *string      `json:"defaultBillingAddressId"`
	Metadata                 mdk.Metadata `json:"metadata"`
}

Jump to

Keyboard shortcuts

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