order_request

package
v1.0.65 Latest Latest
Warning

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

Go to latest
Published: Aug 17, 2025 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *gorm.DB) error

Migrate migrates the order request database tables.

The order request database tables are: - order_requests - order_request_items

Types

type OrderRequestService

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

func NewOrderRequestService

func NewOrderRequestService(db *gorm.DB, ctx *context.ERPContext, merchantService *merchant.MerchantService, productService *product.ProductService, auditTrailSrv *audit_trail.AuditTrailService) *OrderRequestService

NewOrderRequestService creates a new OrderRequestService instance.

This service is responsible for managing order request-related operations within the application. It requires a database connection, ERP context, merchant service, product service, and audit trail service.

func (*OrderRequestService) AddOrderRequestItem

func (s *OrderRequestService) AddOrderRequestItem(orderRequestID string, item models.OrderRequestItemModel) error

AddOrderRequestItem adds a new item to an existing order request.

This method first checks that the order request exists and is in the "PENDING" or "OFFERING" state. It then appends the provided item to the existing items associated with the order request. If the append operation fails, the method returns an error.

Params: - orderRequestID (string): The ID of the order request to add the item to. - item (models.OrderRequestItemModel): The item to add to the order request.

Returns: - (error): An error object if the append operation fails, or nil if successful.

func (*OrderRequestService) CancelOrderRequest

func (s *OrderRequestService) CancelOrderRequest(userID, orderRequestID, reason string) error

CancelOrderRequest cancels an order request by updating its status to "CANCELLED" and setting a cancellation reason. The method takes a user ID, order request ID, and cancellation reason as parameters.

The method first checks that the order request exists and is in the "OFFERING" or "PENDING" state. If the order request is not in one of these states, the method returns an error. It then updates the status of the order request to "CANCELLED" and sets the cancellation reason. If the update fails, the method returns an error.

Params: - userID (string): The ID of the user who is cancelling the order request. - orderRequestID (string): The ID of the order request to cancel. - reason (string): The reason for cancelling the order request.

Returns: - (error): An error object if the update fails, or nil if successful.

func (*OrderRequestService) CreateOrderRequest

func (s *OrderRequestService) CreateOrderRequest(userID string, userLat, userLng float64, expiresAt time.Time) (*models.OrderRequestModel, error)

func (*OrderRequestService) DeleteOrderRequest

func (s *OrderRequestService) DeleteOrderRequest(userID, orderRequestID string) error

DeleteOrderRequest permanently deletes an order request by its ID.

This method takes a user ID and order request ID as parameters and permanently deletes the order request from the database. If the deletion fails, the method returns an error.

Params: - userID (string): The ID of the user who is deleting the order request. - orderRequestID (string): The ID of the order request to delete.

Returns: - (error): An error object if the deletion fails, or nil if successful.

func (*OrderRequestService) FinishOrderRequest

func (s *OrderRequestService) FinishOrderRequest(orderRequestID string) error

FinishOrderRequest marks an order request as "Completed" and logs the action using the audit trail service.

This method first checks that the order request exists and is in the "Accepted" state. If the order request is not in the "Accepted" state, the method returns an error. It then updates the status of the order request to "Completed" and logs the action using the audit trail service. If the update or logging fails, the method returns an error.

Params: - orderRequestID (string): The ID of the order request to finish.

Returns: - (error): An error object if the operation fails, or nil if successful.

func (*OrderRequestService) GetAvailableMerchant

func (s *OrderRequestService) GetAvailableMerchant(orderRequestID string, maxDistance float64) ([]models.MerchantModel, error)

GetAvailableMerchant retrieves a list of nearby merchants for an order request.

This method takes an order request ID and a maximum distance (in kilometers) as parameters, and returns a slice of MerchantModel representing the nearby merchants. If the order request does not exist, or if the retrieval fails, the method returns an error.

The maximum distance parameter is in kilometers.

Params: - orderRequestID (string): The ID of the order request to find nearby merchants for. - maxDistance (float64): The maximum distance in kilometers to search for merchants.

Returns: - ([]models.MerchantModel): A slice of merchant models representing the nearby merchants. - (error): An error object if the retrieval fails, or nil if successful.

func (*OrderRequestService) GetOrderByStatus

func (s *OrderRequestService) GetOrderByStatus(userID string, status []string) (*models.OrderRequestModel, error)

GetOrderByStatus retrieves an order request with the specified user ID and status.

This method queries the database for an order request with the specified user ID and status, preloading its associated items and offers. If successful, it returns the order request model; otherwise, it returns an error.

Params: - userID (string): The user ID. - status ([]string): The order request statuses.

Returns: - (*models.OrderRequestModel): The order request model if found. - (error): An error object if the retrieval fails.

func (*OrderRequestService) GetOrderRequestByID

func (s *OrderRequestService) GetOrderRequestByID(orderRequestID string) (*models.OrderRequestModel, error)

func (*OrderRequestService) GetOrderRequestByUserIDWithStatus

func (s *OrderRequestService) GetOrderRequestByUserIDWithStatus(request http.Request, search string, userID string, status string) (paginate.Page, error)

GetOrderRequestByUserIDWithStatus retrieves paginated order requests by user ID and status.

This method queries the database for order requests with the specified user ID and status, preloading its associated items. If successful, it returns a paginated page of order requests; otherwise, it returns an error.

Params: - request (http.Request): The HTTP request. - search (string): The search query string. - userID (string): The user ID. - status (string): The order request status.

Returns: - (paginate.Page): The paginated page of order requests if found. - (error): An error object if the retrieval fails.

func (*OrderRequestService) GetPendingOrderRequests

func (s *OrderRequestService) GetPendingOrderRequests(merchantID string) ([]models.OrderRequestModel, error)

GetPendingOrderRequests retrieves a list of pending order requests associated with a merchant.

This method takes a merchant ID as a parameter and queries the database to find all order requests with the status "Pending" and the specified merchant ID. It returns a slice of OrderRequestModel and an error if the operation fails.

Params: - merchantID (string): The ID of the merchant to find pending order requests for.

Returns: - ([]models.OrderRequestModel): A slice of order request models that are pending for the merchant. - (error): An error object if the retrieval fails, or nil if successful.

Jump to

Keyboard shortcuts

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