services

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 30, 2024 License: GPL-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the database and external services. They are used to implement the HTTP handlers in the handlers package.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the database and external services. They are used to implement the HTTP handlers in the handlers package.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the database and external services. They are used to implement the HTTP handlers in the handlers package.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the database and external services. They are used to implement the HTTP handlers in the handlers package.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the database and external services. They are used to implement the HTTP handlers in the handlers package.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the database and external services. They are used to implement the HTTP handlers in the handlers package.

Package services contains the business logic of the core module of nutrix.

It implements the required interfaces for the core module of nutrix.

The services in this package are used to interact with the database using the models package, and to interact with the outside world using the dto package.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the persistence layer and perform operations on the data models of the core module.

Package services contains the business logic of the core module of nutrix.

The services in this package are used to interact with the models package, which contains the data models of the core module of nutrix. The services are used to create a RESTful API for the core module of nutrix. The API endpoints are documented using the Swagger specification.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckExpirationDates

func CheckExpirationDates(log logger.ILogger, conf config.Config, notification_svc INotificationService)

CheckExpirationDates is a background job that checks all materials if they are expired and informs the admin about it. The function is designed to be called periodically by the job scheduler.

Types

type CategoryService

type CategoryService struct {
	Logger logger.ILogger
	Config config.Config
}

func (*CategoryService) DeleteCategory

func (cs *CategoryService) DeleteCategory(category_id string) (err error)

DeleteCategory deletes a category from the database.

func (*CategoryService) GetCategories

func (cs *CategoryService) GetCategories(first int, rows int) (categories []models.Category, err error)

GetCategories returns a list of categories from the database.

func (*CategoryService) InsertCategory

func (cs *CategoryService) InsertCategory(category models.Category) (err error)

InsertCategory inserts a new category into the database.

func (*CategoryService) UpdateCategory

func (cs *CategoryService) UpdateCategory(category models.Category) (err error)

UpdateCategory updates a category in the database.

type GetOrdersParameters

type GetOrdersParameters struct {
	// OrderDisplayIdContains is the string to search for in the display_id field.
	OrderDisplayIdContains string
	// First is used in pagination to set the index of the first record to be returned.
	First int
	// Rows is to set the desired row count limit.
	Rows int
}

GetOrdersParameters is the struct to hold the parameters for the GetOrders method.

type INotificationService

type INotificationService interface {
	// HandleHttpRequest handles a HTTP request to the WebSocket endpoint.
	HandleHttpRequest(w http.ResponseWriter, r *http.Request) error
	// SendToTopic sends a message to all subscribers of a topic.
	SendToTopic(topic_name string, message string) error
}

INotificationService is an interface for sending notifications to connected clients. It is used by the HTTP handlers in the handlers package to send notifications.

func SpawnNotificationSingletonSvc

func SpawnNotificationSingletonSvc(name string, logger logger.ILogger, config config.Config) (INotificationService, error)

SpawnNotificationSingletonSvc returns an INotificationService object that can be used to send notifications. The function is designed to be used as a Singleton pattern.

type Log

type Log struct {
	// Logger is used to log messages with different levels of severity.
	Logger logger.ILogger
	// Config holds the configuration settings for the logging service.
	Config config.Config
}

Log represents the logging service in the core module. It holds the logger and configuration required for logging operations.

func (*Log) GetComponentLogs

func (l *Log) GetComponentLogs(component_id string) (logs []models.ComponentConsumeLogs, err error)

GetComponentLogs gets all logs for a given component_id.

func (*Log) GetSalesLogs

func (l *Log) GetSalesLogs() []models.SalesLogs

GetSalesLogs gets all logs for a given component_id.

type MaterialService

type MaterialService struct {
	Logger   logger.ILogger
	Config   config.Config
	Settings models.Settings
}

MaterialService provides methods to manage and manipulate materials. It contains methods for calculating costs, checking availability, and updating material entries in the database. It relies on a logger for logging operations and a configuration for database connectivity.

func (*MaterialService) AddComponent

func (cs *MaterialService) AddComponent(material models.Material) error

AddComponent adds a new material component to the database. It first inserts the material into the "materials" collection, then logs the addition of each entry into the "logs" collection. If there is any error during the database operations, it returns the error.

