Esempio n. 1
0
func GetAppByApiToken(txn gorp.SqlExecutor, apiToken string) (*App, error) {
	var app App
	if err := txn.SelectOne(&app, "SELECT * FROM app where api_token = ?", apiToken); err != nil {
		return nil, err
	}
	return &app, nil
}
Esempio n. 2
0
func SelectOne(s gorp.SqlExecutor, builder squirrel.SelectBuilder, src interface{}) error {
	sql, args, err := builder.ToSql()
	if err != nil {
		return err
	}
	return s.SelectOne(src, sql, args...)
}
Esempio n. 3
0
func GetBundleByFileId(txn gorp.SqlExecutor, fileId string) (*Bundle, error) {
	var bundle Bundle
	if err := txn.SelectOne(&bundle, "SELECT * FROM bundle WHERE file_id = ?", fileId); err != nil {
		return nil, err
	}
	return &bundle, nil
}
Esempio n. 4
0
func GetApp(txn gorp.SqlExecutor, id int) (*App, error) {
	var app App
	if err := txn.SelectOne(&app, "SELECT * FROM app WHERE id = ?", id); err != nil {
		return nil, err
	}
	return &app, nil
}
Esempio n. 5
0
func GetBundle(txn gorp.SqlExecutor, id int) (*Bundle, error) {
	var bundle Bundle
	if err := txn.SelectOne(&bundle, "SELECT * FROM bundle WHERE id = ?", id); err != nil {
		return nil, err
	}
	return &bundle, nil
}
Esempio n. 6
0
func GetUserFromEmail(txn gorp.SqlExecutor, email string) (*User, error) {
	var user User
	err := txn.SelectOne(&user, "SELECT * FROM user WHERE email = ?", email)
	if err != nil {
		return nil, err
	}
	return &user, nil
}
func SelectMessage(db gorp.SqlExecutor, id int64) models.DefaultStruct {

	entity := models.DefaultStruct{}

	err := db.SelectOne(&entity, SQL_MESSAGES_BY_ID, id)

	if err != nil {
		checkErr(err, "select failed")
	}

	return entity
}
func getReplyReadHash(hash string, db gorp.SqlExecutor) *models.WarningResp {
	var reply models.WarningResp
	err := db.SelectOne(&reply, SQL_SELECT_REPLY_BY_READ_HASH,
		map[string]interface{}{
			"hash": hash,
		})
	if err != nil {
		return nil
	}

	return &reply
}
Esempio n. 9
0
func GetUserByLogin(postedUser models.UserLogin, db gorp.SqlExecutor) *models.User {

	user := models.User{}

	db.SelectOne(&user, SQL_LOGIN,
		map[string]interface{}{
			"user": postedUser.Username,
			"pass": postedUser.Password,
		})

	return &user
}
// Get an existent ignoreme register, in case there is none returns nil
func GetIgnoreContact(db gorp.SqlExecutor, id string) *models.Ignore_List {

	var ignored models.Ignore_List
	err := db.SelectOne(&ignored, SQL_IN_IGNORE_LIST_BY_CODE,
		map[string]interface{}{
			"code": id,
		})
	if err != nil {
		return nil
	}

	return &ignored
}
// Check if the contact already requested an ignore list add.
// In case the contact exists on the list the method returns it
func InIgnoreList(db gorp.SqlExecutor, contact string) *models.Ignore_List {
	fmt.Println("InIgnoreList")

	ignored := models.Ignore_List{}

	err := db.SelectOne(&ignored, SQL_IN_IGNORE_LIST_BY_CONTACT,
		map[string]interface{}{
			"contact": contact,
		})
	if err != nil {
		return nil
	}

	return &ignored
}
Esempio n. 12
0
func GetMessage(enc Encoder, db gorp.SqlExecutor, parms martini.Params) (int, string) {
	id, err := strconv.Atoi(parms["id"])

	if err != nil {
		// Invalid id, or does not exist
		return http.StatusBadRequest, ""
	}

	obj := models.MessageStruct{}
	err = db.SelectOne(&obj, "SELECT * FROM messages WHERE id=?", id)

	if err != nil {
		checkErr(err, "get failed")
		// Invalid id, or does not exist
		return http.StatusBadRequest, ""
	}
	return http.StatusOK, Must(enc.EncodeOne(obj))
}
Esempio n. 13
0
// count all warnings registered
func WarnaCounter(enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {

	counts := models.CountWarning{}

	u := UserById(user.UniqueId().(int), db)

	if user.IsAuthenticated() && u.UserRole == models.ROLE_ADMIN {

		err := db.SelectOne(&counts, SQL_WARN_COUNT)
		checkErr(err, "COUNT SENT WARNINGS ERROR")

		if err == nil {
			return http.StatusOK, Must(enc.EncodeOne(counts))
		} else {
			return http.StatusBadRequest, ""
		}

	}

	return http.StatusUnauthorized, ""
}