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                 = 1
	StatusOK                      = 2
	StatusError                   = 3
	StatusArchived                = 4
	PrimaryTypeStripeWebhookEvent = 1
)
View Source
const (
	SortOrderAscending  = 1
	SortOrderDescending = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type EventLog

type EventLog struct {
	PrimaryType   int8   `bson:"primary_type" json:"primary_type"`
	SecondaryType string `bson:"secondary_type" json:"secondary_type"`
	// Content field will store any datatype because we want the ability to
	// store complex data-structures from remote services (ex: Stripe, Inc.) and
	// be able to store simply stuff like plain ol' text.
	Content    any       `bson:"content" json:"content"`
	Error      error     `bson:"error" json:"error"`
	CreatedAt  time.Time `bson:"created_at,omitempty" json:"created_at,omitempty"`
	ModifiedAt time.Time `bson:"modified_at,omitempty" json:"modified_at,omitempty"`
	Status     int8      `bson:"status" json:"status"`
	// ExternalID represent the unique identifier provided by a remote system.
	ExternalID string             `bson:"external_id" json:"external_id"`
	StoreID    primitive.ObjectID `bson:"store_id" json:"store_id"`
	StoreName  string             `bson:"store_name" json:"store_name"`
	ID         primitive.ObjectID `bson:"_id" json:"id"`
}

type EventLogAsSelectOption

type EventLogAsSelectOption 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 EventLogListFilter

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

	// Filter related.
	SearchText    string
	StoreID       primitive.ObjectID
	PrimaryType   int8   `bson:"primary_type" json:"primary_type"`
	SecondaryType string `bson:"secondary_type" json:"secondary_type"`
	Status        int8   `bson:"status" json:"status"`
}

type EventLogListResult

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

type EventLogPaginationListFilter

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

	// Filter related.
	SearchText    string
	StoreID       primitive.ObjectID
	PrimaryType   int8   `bson:"primary_type" json:"primary_type"`
	SecondaryType string `bson:"secondary_type" json:"secondary_type"`
	Status        int8   `bson:"status" json:"status"`
}

type EventLogPaginationListResult

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

EventLogPaginationListResult represents the paginated list results for the associate records.

type EventLogStorer

type EventLogStorer interface {
	Create(ctx context.Context, m *EventLog) error
	GetByID(ctx context.Context, id primitive.ObjectID) (*EventLog, error)
	GetByName(ctx context.Context, name string) (*EventLog, error)
	GetByPaymentProcessorEventLogID(ctx context.Context, paymentProcessorEventLogID string) (*EventLog, error)
	UpdateByID(ctx context.Context, m *EventLog) error
	ListByFilter(ctx context.Context, m *EventLogPaginationListFilter) (*EventLogPaginationListResult, error)
	ListAsSelectOptionByFilter(ctx context.Context, f *EventLogListFilter) ([]*EventLogAsSelectOption, error)
	DeleteByID(ctx context.Context, id primitive.ObjectID) error
	CheckIfExistsByNameInOrgBranch(ctx context.Context, name string, orgID primitive.ObjectID, branchID primitive.ObjectID) (bool, error)
}

EventLogStorer Interface for store.

func NewDatastore

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

type EventLogStorerImpl

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

func (EventLogStorerImpl) CheckIfExistsByNameInOrgBranch

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

func (EventLogStorerImpl) Create

func (impl EventLogStorerImpl) Create(ctx context.Context, u *EventLog) error

func (EventLogStorerImpl) DeleteByID

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

func (EventLogStorerImpl) GetByID

func (EventLogStorerImpl) GetByName

func (impl EventLogStorerImpl) GetByName(ctx context.Context, name string) (*EventLog, error)

func (EventLogStorerImpl) GetByPaymentProcessorEventLogID

func (impl EventLogStorerImpl) GetByPaymentProcessorEventLogID(ctx context.Context, paymentProcessorEventLogID string) (*EventLog, error)

func (EventLogStorerImpl) ListAsSelectOptionByFilter

func (impl EventLogStorerImpl) ListAsSelectOptionByFilter(ctx context.Context, f *EventLogListFilter) ([]*EventLogAsSelectOption, error)

func (EventLogStorerImpl) ListByFilter

func (EventLogStorerImpl) UpdateByID

func (impl EventLogStorerImpl) UpdateByID(ctx context.Context, m *EventLog) error

Jump to

Keyboard shortcuts

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