示例#1
0
//Deletes a certain account from the db
func deleteAccountHandler(db *gorm.DB, acc account, rendr render.Render) {
	if err := db.Delete(&acc).Error; err != nil {
		rendr.Text(http.StatusInternalServerError, err.Error())
	} else {
		rendr.Text(http.StatusOK, "Account deleted")
	}
}
示例#2
0
func MediaDelete(db gorm.DB, r render.Render, params martini.Params) {
	var media models.Media
	if err := db.First(&media, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Media not found"})
		return
	}
	db.Delete(media)
	r.JSON(http.StatusNoContent, nil)
}
func ProjectDelete(db gorm.DB, r render.Render, params martini.Params) {
	var project models.Project
	if err := db.First(&project, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Project not found"})
		return
	}
	db.Delete(project)
	r.JSON(http.StatusNoContent, nil)
}
示例#4
0
func GroupDelete(db gorm.DB, r render.Render, params martini.Params) {
	var group models.Group
	if err := db.First(&group, params["id"]).Error; err != nil {
		r.JSON(http.StatusNotFound, map[string]interface{}{"error": "Group not found"})
		return
	}
	db.Delete(group)
	r.JSON(http.StatusNoContent, nil)
}
示例#5
0
文件: dao.go 项目: itpkg/base
func (p *AuthDao) DelRole(db *gorm.DB, user uint, name string, resource_type string, resource_id uint) {
	role := p.getRole(db, name, resource_type, resource_id)
	for _, pe := range role.Permissions {
		if pe.UserID == user {
			db.Delete(&pe)
			return
		}
	}

}
示例#6
0
//Deletes a user based on a given path `id` param
func deleteUserHandler(db *gorm.DB, params martini.Params, ren render.Render) {
	u, err := findUserFromIDParam(db, params["id"])
	if err != nil {
		ren.Text(err.toMartiniRender())
		return
	}
	if db.Delete(&u).Error != nil {
		ren.Text(http.StatusInternalServerError, err.Error())
		return
	}
	ren.Text(http.StatusOK, fmt.Sprintf("User with id: %d was deleted", u.ID))
}
func deleteTodoHandler(params martini.Params, rendr render.Render, db *gorm.DB) {
	id, err := strconv.Atoi(params["id"])
	if err != nil {
		panic(err)
	}

	t, err := findTodo(db, &todo{ID: id})
	if err != nil {
		rendr.Text(http.StatusBadRequest, err.Error())
		return
	}

	db.Delete(&t)
	rendr.JSON(http.StatusOK, t)
}
// GetDeleteTaskHandler creates HTTP handler for Delete Task operation
func GetDeleteTaskHandler(db *gorm.DB) echo.HandlerFunc {
	return func(c *echo.Context) error {
		id, err := strconv.ParseInt(c.Param("id"), 10, 64)
		if err != nil {
			return c.JSON(http.StatusBadRequest, NewApiError(err.Error()))
		}

		task := model.Task{Id: id}
		if err := db.Delete(&task).Error; err != nil {
			return c.JSON(http.StatusInternalServerError, NewApiError(err.Error()))
		}

		return c.JSON(http.StatusOK, task)
	}
}
示例#9
0
// BeforeDelete invokes required actions before deletion.
func (u *Repo) BeforeDelete(tx *gorm.DB) error {
	tags := Tags{}

	tx.Model(
		u,
	).Related(
		&tags,
	)

	for _, tag := range tags {
		if err := tx.Delete(tag).Error; err != nil {
			return err
		}
	}

	return nil
}
示例#10
0
func upgrade_v3(db gorm.DB) {
	// Hash the passwords
	logging.Info("Migrating 2 => 3")

	var unhashed []user.AuthenticationMethod
	db.Where("method_type = ?", user.AUTH_PASSWD).Find(&unhashed)

	for i := 0; i < len(unhashed); i++ {
		hashed, err := user.HashedPasswordAuth(unhashed[i].Value)
		if err != nil {
			logging.Error("data", "Could not transform password. ID ", unhashed[i].ID)
		} else {
			hashed.UserID = unhashed[i].UserID

			db.Create(&hashed)
			db.Delete(&unhashed[i])
		}
	}
}
示例#11
0
func DeleteSpaceSetting(db gorm.DB, router *gin.Engine) {

	router.DELETE("/space_setting/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			space_setting := &model.SpaceSetting{
				SpaceSettingId: model.SpaceSettingId{Id: id},
			}
			if err := db.First(space_setting).Error; err == nil {
				db.Delete(space_setting)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
示例#12
0
func DeleteWallEntry(db gorm.DB, router *gin.Engine) {

	router.DELETE("/wall_entry/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			wall_entry := &model.WallEntry{
				WallEntryId: model.WallEntryId{Id: id},
			}
			if err := db.First(wall_entry).Error; err == nil {
				db.Delete(wall_entry)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
示例#13
0
func DeleteGroupAdmin(db gorm.DB, router *gin.Engine) {

	router.DELETE("/group_admin/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			group_admin := &model.GroupAdmin{
				GroupAdminId: model.GroupAdminId{Id: id},
			}
			if err := db.First(group_admin).Error; err == nil {
				db.Delete(group_admin)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
示例#14
0
func DeleteModuleEnabled(db gorm.DB, router *gin.Engine) {

	router.DELETE("/module_enabled/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			module_enabled := &model.ModuleEnabled{
				ModuleEnabledId: model.ModuleEnabledId{Id: id},
			}
			if err := db.First(module_enabled).Error; err == nil {
				db.Delete(module_enabled)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
示例#15
0
func DeleteUserHttpSession(db gorm.DB, router *gin.Engine) {

	router.DELETE("/user_http_session/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			user_http_session := &model.UserHttpSession{
				UserHttpSessionId: model.UserHttpSessionId{Id: id},
			}
			if err := db.First(user_http_session).Error; err == nil {
				db.Delete(user_http_session)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
示例#16
0
func DeleteLike(db gorm.DB, router *gin.Engine) {

	router.DELETE("/like/:id", func(c *gin.Context) {
		_id := c.Param("id")
		if id, err := strconv.ParseUint(_id, 10, 64); err == nil {
			like := &model.Like{
				LikeId: model.LikeId{Id: id},
			}
			if err := db.First(like).Error; err == nil {
				db.Delete(like)
				c.AbortWithStatus(http.StatusOK)
			} else {
				c.AbortWithStatus(http.StatusNotFound)
			}
		} else {
			log.Print(err)
			c.AbortWithError(http.StatusBadRequest, err)
		}
	})
}
示例#17
0
// DeleteInstance
// URL: /v2/service_instances/:id
// Request:
// {
//   "service_id": "service-id-here"
//   "plan_id":    "plan-id-here"
// }
func DeleteInstance(p martini.Params, r render.Render, brokerDb *gorm.DB, s *Settings) {
	instance := Instance{}

	brokerDb.Where("uuid = ?", p["id"]).First(&instance)

	if instance.Id == 0 {
		r.JSON(http.StatusNotFound, Response{"Instance not found"})
		return
	}

	var plan *Plan
	plan = FindPlan(instance.PlanId)

	if plan == nil {
		r.JSON(http.StatusBadRequest, Response{"The plan requested does not exist"})
		return
	}
	// Get the correct database logic depending on the type of plan. (shared vs dedicated)
	db, err := s.InitializeAdapter(plan, brokerDb)
	if err != nil {
		desc := "There was an error deleting the instance. Error: " + err.Error()
		r.JSON(http.StatusInternalServerError, Response{desc})
		return
	}
	var status DBInstanceState
	// Delete the database instance.
	if status, err = db.DeleteDB(&instance); status == InstanceNotGone {
		desc := "There was an error deleting the instance."
		if err != nil {
			desc = desc + " Error: " + err.Error()
		}
		r.JSON(http.StatusInternalServerError, Response{desc})
		return
	}
	brokerDb.Delete(&instance)
	r.JSON(http.StatusOK, Response{"The instance was deleted"})
}
示例#18
0
func main() {
	var (
		db   gorm.DB
		user *User
	)

	user = new(User)

	db = SetupDb()

	//START CODE OMIT
	db.Save(&User{FirstName: "John", LastName: "Doe", Age: 25})
	PrintTable(db)

	db.First(user, 1)

	user.FirstName = "James"
	db.Save(user)
	PrintTable(db)

	db.Delete(user)
	PrintTable(db)
	//END CODE OMIT
}
示例#19
0
文件: releases.go 项目: hobeone/gonab
func deleteBinary(tx *gorm.DB, dbbin *types.Binary) error {
	// Delete Parts
	err := tx.Where("binary_id = ?", dbbin.ID).Delete(types.Part{}).Error
	if err != nil {
		return err
	}

	// Delete segments.
	partids := make([]int64, len(dbbin.Parts))
	for i, p := range dbbin.Parts {
		partids[i] = p.ID
	}
	err = tx.Where("part_id in (?)", partids).Delete(types.Segment{}).Error
	if err != nil {
		return err
	}

	// Delete binary
	err = tx.Delete(dbbin).Error
	if err != nil {
		return err
	}
	return nil
}
示例#20
0
func (*PersonAddress) Delete(db *gorm.DB, sources ...interface{}) error {
	return db.Delete(&PersonAddress{}).Error
}
示例#21
0
文件: domains.go 项目: brianz/empire
func domainsDestroy(db *gorm.DB, domain *Domain) error {
	return db.Delete(domain).Error
}
示例#22
0
文件: feed.go 项目: asvins/core
func (e *FeedEvent) Delete(db *gorm.DB) error {
	return db.Delete(e).Error
}
示例#23
0
func (*PersonAddress) Delete(handler gorm.JoinTableHandlerInterface, db *gorm.DB, sources ...interface{}) error {
	return db.Delete(&PersonAddress{}).Error
}
示例#24
0
// New creates a new resource that exposes the DBModel returned by
// `single` as a HTTP API. `collection` should return an array of the
// same type as `single`.
func New(db *gorm.DB, single func() DBModel, collection func() interface{}, linker func(id uint) string) Resource {

	r := Resource{}

	r.Collection = func(ctx *gin.Context, owner DBModel) {
		c := collection()
		if err := db.Model(owner).Related(c).Error; err != nil && err != gorm.ErrRecordNotFound {
			panic(err)
		}

		ctx.JSON(http.StatusOK, c)
	}

	r.Post = func(ctx *gin.Context, user User, parent DBModel) {
		s := single()
		if ctx.BindJSON(s) != nil {
			ctx.JSON(HTTPStatusUnprocessableEntity, errToJSON(ErrRequestMissingAttrs))
			return
		}
		if err := s.SetOwner(user); err != nil {
			panic(err)
		}
		if err := s.SetParent(parent); err != nil {
			panic(err)
		}

		if err := db.Create(s).Error; err != nil {
			if reflect.TypeOf(err) == AcceptableError {
				ctx.JSON(HTTPStatusUnprocessableEntity, errToJSON(err))
			} else {
				panic(err)
			}
		}

		ctx.Header("Location", absURL(ctx.Request, linker(s.GetID())))
		ctx.JSON(http.StatusCreated, s)
	}

	r.Get = func(ctx *gin.Context, s DBModel) {
		ctx.JSON(http.StatusOK, s)
	}

	r.Patch = func(ctx *gin.Context, s DBModel) {
		newS := single()
		if ctx.BindJSON(newS) != nil {
			ctx.JSON(HTTPStatusUnprocessableEntity, errToJSON(ErrRequestMissingAttrs))
			return
		}

		if err := db.Model(s).Updates(newS).Error; err != nil {
			panic(err)
		}

		ctx.JSON(http.StatusOK, newS)
	}

	r.Delete = func(ctx *gin.Context, s DBModel) {
		if err := db.Delete(s).Error; err != nil {
			panic(err)
		}

		ctx.AbortWithStatus(http.StatusNoContent)
	}

	r.ProvideModelForKey = func(key string) func(ModelHandler) gin.HandlerFunc {
		return func(handler ModelHandler) gin.HandlerFunc {
			return func(ctx *gin.Context) {
				id := ctx.Param(key)

				if !regexpID.MatchString(id) {
					ctx.AbortWithError(http.StatusNotFound, gorm.ErrRecordNotFound)
					return
				}

				s := single()
				if err := db.Where("id = ?", id).First(s).Error; err == gorm.ErrRecordNotFound {
					ctx.AbortWithError(http.StatusNotFound, gorm.ErrRecordNotFound)
					return
				} else if err != nil {
					panic(err)
				}

				handler(ctx, s)
			}
		}
	}

	r.ProvideModel = r.ProvideModelForKey("id")

	return r
}
示例#25
0
文件: apps.go 项目: brianz/empire
// appsDestroy destroys an app.
func appsDestroy(db *gorm.DB, app *App) error {
	return db.Delete(app).Error
}
示例#26
0
文件: box.go 项目: asvins/operations
func (b *Box) Delete(db *gorm.DB) error {
	return db.Delete(b).Error
}
示例#27
0
文件: blog.go 项目: bishen/blog
func Delete(params martini.Params, db *gorm.DB) string {
	db.Delete(models.Blog{}, params["id"])
	return "<script>alert('删除完成');window.history.back()</script>"
}
示例#28
0
文件: pack.go 项目: asvins/operations
func (p *Pack) Delete(db *gorm.DB) error {
	return db.Delete(p).Error
}
示例#29
0
文件: ssl.go 项目: yourchanges/empire
func certificatesDestroy(db *gorm.DB, cert *Certificate) error {
	return db.Delete(cert).Error
}
示例#30
0
文件: main.go 项目: oblank/go-todo
func (uc ItemController) DeleteItem(db gorm.DB, id int64) string {
	obj := model.Element{ID: id}
	db.Delete(&obj)
	return ""
}