ui/offering.go
func (h *Handler) GetClientOfferings(tkn string, agent data.HexString,
	minUnitPrice, maxUnitPrice uint64, countries []string,
	offset, limit uint) (*GetClientOfferingsResult, error) {
	logger := h.logger.Add("method", "GetClientOfferings",
		"agent", agent, "minUnitPrice", minUnitPrice,
		"maxUnitPrice", maxUnitPrice, "countries", countries, "offset", offset,
		"limit", limit)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return nil, ErrAccessDenied
	}

	if minUnitPrice != 0 && maxUnitPrice != 0 &&
		minUnitPrice > maxUnitPrice {
		logger.Error(ErrBadUnitPriceRange.Error())
		return nil, ErrBadUnitPriceRange
	}

	cond, args := h.getClientOfferingsConditions(agent, minUnitPrice,
		maxUnitPrice, countries)

	count, err := h.numberOfObjects(
		logger, data.OfferingTable.Name(), cond, args)
	if err != nil {
		return nil, err
	}

	offsetLimit := h.offsetLimit(offset, limit)

	tail := fmt.Sprintf("%s %s %s",
		cond, activeOfferingSorting, offsetLimit)

	result, err := h.selectAllFrom(
		logger, data.OfferingTable, tail, args...)
	if err != nil {
		return nil, err
	}

	offerings := make([]data.Offering, len(result))

	for k, v := range result {
		offerings[k] = *v.(*data.Offering)
	}

	return &GetClientOfferingsResult{offerings, count}, nil
}
func (h *Handler) GetClientOfferings(tkn string, agent data.HexString,
	minUnitPrice, maxUnitPrice uint64, countries []string,
	offset, limit uint) (*GetClientOfferingsResult, error) {
	logger := h.logger.Add("method", "GetClientOfferings",
		"agent", agent, "minUnitPrice", minUnitPrice,
		"maxUnitPrice", maxUnitPrice, "countries", countries, "offset", offset,
		"limit", limit)

	if !h.token.Check(tkn) {
		logger.Warn("access denied")
		return nil, ErrAccessDenied
	}

	if minUnitPrice != 0 && maxUnitPrice != 0 &&
		minUnitPrice > maxUnitPrice {
		logger.Error(ErrBadUnitPriceRange.Error())
		return nil, ErrBadUnitPriceRange
	}

	cond, args := h.getClientOfferingsConditions(agent, minUnitPrice,
		maxUnitPrice, countries)

	count, err := h.numberOfObjects(
		logger, data.OfferingTable.Name(), cond, args)
	if err != nil {
		return nil, err
	}

	offsetLimit := h.offsetLimit(offset, limit)

	tail := fmt.Sprintf("%s %s %s",
		cond, activeOfferingSorting, offsetLimit)

	result, err := h.selectAllFrom(
		logger, data.OfferingTable, tail, args...)
	if err != nil {
		return nil, err
	}

	offerings := make([]data.Offering, len(result))

	for k, v := range result {
		offerings[k] = *v.(*data.Offering)
	}

	return &GetClientOfferingsResult{offerings, count}, nil
}
// GetClientOfferings returns active offerings available for a client.