events

package
v0.0.0-...-2ad8e27 Latest Latest
Warning

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

Go to latest
Published: Jan 1, 2025 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	ArticleId string `json:"articleId" binding:"required,min=1,max=100"`
	Quantity  int    `json:"quantity" binding:"required,min=1"`
}

type Event

type Event struct {
	ID         primitive.ObjectID `bson:"_id,omitempty"`
	OrderId    string             `bson:"orderId" validate:"required,min=1,max=100"`
	Type       EventType          `bson:"type" validate:"required"`
	PlaceEvent *PlaceEvent        `bson:"placeEvent"`
	Validation *ValidationEvent   `bson:"validation"`
	Payment    *PaymentEvent      `bson:"payment"`
	Created    time.Time          `bson:"created"`
	Updated    time.Time          `bson:"updated"`
}

Estuctura basica de del evento

func (*Event) ValidateSchema

func (e *Event) ValidateSchema() error

ValidateSchema valida la estructura para ser insertada en la db

type EventService

type EventService interface {
	SavePlaceOrder(data *PlacedOrderData) (*Event, error)
	SavePayment(data *PaymentEvent) (*Event, error)
	SaveArticleExist(data *ValidationEvent) (*Event, error)
	FindByOrderId(orderId string) ([]*Event, error)
}

func NewEventService

func NewEventService(log log.LogRusEntry, repository EventsRepository) EventService

type EventType

type EventType string
const (
	Place      EventType = "place_order"
	Validation EventType = "aticle_validation"
	Payment    EventType = "payment"
)

type EventsRepository

type EventsRepository interface {
	Insert(event *Event) (*Event, error)
	FindPlaceByCartId(cartId string) (*Event, error)
	FindByOrderId(orderId string) ([]*Event, error)
}

func NewEventsRepository

func NewEventsRepository(log log.LogRusEntry, collection db.Collection) EventsRepository

type PaymentEvent

type PaymentEvent struct {
	OrderId string        `bson:"orderId" binding:"required"`
	Method  PaymentMethod `bson:"metod" binding:"required"`
	Amount  float32       `bson:"amount" binding:"required"`
}

type PaymentMethod

type PaymentMethod string
const (
	Cash   PaymentMethod = "CASH"
	Credit PaymentMethod = "CREDIT"
	Debit  PaymentMethod = "DEBIT"
)

type PlaceEvent

type PlaceEvent struct {
	CartId   string    `bson:"cartId"`
	UserId   string    `bson:"userId" `
	Articles []Article `bson:"articles" `
}

type PlacePrderArticleData

type PlacePrderArticleData struct {
	Id       string `json:"id" binding:"required,min=1,max=100"`
	Quantity int    `json:"quantity" binding:"required,min=1"`
}

type PlacedOrderData

type PlacedOrderData struct {
	CartId   string                  `json:"cartId" binding:"required,min=1,max=100"`
	UserId   string                  `json:"userId" binding:"required,min=1,max=100"`
	Articles []PlacePrderArticleData `json:"articles" binding:"required,gt=0"`
}

type ValidationEvent

type ValidationEvent struct {
	ArticleId   string  `bson:"articleId" json:"articleId"`
	ReferenceId string  `bson:"referenceId" json:"referenceId"`
	IsValid     bool    `bson:"isValid" json:"valid"`
	Stock       int     `bson:"stock" json:"stock"`
	Price       float32 `bson:"price" json:"price"`
}

Jump to

Keyboard shortcuts

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