datastore

package
v0.0.0-...-9d843bf Latest Latest
Warning

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

Go to latest
Published: Aug 13, 2024 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// StatusPending indicates the user has not posted this offer and remains hidden from all the users until active status is used.
	StatusPending = 1
	// StatusActive controls that offer is active.
	StatusActive = 2
	// StatusArchived controls that offer is deleted.
	StatusArchived = 3
	// BusinessFunctionUnspecified indicates no business logic was set with this offer.
	BusinessFunctionUnspecified = 0
	// BusinessFunctionGrantsComicbookSubmissionServices indicates the offer is based on this applications ability to allow making comicbook submissions by the retailer.
	BusinessFunctionGrantsComicbookSubmissionServices = 1
	// PayFrequencyOneTime indicates user only pays once
	PayFrequencyOneTime = 1
	PayFrequencyDay     = 2
	PayFrequencyWeek    = 3
	// PayFrequencyMonthly indicates user pays monthly.
	PayFrequencyMonthly = 4
	// PayFrequencyAnnual indicates user pays annual.
	PayFrequencyAnnual = 5
	// OfferTypeService indicates user gets access to Gym or staff
	OfferTypeService = 1
	// OfferTypeProduct indicates user gets physical product
	OfferTypeProduct = 2
)
View Source
const (
	SortOrderAscending  = 1
	SortOrderDescending = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Offer

type Offer struct {
	Name                 string             `bson:"name" json:"name"`
	Description          string             `bson:"description" json:"description"`
	Price                float64            `bson:"price" json:"price"`
	PriceCurrency        string             `bson:"price_currency" json:"price_currency"`
	PayFrequency         int8               `bson:"pay_frequency" json:"pay_frequency"`
	Status               int8               `bson:"status" json:"status"`
	Type                 int8               `bson:"type" json:"type"`
	CreatedAt            time.Time          `bson:"created_at,omitempty" json:"created_at,omitempty"`
	ModifiedAt           time.Time          `bson:"modified_at,omitempty" json:"modified_at,omitempty"`
	ID                   primitive.ObjectID `bson:"_id" json:"id"`
	PaymentProcessorName string             `bson:"payment_processor_name" json:"payment_processor_name"`
	StripeProductID      string             `bson:"stripe_product_id" json:"stripe_product_id"`
	StripePriceID        string             `bson:"stripe_price_id" json:"stripe_price_id"`
	StripeImageURL       string             `bson:"stripe_image_url" json:"stripe_image_url"`
	IsSubscription       bool               `bson:"is_subscription" json:"is_subscription"`

	// Controls how the user is able to book in our system. Special thanks to http://www.heppnetz.de/ontologies/goodrelations/v1#BusinessFunction.
	BusinessFunction int8 `bson:"business_function" json:"business_function"`
	// ServiceType indicatest the comic book service type associated with this
	// offer.
	ServiceType int8 `bson:"service_type" json:"service_type"`
}

type OfferAsSelectOption

type OfferAsSelectOption struct {
	Value primitive.ObjectID `bson:"_id" json:"value"` // Extract from the database `_id` field and output through API as `value`.
	Label string             `bson:"name" json:"label"`
}

type OfferListFilter

type OfferListFilter struct {
	// Pagination related.
	Cursor    primitive.ObjectID
	PageSize  int64
	SortField string
	SortOrder int8 // 1=ascending | -1=descending

	// Filter related.
	SearchText string
	Status     int8
}

type OfferListResult

type OfferListResult struct {
	Results     []*Offer           `json:"results"`
	NextCursor  primitive.ObjectID `json:"next_cursor"`
	HasNextPage bool               `json:"has_next_page"`
}

type OfferPaginationListFilter

type OfferPaginationListFilter struct {
	// Pagination related.
	Cursor    string
	PageSize  int64
	SortField string
	SortOrder int8 // 1=ascending | -1=descending

	// Filter related.
	SearchText string
	Status     int8
}

type OfferPaginationListResult

type OfferPaginationListResult struct {
	Results     []*Offer `json:"results"`
	NextCursor  string   `json:"next_cursor"`
	HasNextPage bool     `json:"has_next_page"`
}

OfferPaginationListResult represents the paginated list results for the associate records.

type OfferStorer

type OfferStorer interface {
	Create(ctx context.Context, m *Offer) error
	GetByID(ctx context.Context, id primitive.ObjectID) (*Offer, error)
	GetByStripeProductID(ctx context.Context, stripeProductID string) (*Offer, error)
	GetByStripePriceID(ctx context.Context, stripePriceID string) (*Offer, error)
	GetByName(ctx context.Context, name string) (*Offer, error)
	GetByServiceType(ctx context.Context, serviceType int8) (*Offer, error)
	UpdateByID(ctx context.Context, m *Offer) error
	// Upsert will create the `Offer` record if the `ID` field doesn't exist, or update the `Offer` record if the `ID` exists.
	Upsert(ctx context.Context, offer *Offer) error
	ListByFilter(ctx context.Context, m *OfferPaginationListFilter) (*OfferPaginationListResult, error)
	ListAsSelectOptionByFilter(ctx context.Context, f *OfferPaginationListFilter) ([]*OfferAsSelectOption, error)
	DeleteByID(ctx context.Context, id primitive.ObjectID) error
	CheckIfExistsByNameInOrgBranch(ctx context.Context, name string, orgID primitive.ObjectID, branchID primitive.ObjectID) (bool, error)
	CheckIfExistsByID(ctx context.Context, id primitive.ObjectID) (bool, error)
}

OfferStorer Interface for store.

func NewDatastore

func NewDatastore(appCfg *c.Conf, loggerp *slog.Logger, client *mongo.Client) OfferStorer

type OfferStorerImpl

type OfferStorerImpl struct {
	Logger     *slog.Logger
	DbClient   *mongo.Client
	Collection *mongo.Collection
}

func (OfferStorerImpl) CheckIfExistsByID

func (impl OfferStorerImpl) CheckIfExistsByID(ctx context.Context, id primitive.ObjectID) (bool, error)

func (OfferStorerImpl) CheckIfExistsByNameInOrgBranch

func (impl OfferStorerImpl) CheckIfExistsByNameInOrgBranch(ctx context.Context, name string, orgID primitive.ObjectID, branchID primitive.ObjectID) (bool, error)

func (OfferStorerImpl) Create

func (impl OfferStorerImpl) Create(ctx context.Context, u *Offer) error

func (OfferStorerImpl) DeleteByID

func (impl OfferStorerImpl) DeleteByID(ctx context.Context, id primitive.ObjectID) error

func (OfferStorerImpl) GetByID

func (impl OfferStorerImpl) GetByID(ctx context.Context, id primitive.ObjectID) (*Offer, error)

func (OfferStorerImpl) GetByName

func (impl OfferStorerImpl) GetByName(ctx context.Context, name string) (*Offer, error)

func (OfferStorerImpl) GetByServiceType

func (impl OfferStorerImpl) GetByServiceType(ctx context.Context, serviceType int8) (*Offer, error)

func (OfferStorerImpl) GetByStripePriceID

func (impl OfferStorerImpl) GetByStripePriceID(ctx context.Context, stripePriceID string) (*Offer, error)

func (OfferStorerImpl) GetByStripeProductID

func (impl OfferStorerImpl) GetByStripeProductID(ctx context.Context, stripeProductID string) (*Offer, error)

func (OfferStorerImpl) ListAsSelectOptionByFilter

func (impl OfferStorerImpl) ListAsSelectOptionByFilter(ctx context.Context, f *OfferPaginationListFilter) ([]*OfferAsSelectOption, error)

func (OfferStorerImpl) ListByFilter

func (OfferStorerImpl) UpdateByID

func (impl OfferStorerImpl) UpdateByID(ctx context.Context, m *Offer) error

func (OfferStorerImpl) Upsert

func (impl OfferStorerImpl) Upsert(ctx context.Context, offer *Offer) error

Jump to

Keyboard shortcuts

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