Beispiel #1
0
func Search(title, lead, content, publishStart, publishEnd, active, slug, pageStr, resultsStr string, dtx *apicontext.DataContext) (pagination.Objects, error) {
	var err error
	var l pagination.Objects
	var fs []interface{}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return l, err
	}
	defer db.Close()

	stmt, err := db.Prepare(search)
	if err != nil {
		return l, err
	}
	defer stmt.Close()

	res, err := stmt.Query("%"+title+"%", "%"+lead+"%", "%"+content+"%", "%"+publishStart+"%", "%"+publishEnd+"%", "%"+active+"%", "%"+slug+"%", dtx.APIKey, dtx.BrandID, dtx.BrandID)
	for res.Next() {
		n, err := scanItem(res)
		if err == nil {
			fs = append(fs, n)
		}
	}
	defer res.Close()
	l = pagination.Paginate(pageStr, resultsStr, fs)
	return l, err
}
Beispiel #2
0
// Searches for a web property given all the web properties properties as search parameters.
func Search(name, custID, badgeID, url, isEnabled, sellerID, webPropertyTypeID, isFinalApproved, isEnabledDate, isDenied, requestedDate, typeID, pageStr, resultsStr string) (pagination.Objects, error) {
	var err error
	var l pagination.Objects
	var fs []interface{}

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return l, err
	}
	defer db.Close()

	stmt, err := db.Prepare(search)
	if err != nil {
		return l, err
	}
	defer stmt.Close()

	res, err := stmt.Query("%"+name+"%", "%"+custID+"%", "%"+url+"%", "%"+isEnabled+"%", "%"+sellerID+"%", "%"+webPropertyTypeID+"%", "%"+isFinalApproved+"%", "%"+isEnabledDate+"%", "%"+isDenied+"%", "%"+requestedDate+"%", "%"+typeID+"%")
	for res.Next() {
		var w WebProperty
		res.Scan(&w.ID, &w.Name, &w.CustID, &w.BadgeID, &w.Url, &w.IsEnabled, &w.SellerID, &w.WebPropertyType.ID, &w.IsFinalApproved, &w.IsEnabledDate, &w.IsDenied, &w.RequestedDate, &w.AddedDate)
		fs = append(fs, w)
	}
	l = pagination.Paginate(pageStr, resultsStr, fs)
	return l, err
}
Beispiel #3
0
func GetLeads(pageStr, resultsStr string, dtx *apicontext.DataContext) (pagination.Objects, error) {
	var err error
	var fs []interface{}
	var l pagination.Objects
	redis_key := "news:leads" + ":" + dtx.BrandString
	data, err := redis.Get(redis_key)
	if err == nil && len(data) > 0 {
		err = json.Unmarshal(data, &l)
		return l, err
	}
	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return l, err
	}
	defer db.Close()

	stmt, err := db.Prepare(getLeads)
	if err != nil {
		return l, err
	}
	defer stmt.Close()

	res, err := stmt.Query(dtx.APIKey, dtx.BrandID, dtx.BrandID)
	for res.Next() {
		var f News
		res.Scan(&f.Lead)
		fs = append(fs, f)
	}
	defer res.Close()
	l = pagination.Paginate(pageStr, resultsStr, fs)

	go redis.Setex(redis_key, l, 86400)
	return l, err
}
Beispiel #4
0
func Search(dtx *apicontext.DataContext, question, answer, pageStr, resultsStr string) (pagination.Objects, error) {
	var err error
	var fs []interface{}
	var p pagination.Objects

	db, err := sql.Open("mysql", database.ConnectionString())
	if err != nil {
		return p, err
	}
	defer db.Close()

	stmt, err := db.Prepare(searchFaqStmt)
	if err != nil {
		return p, err
	}
	defer stmt.Close()

	res, err := stmt.Query(dtx.APIKey, dtx.BrandID, "%"+question+"%", "%"+answer+"%")
	for res.Next() {
		var f Faq
		res.Scan(&f.ID, &f.Question, &f.Answer, &f.BrandID)
		fs = append(fs, f)
	}

	p = pagination.Paginate(pageStr, resultsStr, fs)
	return p, err
}