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


Golang DB.GetUserWithId方法代码示例

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


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

示例1: HandleCreateIRLMoji

func HandleCreateIRLMoji(r render.Render, bindErr binding.Errors, im models.IRLMoji, db *models.DB, backchannel Backchannel) {
	if bindErr.Count() > 0 {
		r.JSON(400, JsonErrBinding(bindErr))
		return
	}

	if backchannel.UserId() == "" {
		r.JSON(403, JsonErr("The provided credentials were invalid."))
		return
	}

	user, err := db.GetUserWithId(backchannel.UserId())
	if err != nil {
		r.JSON(403, "Could not find a user with your credentials.")
		return
	}

	// Now let's create that user, shall we?
	insertedIM, err := db.InsertIM(user.Id, im.Emoji, im.Picture)
	if err != nil {
		log.Println("Error creating user:", err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
		return
	}

	r.JSON(200, map[string]*models.IRLMoji{"irlmoji": insertedIM})
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:27,代码来源:handlers_irlmoji.go

示例2: HandleGetCurrentUser

func HandleGetCurrentUser(r render.Render, backchannel Backchannel, db *models.DB) {
	if backchannel.UserId() == "" {
		r.JSON(200, map[string]*models.User{"user": nil})
		return
	}
	if user, err := db.GetUserWithId(backchannel.UserId()); err == nil {
		r.JSON(200, map[string]*models.User{"user": user})
	} else {
		log.Println("Error getting current user:", err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
	}
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:12,代码来源:handlers_user.go

示例3: HandleToggleHeart

func HandleToggleHeart(r render.Render, bindErr binding.Errors, heart models.Heart, db *models.DB, backchannel Backchannel) {
	if bindErr.Count() > 0 {
		r.JSON(400, JsonErrBinding(bindErr))
		return
	}

	if backchannel.UserId() == "" {
		r.JSON(403, JsonErr("The provided credentials were invalid."))
		return
	}

	im, err := db.GetIMWithId(heart.IRLMojiId)
	if err != nil {
		r.JSON(404, JsonErr("The provided IRLMoji id was invalid."))
		return
	}

	user, err := db.GetUserWithId(backchannel.UserId())
	if err != nil {
		r.JSON(403, "Could not find a user with your credentials.")
		return
	}

	_, err = db.ToggleHeart(user.Id, im.Id)
	if err != nil {
		log.Println("Error toggling heart:", err.Error())
		r.JSON(500, "Sorry, an internal server error has occurred.")
	}

	im, err = db.GetIMWithId(heart.IRLMojiId)
	if err != nil {
		log.Println("Error getting IRLMoji after toggling heart:", err.Error())
		r.JSON(500, "Sorry, an internal server error has occurred.")
		return
	}

	err = db.AnnotateHearted(im, user.Id)
	if err != nil {
		log.Println("Error annotating hearted info:", err.Error())
		r.JSON(500, "Sorry, an internal server error has occurred.")
		return
	}

	r.JSON(200, map[string]*models.IRLMoji{"irlmoji": im})
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:45,代码来源:handlers_irlmoji.go

示例4: HandleDeleteIRLMoji

func HandleDeleteIRLMoji(r render.Render, db *models.DB, params martini.Params, backchannel Backchannel) {
	if backchannel.UserId() == "" {
		r.JSON(403, JsonErr("The provided credentials were invalid."))
		return
	}

	user, err := db.GetUserWithId(backchannel.UserId())
	if err != nil {
		r.JSON(403, "Could not find a user with your credentials.")
		return
	}

	irlmojiId, err := strconv.ParseUint(params["irlmojiId"], 10, 64)
	if err != nil {
		r.JSON(404, JsonErr("Invalid IRLMoji id provided:"+
			params["irlmojiId"]))
	}

	im, err := db.GetIMWithId(irlmojiId)
	if err != nil {
		r.JSON(404, JsonErr("The provided IRLMoji id was invalid."))
		return
	}

	if im.UserId != user.Id && !user.IsAdmin {
		r.JSON(403, "You are not allowed to delete that IRLMoji.")
		return
	}

	err = db.DeleteIMWithId(im.Id)
	if err != nil {
		log.Println("Error deleting IRLMoji:", err.Error())
		r.JSON(500, JsonErr("There was an error deleting that IRLMoji."))
	}
	r.JSON(200, map[string]string{"status": "ok"})
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:36,代码来源:handlers_irlmoji.go

示例5: HandleCreateUserByTwitter

func HandleCreateUserByTwitter(r render.Render, bindErr binding.Errors, userForm models.UserForm, db *models.DB) {
	if bindErr.Count() > 0 {
		r.JSON(400, JsonErrBinding(bindErr))
		return
	}

	// Build Twitter client
	config := &oauth1a.ClientConfig{
		ConsumerKey:    TWITTER_CONSUMER_KEY,
		ConsumerSecret: TWITTER_CONSUMER_SECRET,
	}
	oauthUser := oauth1a.NewAuthorizedConfig(userForm.TwitterAccessToken,
		userForm.TwitterAccessSecret)
	client := twittergo.NewClient(config, oauthUser)

	// Build request to send to Twitter
	req, err := http.NewRequest("GET", "/1.1/account/verify_credentials.json", nil)
	if err != nil {
		log.Println("Could not build request for Twitter:", err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
	}

	// Send it
	resp, err := client.SendRequest(req)
	if err != nil {
		log.Println("Error sending request to Twitter:", err.Error())
		r.JSON(504, JsonErr("Could not communicate properly with Twitter, "+
			"please try again soon."))
		return
	}

	// Parse the response
	var result = &twittergo.User{}
	if err = resp.Parse(result); err != nil {
		log.Println("Error parsing Twitter result:", err.Error(), "Response:",
			resp)
		r.JSON(504, JsonErr("Got a bad response from Twitter, please try "+
			"again soon."))
		return
	}

	user, err := db.GetUserWithId(result.IdStr())
	if err == nil {
		user, err = db.UpdateUserAuth(user.Id, userForm.TwitterAccessToken,
			userForm.TwitterAccessSecret)
		if err != nil {
			log.Println("Error updating user auth:", err.Error())
			r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
			return
		}
		r.JSON(200, map[string]*models.User{"user": user})
		return
	}

	// Now let's create that user, shall we?
	user, err = db.CreateUser(
		result.IdStr(),
		result.ScreenName(),
		(*result)["profile_image_url"].(string),
		userForm.TwitterAccessToken,
		userForm.TwitterAccessSecret,
	)
	if err != nil {
		log.Println("Error creating user:", err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
		return
	}

	r.JSON(200, map[string]*models.User{"user": user})
}
开发者ID:AndrewJHart,项目名称:irlmoji,代码行数:70,代码来源:handlers_user.go


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