func (*MaterialService) CalculateMaterialCost

func (cs *MaterialService) CalculateMaterialCost(entry_id, material_id string, quantity float64) (cost float64, err error)

CalculateMaterialCost calculates the cost of a material entry based on its ID, material ID, and quantity. It connects to the MongoDB database, retrieves the specific material entry, and calculates the cost using the purchase price and purchase quantity.

func (*MaterialService) ConsumeItemComponentsForOrder

func (cs *MaterialService) ConsumeItemComponentsForOrder(item models.OrderItem, order models.Order, item_order_index int) (notifications []models.WebsocketTopicServerMessage, err error)

ConsumeItemComponentsForOrder consumes components for an order item, and returns the notifications to be sent via websocket. It returns an error if something goes wrong.

func (*MaterialService) DeleteEntry

func (cs *MaterialService) DeleteEntry(entryid string, componentid string) error

DeleteEntry deletes an entry from a material in the database.

The function takes a entry ID and a component ID as parameters. It then finds the material with the given component ID and removes the entry with the given entry ID from the material's entries array. If the material or the entry is not found, the function will return an error.

func (*MaterialService) EditMaterial

func (cs *MaterialService) EditMaterial(materialEditRequest dto.MaterialEditRequest) error

EditMaterial updates a material in the database.

The function takes a MaterialEditRequest as a parameter and updates the corresponding material in the database with the provided information.

The function is used to edit an existing material in the database.

func (*MaterialService) GetComponentAvailability

func (cs *MaterialService) GetComponentAvailability(componentid string) (amount float32, err error)

GetComponentAvailability retrieves the total quantity of a specific component.

The function takes a component ID as a parameter and returns the total quantity of the specified component in the database. If the component is not found in the database, the function returns an error.

The function is used to check the availability of a specific component before consuming it. The component quantity is calculated by summing up the quantity of all entries of the component.

func (*MaterialService) GetMaterialEntryAvailability

func (cs *MaterialService) GetMaterialEntryAvailability(material_id string, entry_id string) (amount float32, err error)

GetMaterialEntryAvailability retrieves the quantity of a specific material entry from the database.

The function takes a material ID and an entry ID as parameters and returns the quantity of the specified entry in the material. If the entry is not found in the material, the function returns an error.

func (*MaterialService) GetMaterials

func (cs *MaterialService) GetMaterials() (materials []models.Material, err error)

GetMaterials retrieves all materials from the database.

The function returns a slice of Material structs.

func (*MaterialService) PushMaterialEntry

func (cs *MaterialService) PushMaterialEntry(componentId string, entries []models.MaterialEntry) error

PushMaterialEntry adds a new entry to a material in the database.

The function takes a component ID and a slice of MaterialEntry structs as parameters. It then finds the material with the given ID and appends the new entries to the material's entries array. If the material is not found, the function will return an error.

type MelodyWebsocket

type MelodyWebsocket struct {
	// Logger is a logger object used to log messages.
	Logger logger.ILogger
	// Config is a configuration object used to configure the WebSocket endpoint.
	Config config.Config

	// Topics is a slice of Topic objects used to store the topics and their subscribers.
	Topics []models.Topic
	// contains filtered or unexported fields
}

MelodyWebsocket is a struct that implements the INotificationService interface. It uses the Melody library to handle WebSocket connections and send messages.

func (*MelodyWebsocket) AddSessionToTopic

func (ws *MelodyWebsocket) AddSessionToTopic(topic_name string, session_id string)

AddSessionToTopic adds a session to a topic.

func (*MelodyWebsocket) GetTopic

func (ws *MelodyWebsocket) GetTopic(topic_name string) (topic models.Topic, index int, err error)

GetTopic returns a topic and its index in the Topics slice.

func (*MelodyWebsocket) HandleConnect

func (ws *MelodyWebsocket) HandleConnect()

HandleConnect sets up the session context when a new WebSocket connection is established.

func (*MelodyWebsocket) HandleHttpRequest

func (ws *MelodyWebsocket) HandleHttpRequest(w http.ResponseWriter, r *http.Request) error

HandleHttpRequest handles a HTTP request to the WebSocket endpoint.

