예제 #1
0
func GetAuthority(txn gorp.SqlExecutor, id int) (*Authority, error) {
	authority, err := txn.Get(Authority{}, id)
	if err != nil {
		return nil, err
	}
	return authority.(*Authority), nil
}
예제 #2
0
func SetReply(entity models.WarningResp, enc Encoder, db gorp.SqlExecutor) (int, string) {

	if isInvalidReply(&entity) {
		return http.StatusBadRequest, Must(enc.EncodeOne(entity))
	}

	obj, err := db.Get(models.WarningResp{}, entity.Id)
	replyObj := obj.(*models.WarningResp)

	if err != nil || replyObj == nil || entity.Resp_hash != replyObj.Resp_hash {
		return http.StatusBadRequest, ""
	} else {
		replyObj.Message = entity.Message
		replyObj.Ip = entity.Ip
		replyObj.Browser = entity.Browser
		replyObj.Operating_system = entity.Operating_system
		replyObj.Device = entity.Device
		replyObj.Raw = entity.Raw
		replyObj.Reply_date = entity.Reply_date
		replyObj.Timezone = entity.Timezone

		go notifyReplyDone(replyObj, db)

		_, err = db.Update(replyObj)
		checkErr(err, "ERROR UpdateWarningSent ERROR")
	}

	return http.StatusOK, Must(enc.EncodeOne(replyObj))
}
예제 #3
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...)
}
예제 #4
0
파일: audit.go 프로젝트: kayac/alphawing
func GetAudit(txn gorp.SqlExecutor, id int) (*Audit, error) {
	audit, err := txn.Get(Audit{}, id)
	if err != nil {
		return nil, err
	}
	return audit.(*Audit), nil
}
예제 #5
0
파일: booking.go 프로젝트: pyanfield/revel
func (b *Booking) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

	obj, err = exe.Get(User{}, b.UserId)
	if err != nil {
		return fmt.Errorf("Error loading a booking's user (%d): %s", b.UserId, err)
	}
	b.User = obj.(*User)

	obj, err = exe.Get(Hotel{}, b.HotelId)
	if err != nil {
		return fmt.Errorf("Error loading a booking's hotel (%d): %s", b.HotelId, err)
	}
	b.Hotel = obj.(*Hotel)

	if b.CheckInDate, err = time.Parse(SQL_DATE_FORMAT, b.CheckInStr); err != nil {
		return fmt.Errorf("Error parsing check in date '%s':", b.CheckInStr, err)
	}
	if b.CheckOutDate, err = time.Parse(SQL_DATE_FORMAT, b.CheckOutStr); err != nil {
		return fmt.Errorf("Error parsing check out date '%s':", b.CheckOutStr, err)
	}
	return nil
}
func UpdateIgnoreList(entity *models.Ignore_List, db gorp.SqlExecutor) {

	_, err := db.Update(entity)
	if err != nil {
		checkErr(err, "update failed")
	}
}
func UpdateIgnoreSent(entity *models.Ignore_List, db gorp.SqlExecutor) bool {
	entity.Sent = true
	entity.Last_modified_date = time.Now().String()
	_, err := db.Update(entity)
	checkErr(err, "ERROR UpdateWarningSent ERROR")
	return err == nil
}
예제 #8
0
파일: app.go 프로젝트: kayac/alphawing
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
}
예제 #9
0
파일: app.go 프로젝트: kayac/alphawing
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
}
예제 #10
0
파일: bundle.go 프로젝트: kayac/alphawing
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
}
예제 #11
0
파일: bundle.go 프로젝트: kayac/alphawing
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
}
예제 #12
0
파일: bundle.go 프로젝트: kayac/alphawing
func (bundle *Bundle) App(txn gorp.SqlExecutor) (*App, error) {
	app, err := txn.Get(App{}, bundle.AppId)
	if err != nil {
		return nil, err
	}
	return app.(*App), nil
}
예제 #13
0
파일: user.go 프로젝트: kayac/alphawing
func GetUser(txn gorp.SqlExecutor, id int) (*User, error) {
	user, err := txn.Get(User{}, id)
	if err != nil {
		return nil, err
	}
	return user.(*User), nil
}
예제 #14
0
func UpdateReplySent(entity *models.WarningResp, db gorp.SqlExecutor) bool {
	entity.Sent = true

	_, err := db.Update(entity)
	checkErr(err, "ERROR UpdateReplySent ERROR")
	return err == nil
}
예제 #15
0
파일: app.go 프로젝트: kayac/alphawing
func (app *App) GetMaxRevisionByBundleVersion(txn gorp.SqlExecutor, bundleVersion string) (int, error) {
	revision, err := txn.SelectInt(
		"SELECT IFNULL(MAX(revision), 0) FROM bundle WHERE app_id = ? AND bundle_version = ?",
		app.Id,
		bundleVersion,
	)
	return int(revision), err
}
예제 #16
0
파일: api.go 프로젝트: hackerlist/monty
// Convenience types for loading info from the DB
func getbyid(tx gorp.SqlExecutor, typ interface{}, id int) (interface{}, error) {
	res, err := tx.Get(typ, id)
	if err != nil {
		return nil, err
	}

	return res, nil
}
예제 #17
0
파일: user.go 프로젝트: kayac/alphawing
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
}
예제 #18
0
파일: app.go 프로젝트: kayac/alphawing
func (app *App) Authorities(txn gorp.SqlExecutor) ([]*Authority, error) {
	var authorities []*Authority
	_, err := txn.Select(&authorities, "SELECT * FROM authority WHERE app_id = ? ORDER BY id ASC", app.Id)
	if err != nil {
		return nil, err
	}
	return authorities, nil
}
예제 #19
0
파일: app.go 프로젝트: kayac/alphawing
func (app *App) BundlesByPlatformType(txn gorp.SqlExecutor, platformType BundlePlatformType) ([]*Bundle, error) {
	var bundles []*Bundle
	_, err := txn.Select(&bundles, "SELECT * FROM bundle WHERE app_id = ? AND platform_type = ? ORDER BY id DESC", app.Id, platformType)
	if err != nil {
		return nil, err
	}
	return bundles, nil
}
예제 #20
0
파일: app.go 프로젝트: kayac/alphawing
func (app *App) Bundles(txn gorp.SqlExecutor) ([]*Bundle, error) {
	var bundles []*Bundle
	_, err := txn.Select(&bundles, "SELECT * FROM bundle WHERE app_id = ? ORDER BY id DESC", app.Id)
	if err != nil {
		return nil, err
	}
	return bundles, nil
}
func AddContact_type(entity models.DefaultStruct, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {
	err := db.Insert(&entity)
	if err != nil {
		checkErr(err, "INSERT CONTACT TYPE FAILED")
		return http.StatusBadRequest, ""
	}
	w.Header().Set("Location", fmt.Sprintf("/warnabroda/contact_types/%d", entity.Id))
	return http.StatusCreated, Must(enc.EncodeOne(entity))
}
예제 #22
0
func AddMessage(entity models.DefaultStruct, w http.ResponseWriter, enc Encoder, db gorp.SqlExecutor) (int, string) {
	err := db.Insert(&entity)
	if err != nil {
		checkErr(err, "insert failed")
		return http.StatusBadRequest, ""
	}
	w.Header().Set("Location", fmt.Sprintf("/warnabroda/messages/%d", entity.Id))
	return http.StatusCreated, Must(enc.EncodeOne(entity))
}
예제 #23
0
func GetSubjects(enc Encoder, db gorp.SqlExecutor) (int, string) {
	var subjects []models.DefaultStruct
	_, err := db.Select(&subjects, SQL_SELECT_SUBJECTS_BY_ID)
	if err != nil {
		checkErr(err, "SELECT SUBJECTS FAILED")
		return http.StatusInternalServerError, ""
	}
	return http.StatusOK, Must(enc.Encode(subjectsToIface(subjects)...))
}
func GetContact_types(enc Encoder, db gorp.SqlExecutor) (int, string) {
	var contact_types []models.DefaultStruct
	_, err := db.Select(&contact_types, SQL_CONTACT_TYPES_BY_ID)
	if err != nil {
		checkErr(err, "SELECT CONTACT TYPES FAILED")
		return http.StatusBadRequest, ""
	}
	return http.StatusOK, Must(enc.Encode(contact_typesToIface(contact_types)...))
}
예제 #25
0
파일: app.go 프로젝트: kayac/alphawing
func (app *App) HasAuthorityForEmail(txn gorp.SqlExecutor, email string) (bool, error) {
	count, err := txn.SelectInt("SELECT COUNT(id) FROM authority WHERE app_id = ? AND email = ?", app.Id, email)
	if err != nil {
		return false, err
	}
	if count > 0 {
		return true, nil
	}
	return false, nil
}
예제 #26
0
// PostInsert ensures that the Attendees list is set in the database
func (i *Invite) PostInsert(s gorp.SqlExecutor) error {
	query := "insert into profile_invite values ($1, $2, $3)"
	for _, a := range i.Attendees {
		_, err := s.Exec(query, a.Id, i.Id, string(a.Status))
		if err != nil {
			return err
		}
	}
	return nil
}
예제 #27
0
// intercepts more than two requests to ignore list add.
func MoreThanTwoRequestByIp(db gorp.SqlExecutor, entity *models.Ignore_List) bool {

	sql := SQL_COUNT_MULTIPLE_IGNOREME_REQUESTS

	total, err := db.SelectInt(sql, entity.Ip)
	checkErr(err, "COUNT ERROR")

	return total >= 2

}
예제 #28
0
func GetIgnoreContactById(id int64, db gorp.SqlExecutor) *models.Ignore_List {
	obj, err := db.Get(models.Ignore_List{}, id)

	if err != nil || obj == nil {
		return nil
	}

	entity := obj.(*models.Ignore_List)
	return entity
}
예제 #29
0
func IsExistAuthorityForEmail(txn gorp.SqlExecutor, email string) (bool, error) {
	count, err := txn.SelectInt("SELECT COUNT(id) FROM authority WHERE email = ?", email)
	if err != nil {
		return false, err
	}
	if count > 0 {
		return true, nil
	}
	return false, nil
}
예제 #30
0
파일: app.go 프로젝트: kayac/alphawing
func (app *App) RefreshToken(txn gorp.SqlExecutor) error {
	current, err := GetApp(txn, app.Id)
	if err != nil {
		return err
	}

	current.ApiToken = NewToken()

	_, err = txn.Update(current)
	return err
}