Documentation
¶
Index ¶
- Constants
- type Address
- type CreateAddressInput
- type CreateCustomerInput
- type Customer
- type Module
- func (m *Module) AddAddressStepHandler(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) AddCustomerAddress(ctx context.Context, customerID string, input CreateAddressInput) (*Address, error)
- func (m *Module) CreateCustomer(ctx context.Context, input CreateCustomerInput) (*Customer, error)
- func (m *Module) CreateProfileStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) DeleteCustomer(ctx context.Context, id string) (bool, error)
- func (m *Module) DeleteCustomerAddress(ctx context.Context, addressID string) (bool, error)
- func (m *Module) DeleteCustomerStepHandler(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) FieldResolvers() map[string]any
- func (m *Module) GetCustomer(ctx context.Context, id string) (*Customer, error)
- func (m *Module) GetCustomerAddresses(ctx context.Context, customerID string) ([]*Address, error)
- func (m *Module) GetCustomerStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) ID() string
- func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error
- func (m *Module) ListCustomers(ctx context.Context) ([]*Customer, error)
- func (m *Module) ListCustomersStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) ListResources(ctx context.Context) ([]mdk.MCPResource, error)
- func (m *Module) Models() []any
- func (m *Module) Mutations() map[string]any
- func (m *Module) Queries() map[string]any
- func (m *Module) ReadResource(ctx context.Context, uri string) (string, error)
- func (m *Module) Repo() *Repository
- func (m *Module) Routes() []mdk.Route
- func (m *Module) Shutdown(ctx context.Context) error
- func (m *Module) UpdateCustomer(ctx context.Context, id string, input UpdateCustomerInput) (*Customer, error)
- func (m *Module) UpdateCustomerAddress(ctx context.Context, addressID string, input UpdateAddressInput) (*Address, error)
- type Repository
- func (r *Repository) Delete(ctx context.Context, id string) error
- func (r *Repository) DeleteAddress(ctx context.Context, id string) error
- func (r *Repository) GetAddressByID(ctx context.Context, id string) (*Address, error)
- func (r *Repository) GetAddressesByCustomerID(ctx context.Context, customerID string) ([]*Address, error)
- func (r *Repository) GetByID(ctx context.Context, id string) (*Customer, error)
- func (r *Repository) GetByUserID(ctx context.Context, userID string) (*Customer, error)
- func (r *Repository) List(ctx context.Context) ([]*Customer, error)
- func (r *Repository) Save(ctx context.Context, c *Customer) error
- func (r *Repository) SaveAddress(ctx context.Context, addr *Address) error
- type UpdateAddressInput
- type UpdateCustomerInput
Constants ¶
const ( PersonaWhale = "WHALE" PersonaGold = "GOLD" PersonaFrustrated = "FRUSTRATED" PersonaRegular = "REGULAR" PersonaNewbie = "NEWBIE" )
Personas.
const ( TaskCalculatePersona = "customer.calculate_persona" TaskUpdatePersona = "customer.update_persona" TaskUpdateDetails = "customer.update_details" )
Workflow task names.
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 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 (*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
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
DeleteCustomer deletes a customer record.
func (*Module) DeleteCustomerAddress ¶ added in v0.4.0
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 ¶
FieldResolvers exposes custom field-level resolvers.
func (*Module) GetCustomer ¶
GetCustomer retrieves an individual customer by ID.
func (*Module) GetCustomerAddresses ¶ added in v0.4.0
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) Init ¶
Init initializes the customer module, subscribing to identity events to seed customer profiles.
func (*Module) ListCustomers ¶
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 (*Module) ReadResource ¶ added in v0.4.0
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
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) GetByUserID ¶
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.