func (*MelodyWebsocket) HandleMessages

func (ws *MelodyWebsocket) HandleMessages()

HandleMessages handles messages received from clients.

func (*MelodyWebsocket) SendToSession

func (ws *MelodyWebsocket) SendToSession(msg string, session_id string)

SendToSession sends a message to a specific session.

func (*MelodyWebsocket) SendToTopic

func (ws *MelodyWebsocket) SendToTopic(topic_name string, message string) error

SendToTopic sends a message to all subscribers of a topic.

type OrderService

type OrderService struct {
	Logger   logger.ILogger
	Config   config.Config
	Settings models.Settings
}

OrderService is the service to interact with the orders collection in the database.

func (*OrderService) CalculateCost

func (os *OrderService) CalculateCost(items []models.OrderItem) (cost []models.ItemCost, err error)

CalculateCost calculates the cost of each item in the provided list of order items.

func (*OrderService) CancelOrder

func (os *OrderService) CancelOrder(order_id string) (err error)

CancelOrder sets the state of the order with the given order_id to "cancelled".

func (*OrderService) FinishOrder

func (os *OrderService) FinishOrder(finish_order_request dto.FinishOrderRequest) (err error)

FinishOrder sets the state of the order with the given order_id to "finished".

func (*OrderService) GetOrder

func (os *OrderService) GetOrder(order_id string) (models.Order, error)

GetOrder retrieves an order from the database with the given order_id.

func (*OrderService) GetOrderDisplayId

func (os *OrderService) GetOrderDisplayId() (order_display_id string, err error)

GetOrderDisplayId returns a new order display id and increments the current value in the database.

func (*OrderService) GetOrders

func (os *OrderService) GetOrders(params GetOrdersParameters) (orders []models.Order, totalRecords int64, err error)

GetOrders retrieves all orders from the database by default, If the OrderDisplayIdContains parameter is not empty, the function will check if display_id is not "" then it will filter for all order that contains the specified string

func (*OrderService) GetStashedOrders

func (os *OrderService) GetStashedOrders() (stashed_orders []models.Order, err error)

GetStashedOrders retrieves all stashed orders from the "stashed_orders" collection in the database.

func (*OrderService) GetUnpaidOrders

func (os *OrderService) GetUnpaidOrders() (orders []models.Order, err error)

GetUnpaidOrders returns all orders that are not paid and their state is not cancelled.

func (*OrderService) PayUnpaidOrder

func (os *OrderService) PayUnpaidOrder(order_id string) (err error)

PayUnpaidOrder sets the is_paid field of the order with the given order_id to true.

func (*OrderService) RemoveStashedOrder

func (os *OrderService) RemoveStashedOrder(stash_remove_request dto.OrderRemoveStashRequest) error

RemoveStashedOrder removes an order from the "stashed_orders" collection based on the provided order display ID.

func (*OrderService) StartOrder

func (os *OrderService) StartOrder(order_start_request dto.OrderStartRequest) error

StartOrder sets the state of the order with the given order_id to "in_progress", and updates the "started_at" field with the current time. It also consumes the item components from the inventory and sends a notification to the websockets.

func (*OrderService) StashOrder

func (os *OrderService) StashOrder(order_stash_request dto.OrderStashRequest) (models.Order, error)

StashOrder adds an order to the "stashed_orders" collection in the database.

func (*OrderService) SubmitOrder

func (os *OrderService) SubmitOrder(order models.Order) (err error)

SubmitOrder adds an order to the database and creates a display id.

type RecipeService

type RecipeService struct {
	Logger logger.ILogger
	Config config.Config
}

RecipeService provides methods to manage recipes, including logging and configuration.

func (*RecipeService) CheckRecipesAvailability

func (rs *RecipeService) CheckRecipesAvailability(recipe_ids []string) (availabilities []dto.RecipeAvailability, err error)

CheckRecipesAvailability checks the availability of a list of recipes. It returns a slice of RecipeAvailability with the available and ready number for each recipe.

func (*RecipeService) ConsumeFromReady

func (rs *RecipeService) ConsumeFromReady(product_id string, quantity float64) error

ConsumeFromReady consumes a quantity from the ready stock of a product.

