コード例 #1
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
}
コード例 #2
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
}
コード例 #3
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
}
コード例 #4
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))
}
コード例 #5
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
}
コード例 #6
0
func SaveOrUpdateMessage(entity models.MessageStruct, enc Encoder, db gorp.SqlExecutor, user sessionauth.User) (int, string) {

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

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

		entity.Last_modified_by = user.UniqueId().(int)

		if entity.Id < 1 {
			err := db.Insert(&entity)
			if err != nil {
				checkErr(err, "insert failed")
				return http.StatusBadRequest, ""
			}
		} else {
			obj, _ := db.Get(models.MessageStruct{}, entity.Id)
			if obj == nil {
				// Invalid id, or does not exist
				return http.StatusBadRequest, ""
			}

			_, err := db.Update(&entity)
			if err != nil {
				checkErr(err, "update failed")
				return http.StatusBadRequest, ""
			}
		}

		return http.StatusOK, Must(enc.EncodeOne(entity))

	}

	return http.StatusUnauthorized, ""
}
コード例 #7
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
}
コード例 #8
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
}
コード例 #9
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
}
コード例 #10
0
func GetReplyById(id int64, db gorp.SqlExecutor) *models.WarningResp {

	obj, err := db.Get(models.WarningResp{}, id)

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

	entity := obj.(*models.WarningResp)
	return entity
}
コード例 #11
0
// Get a subject by ID
func GetSubject(enc Encoder, db gorp.SqlExecutor, parms martini.Params) (int, string) {
	id, err := strconv.Atoi(parms["id"])
	obj, _ := db.Get(models.DefaultStruct{}, id)
	if err != nil || obj == nil {
		checkErr(err, "GET SUBJECT FAILED")
		// Invalid id, or does not exist
		return http.StatusNotFound, ""
	}
	entity := obj.(*models.DefaultStruct)
	return http.StatusOK, Must(enc.EncodeOne(entity))
}
コード例 #12
0
func GetContact_type(enc Encoder, db gorp.SqlExecutor, parms martini.Params) (int, string) {
	id, err := strconv.Atoi(parms["id"])
	obj, _ := db.Get(models.DefaultStruct{}, id)
	if err != nil || obj == nil {
		checkErr(err, "GET CONTACT TYPE FAILED")
		// Invalid id, or does not exist
		return http.StatusBadRequest, ""
	}
	entity := obj.(*models.DefaultStruct)
	return http.StatusOK, Must(enc.EncodeOne(entity))
}
コード例 #13
0
func UserById(id int, db gorp.SqlExecutor) *models.User {

	obj, err := db.Get(models.User{}, id)

	if err != nil || obj == nil {
		return nil
	}
	entity := obj.(*models.User)

	return entity
}
コード例 #14
0
func GetWarning(id int64, db gorp.SqlExecutor) *models.Warning {

	obj, err := db.Get(models.Warning{}, id)

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

	entity := obj.(*models.Warning)
	return entity
}
コード例 #15
0
func notifyReplyDone(entity *models.WarningResp, db gorp.SqlExecutor) {
	obj, err := db.Get(models.Warning{}, entity.Id_warning)
	if err == nil {
		warningObj := obj.(*models.Warning)
		warningObj.WarnResp = entity

		if strings.Contains(entity.Reply_to, "@") { //notify the reply is ready via e-mail
			SendEmailReplyDone(warningObj, db)
		} else { //notify the reply is ready via e-mail
			SendWhatsappReplyDone(warningObj, db)
		}
	}

}
コード例 #16
0
ファイル: post.go プロジェクト: mischief/airplane
func (p *Post) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

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

	p.User = obj.(*User)

	return nil
}
コード例 #17
0
func DeleteIgnoreList(db gorp.SqlExecutor, parms martini.Params) (int, string) {
	id, err := strconv.Atoi(parms["id"])
	obj, _ := db.Get(models.Ignore_List{}, id)
	if err != nil || obj == nil {
		checkErr(err, "get failed")
		// Invalid id, or does not exist
		return http.StatusBadRequest, ""
	}
	entity := obj.(*models.Ignore_List)
	_, err = db.Delete(entity)
	if err != nil {
		checkErr(err, "delete failed")
		return http.StatusBadRequest, ""
	}
	return http.StatusOK, ""
}
コード例 #18
0
func DeleteContact_type(db gorp.SqlExecutor, parms martini.Params) (int, string) {
	id, err := strconv.Atoi(parms["id"])
	obj, _ := db.Get(models.DefaultStruct{}, id)
	if err != nil || obj == nil {
		checkErr(err, "GET CONTACT TYPE FAILED")
		// Invalid id, or does not exist
		return http.StatusBadRequest, ""
	}
	entity := obj.(*models.DefaultStruct)
	_, err = db.Delete(entity)
	if err != nil {
		checkErr(err, "DELETE CONTACT TYPE FAILED")
		return http.StatusConflict, ""
	}
	return http.StatusBadRequest, ""
}
コード例 #19
0
func GetWarningDetail(enc Encoder, db gorp.SqlExecutor, user sessionauth.User, parms martini.Params) (int, string) {

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

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

		id, err := strconv.Atoi(parms["id"])
		obj, _ := db.Get(models.Warning{}, id)
		if err != nil || obj == nil {
			checkErr(err, "GET WARNING DETAIL FAILED")
			// Invalid id, or does not exist
			return http.StatusNotFound, ""
		}
		entity := obj.(*models.Warning)
		return http.StatusOK, Must(enc.EncodeOne(entity))
	}

	return http.StatusUnauthorized, ""

}
コード例 #20
0
func ReadReply(entity models.WarningResp, enc Encoder, db gorp.SqlExecutor) (int, string) {

	if isInvalidReplyRead(&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.Read_hash != replyObj.Read_hash {
		return http.StatusBadRequest, ""
	} else {
		replyObj.Response_read = entity.Response_read

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

	return http.StatusOK, ""

}
コード例 #21
0
ファイル: profile.go プロジェクト: jango2015/baseapp
func (p *Profile) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

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

	/*obj, err = exe.Get(Post{}, p.ProfileId)
	if err != nil {
		return fmt.Errorf("Error loading a profile's posts (%d): %s", p.ProfileId, err)
	}
	var posts []*Post
	for _, post := range obj {
		posts = append(posts, post.(*Post))
	}
	p.Posts = posts*/

	return nil
}
コード例 #22
0
ファイル: project.go プロジェクト: shaheemirza/CAGo
func (c *ProjectMembership) PostGet(exe gorp.SqlExecutor) error {
	var (
		obj interface{}
		err error
	)

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

	if c.ProjectId != 0 {
		obj, err = exe.Get(Project{}, c.ProjectId)
		if err != nil {
			return fmt.Errorf("Error loading a certificate (%d): %s", c.ProjectId, err)
		}
		c.Project = obj.(*Project)
	}

	return nil
}