marketing

package
v0.14.6 Latest Latest
Warning

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

Go to latest
Published: Jul 2, 2019 License: AGPL-3.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// FreeCredit is a type of offers used for Free Credit Program
	FreeCredit = OfferType(iota)
	// Referral is a type of offers used for Referral Program
	Referral
)
View Source
const (
	// Done is a default offer status when an offer is not being used currently
	Done = OfferStatus(iota)
	// Default is a offer status when an offer is used as a default offer
	Default
	// Active is a offer status when an offer is currently being used
	Active
)

Variables

View Source
var (
	// Error the default offers errs class
	Error = errs.Class("marketing error")
)
View Source
var OffersErr = errs.Class("offers error")

OffersErr creates offer error class

Functions

This section is empty.

Types

type DB

type DB interface {
	Offers() Offers
}

DB contains access to all marketing related databases

type NewOffer

type NewOffer struct {
	Name        string
	Description string

	AwardCreditInCents   int
	InviteeCreditInCents int

	RedeemableCap int

	AwardCreditDurationDays   int
	InviteeCreditDurationDays int

	ExpiresAt time.Time

	Status OfferStatus
	Type   OfferType
}

NewOffer holds information that's needed for creating a new offer

type Offer

type Offer struct {
	ID          int
	Name        string
	Description string

	AwardCreditInCents   int
	InviteeCreditInCents int

	AwardCreditDurationDays   int
	InviteeCreditDurationDays int

	RedeemableCap int
	NumRedeemed   int

	ExpiresAt time.Time
	CreatedAt time.Time

	Status OfferStatus
	Type   OfferType
}

Offer contains info needed for giving users free credits through different offer programs

type OfferStatus

type OfferStatus int

OfferStatus indicates the status of an offer

type OfferType

type OfferType int

OfferType indicates the type of an offer

type Offers

type Offers interface {
	ListAll(ctx context.Context) ([]Offer, error)
	GetCurrentByType(ctx context.Context, offerType OfferType) (*Offer, error)
	Create(ctx context.Context, offer *NewOffer) (*Offer, error)
	Redeem(ctx context.Context, offerID int) error
	Finish(ctx context.Context, offerID int) error
}

Offers holds information about offer

type Service

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

Service allows access to offers info in the db

func NewService

func NewService(log *zap.Logger, db DB) (*Service, error)

NewService creates a new offers db

func (*Service) FinishOffer added in v0.14.0

func (s *Service) FinishOffer(ctx context.Context, oID int) (err error)

FinishOffer updates an active offer's status to be Done and its expiration time to be now

func (*Service) GetCurrentOfferByType

func (s *Service) GetCurrentOfferByType(ctx context.Context, offerType OfferType) (offer *Offer, err error)

GetCurrentOfferByType returns current active offer

func (*Service) InsertNewOffer

func (s *Service) InsertNewOffer(ctx context.Context, offer *NewOffer) (o *Offer, err error)

InsertNewOffer inserts a new offer into the db

func (*Service) ListAllOffers

func (s *Service) ListAllOffers(ctx context.Context) (offers []Offer, err error)

ListAllOffers returns all available offers in the db

func (*Service) RedeemOffer added in v0.14.0

func (s *Service) RedeemOffer(ctx context.Context, uo *UpdateOffer) (err error)

RedeemOffer adds 1 to the number of redeemed for an offer

type UpdateOffer

type UpdateOffer struct {
	ID        int
	Status    OfferStatus
	ExpiresAt time.Time
}

UpdateOffer holds fields needed for update an offer

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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