func (*RecipeService) DeleteProduct

func (rs *RecipeService) DeleteProduct(product_id string) (err error)

DeleteProduct deletes a product from the database.

It takes a product_id and deletes it from the database.

func (*RecipeService) FillRecipeDesign

func (rs *RecipeService) FillRecipeDesign(item models.OrderItem) (models.OrderItem, error)

FillRecipeDesign fills the recipe design for an order item with its product and sub products.

func (*RecipeService) GetProducts

func (rs *RecipeService) GetProducts(first_index int, rows int) (products []models.Product, totalRecords int64, err error)

GetProducts retrieves a list of products from the database.

It takes a first_index and rows and returns a slice of products. It also returns the total number of records in the database. It returns an error if the products could not be retrieved.

func (*RecipeService) GetReadyNumber

func (rs *RecipeService) GetReadyNumber(recipe_id string) (ready float64, err error)

GetReadyNumber returns the ready number of a given recipe

func (*RecipeService) GetRecipeMaterials

func (rs *RecipeService) GetRecipeMaterials(recipe_id string) (materials []models.Material, err error)

GetRecipeMaterials returns all materials for a given recipe.

func (*RecipeService) GetRecipeTree

func (rs *RecipeService) GetRecipeTree(recipe_id string) (tree models.Product, err error)

GetRecipeTree returns the recipe tree for a given recipe_id.

func (*RecipeService) InsertNew

func (rs *RecipeService) InsertNew(product models.Product) (err error)

InsertNew inserts a new product into the database.

It takes a product and inserts it into the database. It returns an error if the product could not be inserted.

func (*RecipeService) UpdateProduct

func (rs *RecipeService) UpdateProduct(product models.Product) (err error)

UpdateProduct updates a product in the database.

It takes a product and updates it in the database.

If the product is not found, it will return an error.

type SalesService

type SalesService struct {
	// Logger is the logger for the sales service.
	Logger logger.ILogger
	// Config is the configuration for the sales service.
	Config config.Config
}

SalesService contains the configuration and logger for the sales service.

func (*SalesService) AddOrderToSalesDay

func (ss *SalesService) AddOrderToSalesDay(order models.Order, items_cost []models.ItemCost) error

AddOrderToSalesDay adds an order to the "sales" collection in the database. It takes two parameters, order and items_cost, which are the order and its associated item costs. It returns an error if the query fails.

func (*SalesService) GetSalesPerday

func (ss *SalesService) GetSalesPerday(first int, rows int) (salesPerDay []models.SalesPerDay, totalRecords int, err error)

format 2006-01-02 GetSalesPerday returns a slice of models.SalesPerDay and the total count of records in the database. It takes two parameters, first and rows, which determine the offset and limit of the query. It returns an error if the query fails.

type Seeder

type Seeder struct {
	// Logger provides logging capabilities for the seeding process.
	Logger logger.ILogger
	// Config holds the configuration settings needed for database connections.
	Config config.Config
	// Settings contains additional configuration settings used during seeding.
	Settings models.Settings
	// Prompter is used to interact with the user through prompts.
	Prompter userio.Prompter
	// IsNewOnly indicates whether only new data should be seeded, leaving existing data untouched.
	IsNewOnly bool
}

func (*Seeder) SeedCategories

func (s *Seeder) SeedCategories() error

SeedCategories seeds categories into the database, optionally creating new categories if they don't exist.

func (*Seeder) SeedMaterials

func (s *Seeder) SeedMaterials(seedEntries bool) error

SeedMaterials seeds materials into the database, optionally creating new materials if they don't exist.

func (*Seeder) SeedProducts

func (s *Seeder) SeedProducts() error

SeedProducts seeds products into the database, optionally creating new products if they don't exist.

type SettingsService

type SettingsService struct {
	Config config.Config
}

func (*SettingsService) GetSettings

func (os *SettingsService) GetSettings() (ordersettings models.Settings, err error)

GetSettings returns the settings from the database

func (*SettingsService) UpdateSettings

func (ss *SettingsService) UpdateSettings(settings models.Settings) (err error)

UpdateSettings updates the settings in the database

Jump to

Keyboard shortcuts

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