Documentation
¶
Index ¶
- func Migrate(tx *gorm.DB) error
- type OfferingService
- func (s *OfferingService) CreateOffer(merchant models.MerchantAvailableProduct, userID string) (*models.OfferModel, error)
- func (s *OfferingService) CreateOffers(orderRequest models.OrderRequestModel, ...) error
- func (s *OfferingService) GetOffersForByIDs(userID string, offerIds []string) ([]models.OfferModel, error)
- func (s *OfferingService) GetOffersForUser(userID, status string, orderRequestID *string) ([]models.OfferModel, error)
- func (s *OfferingService) TakeOffer(offerID string, totalPrice, shippingFee, distance float64) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type OfferingService ¶
type OfferingService struct {
// contains filtered or unexported fields
}
func NewOfferingService ¶
func NewOfferingService(db *gorm.DB, ctx *context.ERPContext, auditTrailSrv *audit_trail.AuditTrailService) *OfferingService
func (*OfferingService) CreateOffer ¶
func (s *OfferingService) CreateOffer(merchant models.MerchantAvailableProduct, userID string) (*models.OfferModel, error)
func (*OfferingService) CreateOffers ¶
func (s *OfferingService) CreateOffers(orderRequest models.OrderRequestModel, availableMerchants []models.MerchantAvailableProduct) error
CreateOffers creates offers for an order request from a list of available merchants.
This method takes an OrderRequestModel and a slice of MerchantAvailableProduct as parameters, constructs an OfferModel for each merchant, and persists them to the database. The offer's status is initially set to "PENDING". The method also logs the action using the audit trail service.
If the order request is already accepted, the method returns an error.
Params:
- orderRequest (models.OrderRequestModel): The order request for which offers will be created.
- availableMerchants ([]models.MerchantAvailableProduct): A slice of merchant information and product details for the offers.
Returns: - (error): An error object if the creation fails, or nil if the operation is successful.
func (*OfferingService) GetOffersForByIDs ¶
func (s *OfferingService) GetOffersForByIDs(userID string, offerIds []string) ([]models.OfferModel, error)
func (*OfferingService) GetOffersForUser ¶
func (s *OfferingService) GetOffersForUser(userID, status string, orderRequestID *string) ([]models.OfferModel, error)
GetOffersForUser retrieves a list of offers for a specified user ID, status, and order request ID.
This method queries the database to find all offers associated with the provided user ID, status, and order request ID. It returns a slice of OfferModel and an error if the operation fails.
Params: - userID (string): The ID of the user whose offers are to be retrieved. - status (string): The status of the offers to be retrieved. - orderRequestID (*string): An optional order request ID to filter the offers.
Returns: - ([]models.OfferModel): A slice of offer models that match the criteria. - (error): An error object if the database query fails, otherwise nil.
func (*OfferingService) TakeOffer ¶
func (s *OfferingService) TakeOffer(offerID string, totalPrice, shippingFee, distance float64) error
TakeOffer takes an offer and updates the order request status to Accepted.
This method takes an offer ID, total price, shipping fee, and distance as parameters. It first checks if the offer is already taken, and returns an error if it is. Then it verifies the order request status and returns an error if the order request is not in the pending status.
If the offer is taken successfully, the method also updates the order request status to Accepted and sets the merchant ID.
Params: - offerID (string): The ID of the offer to be taken. - totalPrice (float64): The total price of the offer. - shippingFee (float64): The shipping fee of the offer. - distance (float64): The distance of the offer.
Returns: - (error): An error object if the taking fails, or nil if the operation is successful.