當前位置: 首頁>>代碼示例>>Golang>>正文


Golang DB.AnnotateHearted方法代碼示例

本文整理匯總了Golang中github.com/ericflo/irlmoji/src/models.DB.AnnotateHearted方法的典型用法代碼示例。如果您正苦於以下問題:Golang DB.AnnotateHearted方法的具體用法?Golang DB.AnnotateHearted怎麽用?Golang DB.AnnotateHearted使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在github.com/ericflo/irlmoji/src/models.DB的用法示例。


在下文中一共展示了DB.AnnotateHearted方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: HandleGetUserTimeline

func HandleGetUserTimeline(r render.Render, limit Limit, params martini.Params, db *models.DB, backchannel Backchannel) {
	user, err := db.GetUserWithUsername(params["username"])
	if err != nil {
		r.JSON(404, JsonErr("Username '"+params["username"]+"' not found."))
		return
	}
	timeline, err := db.GetIMsForUser(user.Id, limit.GetLimit()+uint32(1))
	if err != nil {
		log.Println("Error getting IMs for user", user.Username, err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
		return
	}
	for _, im := range timeline {
		err = db.AnnotateHearted(im, backchannel.UserId())
		if err != nil {
			log.Println("Error annotating hearted info:", err.Error())
			r.JSON(500, "Sorry, an internal server error has occurred.")
			return
		}
	}
	hasMore, timeline := hasMoreTimeline(limit, timeline)
	r.JSON(200, map[string]interface{}{
		"timeline": timeline,
		"hasMore":  hasMore,
	})
}
開發者ID:AndrewJHart,項目名稱:irlmoji,代碼行數:26,代碼來源:handlers_irlmoji.go

示例2: HandleGetIRLMoji

func HandleGetIRLMoji(r render.Render, db *models.DB, params martini.Params, backchannel Backchannel, limit Limit) {
	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:"+
			params["irlmojiId"]))
		return
	}
	hearts, err := db.GetHeartsForIRLMoji(irlmojiId, limit.GetLimit())
	if err == nil {
		im.Hearts = hearts
	} else {
		log.Println("WARNING: Could not get IRLMoji hearts:", err.Error())
	}
	err = db.AnnotateHearted(im, backchannel.UserId())
	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,代碼行數:26,代碼來源:handlers_irlmoji.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: HandleGetHomeTimeline

func HandleGetHomeTimeline(r render.Render, limit Limit, db *models.DB, backchannel Backchannel) {
	timeline, err := db.GetAllIMs(limit.GetLimit() + uint32(1))
	if err != nil {
		r.JSON(500, JsonErr("Internal error: "+err.Error()))
		return
	}
	for _, im := range timeline {
		err = db.AnnotateHearted(im, backchannel.UserId())
		if err != nil {
			log.Println("Error annotating hearted info:", err.Error())
			r.JSON(500, "Sorry, an internal server error has occurred.")
			return
		}
	}
	hasMore, timeline := hasMoreTimeline(limit, timeline)
	r.JSON(200, map[string]interface{}{
		"timeline": timeline,
		"hasMore":  hasMore,
	})
}
開發者ID:AndrewJHart,項目名稱:irlmoji,代碼行數:20,代碼來源:handlers_irlmoji.go

示例5: HandleGetEmojiTimeline

func HandleGetEmojiTimeline(r render.Render, limit Limit, params martini.Params, db *models.DB, backchannel Backchannel) {
	timeline, err := db.GetIMsForEmoji(params["emoji"], limit.GetLimit()+uint32(1))
	if err != nil {
		log.Println("Error getting IMs for emoji", params["emoji"], err.Error())
		r.JSON(500, JsonErr("Sorry, an internal server error has occurred."))
		return
	}
	for _, im := range timeline {
		err = db.AnnotateHearted(im, backchannel.UserId())
		if err != nil {
			log.Println("Error annotating hearted info:", err.Error())
			r.JSON(500, "Sorry, an internal server error has occurred.")
			return
		}
	}
	hasMore, timeline := hasMoreTimeline(limit, timeline)
	r.JSON(200, map[string]interface{}{
		"timeline": timeline,
		"hasMore":  hasMore,
	})
}
開發者ID:AndrewJHart,項目名稱:irlmoji,代碼行數:21,代碼來源:handlers_irlmoji.go


注:本文中的github.com/ericflo/irlmoji/src/models.DB.AnnotateHearted方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。