コード例 #1
0
ファイル: authority.go プロジェクト: kayac/alphawing
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
}
コード例 #6
0
func UpdateIgnoreList(entity *models.Ignore_List, db gorp.SqlExecutor) {

	_, err := db.Update(entity)
	if err != nil {
		checkErr(err, "update failed")
	}
}
コード例 #7
0
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
}
コード例 #21
0
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)...))
}
コード例 #24
0
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
ファイル: profile.go プロジェクト: randallsquared/gochute
// 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
ファイル: authority.go プロジェクト: kayac/alphawing
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
}