当前位置: 首页>>代码示例>>Golang>>正文


Golang Repositories.DoorRepository方法代码示例

本文整理汇总了Golang中github.com/masom/doorbot/doorbot.Repositories.DoorRepository方法的典型用法代码示例。如果您正苦于以下问题:Golang Repositories.DoorRepository方法的具体用法?Golang Repositories.DoorRepository怎么用?Golang Repositories.DoorRepository使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/masom/doorbot/doorbot.Repositories的用法示例。


在下文中一共展示了Repositories.DoorRepository方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: Put

// Put updates a door
func Put(render render.Render, r doorbot.Repositories, params martini.Params, vm DoorViewModel) {
	id, err := strconv.ParseUint(params["id"], 10, 32)
	if err != nil {
		render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
		return
	}

	repo := r.DoorRepository()
	door, err := repo.Find(r.DB(), uint(id))
	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": r.AccountScope(),
			"door_id":    id,
			"step":       "door-find",
		}).Error("Api::Doors->Put database error")

		render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
		return
	}

	if door == nil {
		render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified door does not exists"}))
		return
	}

	door.Name = vm.Door.Name

	_, err = repo.Update(r.DB(), door)

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": r.AccountScope(),
			"door_id":    id,
			"step":       "door-update",
		}).Error("Api::Doors->Put database error")

		render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
		return
	}

	log.WithFields(log.Fields{
		"account_id": r.AccountScope(),
		"door_id":    vm.Door.ID,
	}).Error("Api::Doors->Post door updated")

	render.JSON(http.StatusOK, DoorViewModel{Door: door})
}
开发者ID:masom,项目名称:doorbot,代码行数:50,代码来源:doors.go

示例2: Index

// Index return a list of doors
func Index(render render.Render, r doorbot.Repositories) {
	repo := r.DoorRepository()

	doors, err := repo.All(r.DB())

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": r.AccountScope(),
		}).Error("Api::Doors->Index database error")

		render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
		return
	}

	render.JSON(http.StatusOK, DoorsViewModel{Doors: doors})
}
开发者ID:masom,项目名称:doorbot,代码行数:18,代码来源:doors.go

示例3: Post

// Post creates a door
func Post(render render.Render, r doorbot.Repositories, vm DoorViewModel) {
	repo := r.DoorRepository()

	err := repo.Create(r.DB(), vm.Door)

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": r.AccountScope(),
		}).Error("Api::Doors->Post database error")

		render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
		return
	}

	log.WithFields(log.Fields{
		"account_id": r.AccountScope(),
		"door_id":    vm.Door.ID,
	}).Error("Api::Doors->Post door created")

	render.JSON(http.StatusCreated, vm)
}
开发者ID:masom,项目名称:doorbot,代码行数:23,代码来源:doors.go

示例4: Get

// Get return a specific door
func Get(render render.Render, r doorbot.Repositories, params martini.Params) {
	id, err := strconv.ParseUint(params["id"], 10, 32)

	if err != nil {
		render.JSON(http.StatusBadRequest, doorbot.NewBadRequestErrorResponse([]string{"The id must be an unsigned integer"}))
		return
	}

	repo := r.DoorRepository()
	door, err := repo.Find(r.DB(), uint(id))

	if door == nil || err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": r.AccountScope(),
			"door_id":    id,
		}).Error("Api::Doors->Get database error")

		render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified door does not exists"}))
		return
	}

	render.JSON(http.StatusOK, DoorViewModel{Door: door})
}
开发者ID:masom,项目名称:doorbot,代码行数:25,代码来源:doors.go

示例5: Notify

// Notify someone their presence is needed at a given door.
func Notify(render render.Render, account *doorbot.Account, r doorbot.Repositories, notificator notifications.Notificator, vm ViewModel) {

	notification := vm.Notification

	log.WithFields(log.Fields{
		"account_id": account.ID,
		"person_id":  notification.PersonID,
		"door_id":    notification.DoorID,
	}).Info("Api::Notifications->Notify request")

	peopleRepo := r.PersonRepository()
	doorRepo := r.DoorRepository()

	person, err := peopleRepo.Find(r.DB(), notification.PersonID)

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": account.ID,
			"person_id":  notification.PersonID,
			"door_id":    notification.DoorID,
			"step":       "person-find",
		}).Error("Api::Notifications->Notify database error")

		render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
		return
	}

	if person == nil {
		render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified person does not exists."}))
		log.WithFields(log.Fields{
			"account_id": account.ID,
			"person_id":  notification.PersonID,
			"door_id":    notification.DoorID,
		}).Info("Api::Notifications->Notify person not found")
		return
	}

	if !person.IsVisible || !person.IsAvailable {
		log.WithFields(log.Fields{
			"account_id":          account.ID,
			"person_id":           notification.PersonID,
			"door_id":             notification.DoorID,
			"person_is_visible":   person.IsVisible,
			"person_is_available": person.IsAvailable,
		}).Info("Api::Notifications->Notify person is not available/visible")

		//TODO Would there be a better status code?
		render.JSON(http.StatusForbidden, doorbot.NewForbiddenErrorResponse([]string{"The specified user is currently not available."}))
		return
	}

	//TODO Infer from the  device token?
	door, err := doorRepo.Find(r.DB(), notification.DoorID)

	if err != nil {
		log.WithFields(log.Fields{
			"error":      err,
			"account_id": account.ID,
			"person_id":  notification.PersonID,
			"door_id":    notification.DoorID,
			"step":       "door-find",
		}).Error("Api::Notifications->Notify database error")
		render.JSON(http.StatusInternalServerError, doorbot.NewInternalServerErrorResponse([]string{}))
		return
	}

	if door == nil {
		render.JSON(http.StatusNotFound, doorbot.NewEntityNotFoundResponse([]string{"The specified door does not exists."}))
		log.WithFields(log.Fields{
			"account_id": account.ID,
			"person_id":  person.ID,
			"door_id":    notification.DoorID,
		}).Info("Api::Notifications->Notify door not found")
		return
	}

	notificator.KnockKnock(door, person)

	render.JSON(http.StatusAccepted, ViewModel{Notification: notification})
}
开发者ID:masom,项目名称:doorbot,代码行数:82,代码来源:notifications.go


注:本文中的github.com/masom/doorbot/doorbot.Repositories.DoorRepository方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。