Documentation
¶
Index ¶
- type Coupon
- type IdempotencyKey
- type LoyaltyPoints
- type Module
- func (m *Module) AddLoyaltyPoints(ctx context.Context, input any) (any, error)
- func (m *Module) AddLoyaltyPointsStep(sCtx mdk.StepContext) mdk.StepResult
- func (m *Module) ApplyCouponToCart(ctx context.Context, cartID string, couponCode string) (*cart.Cart, error)
- func (m *Module) FieldResolvers() map[string]any
- func (m *Module) GetCoupon(ctx context.Context, code string) (*Coupon, error)
- func (m *Module) GetLoyaltyBalance(ctx context.Context, customerID string) (int, error)
- func (m *Module) ID() string
- func (m *Module) Init(ctx context.Context, rt mdk.Runtime) error
- func (m *Module) Models() []any
- func (m *Module) Mutations() map[string]any
- func (m *Module) Queries() map[string]any
- func (m *Module) Repo() *Repository
- func (m *Module) Routes() []mdk.Route
- func (m *Module) Shutdown(ctx context.Context) error
- func (m *Module) ValidateCoupon(ctx context.Context, input any) (any, error)
- func (m *Module) ValidateCouponStep(sCtx mdk.StepContext) mdk.StepResult
- type Repository
- func (r *Repository) GetCouponByCode(ctx context.Context, code string) (*Coupon, error)
- func (r *Repository) GetLoyaltyPointsByCustomerID(ctx context.Context, customerID string) (*LoyaltyPoints, error)
- func (r *Repository) SaveCoupon(ctx context.Context, c *Coupon) error
- func (r *Repository) SaveLoyaltyPoints(ctx context.Context, lp *LoyaltyPoints) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Coupon ¶
type Coupon struct {
ID string `gorm:"primaryKey" json:"id"`
Code string `gorm:"uniqueIndex;not null" json:"code"`
DiscountPercentage float64 `gorm:"not null" json:"discount_percentage"`
Active bool `gorm:"default:true" json:"active"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
Coupon represents a discount code.
type IdempotencyKey ¶
type IdempotencyKey struct {
ID string `gorm:"primaryKey"`
Scope string `gorm:"index:idx_scope_key,unique"`
Key string `gorm:"index:idx_scope_key,unique"`
CreatedAt time.Time
}
IdempotencyKey prevents duplicate processing of the same operation.
type LoyaltyPoints ¶
type LoyaltyPoints struct {
ID string `gorm:"primaryKey" json:"id"`
CustomerID string `gorm:"uniqueIndex;not null" json:"customer_id"`
Balance int `gorm:"default:0" json:"balance"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `gorm:"index" json:"-"`
}
LoyaltyPoints represents a customer's rewards balance.
type Module ¶
type Module struct {
// contains filtered or unexported fields
}
Module implements the mdk.Module interface for Marketing.
func (*Module) AddLoyaltyPoints ¶
AddLoyaltyPoints adds points based on the order total.
func (*Module) AddLoyaltyPointsStep ¶
func (m *Module) AddLoyaltyPointsStep(sCtx mdk.StepContext) mdk.StepResult
AddLoyaltyPointsStep wraps AddLoyaltyPoints to mdk.StepHandler.
func (*Module) ApplyCouponToCart ¶
func (*Module) FieldResolvers ¶
func (*Module) GetLoyaltyBalance ¶
func (*Module) Repo ¶
func (m *Module) Repo() *Repository
func (*Module) ValidateCoupon ¶
ValidateCoupon checks if a coupon is valid and returns it.
func (*Module) ValidateCouponStep ¶
func (m *Module) ValidateCouponStep(sCtx mdk.StepContext) mdk.StepResult
ValidateCouponStep wraps ValidateCoupon to mdk.StepHandler.
type Repository ¶
type Repository struct {
// contains filtered or unexported fields
}
func NewRepository ¶
func NewRepository(database *gorm.DB) *Repository
func (*Repository) GetCouponByCode ¶
func (*Repository) GetLoyaltyPointsByCustomerID ¶
func (r *Repository) GetLoyaltyPointsByCustomerID(ctx context.Context, customerID string) (*LoyaltyPoints, error)
func (*Repository) SaveCoupon ¶
func (r *Repository) SaveCoupon(ctx context.Context, c *Coupon) error
func (*Repository) SaveLoyaltyPoints ¶
func (r *Repository) SaveLoyaltyPoints(ctx context.Context, lp *LoyaltyPoints) error
Click to show internal directories.
Click to hide internal directories.