本文整理匯總了Golang中github.com/varding/wetalk/modules/models.Post.IsBest方法的典型用法代碼示例。如果您正苦於以下問題:Golang Post.IsBest方法的具體用法?Golang Post.IsBest怎麽用?Golang Post.IsBest使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/varding/wetalk/modules/models.Post
的用法示例。
在下文中一共展示了Post.IsBest方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: Post
func (this *ApiRouter) Post() {
if this.CheckActiveRedirect() {
return
}
if this.IsAjax() {
result := map[string]interface{}{
"success": false,
}
action := this.GetString("action")
switch action {
case "toggle-best":
if !this.User.IsAdmin {
result["success"] = false
} else {
if postId, err := this.GetInt("post"); err == nil {
//set post best
var post models.Post
if err := orm.NewOrm().QueryTable("post").Filter("Id", postId).One(&post); err == nil {
post.IsBest = !post.IsBest
if post.Update("IsBest") == nil {
result["success"] = true
}
}
}
}
case "toggle-fav":
if postId, err := this.GetInt("post"); err == nil {
var post models.Post
if err := orm.NewOrm().QueryTable("post").Filter("Id", postId).One(&post); err == nil {
if post.Id != 0 {
var favoritePost models.FavoritePost
if this.User.FavoritePosts().Filter("Post__id", post.Id).One(&favoritePost); err == nil {
if favoritePost.Id > 0 {
//toogle IsFav
favoritePost.IsFav = !favoritePost.IsFav
if favoritePost.Update("IsFav") == nil {
//update user fav post count
if favoritePost.IsFav {
this.User.FavPosts += 1
} else {
this.User.FavPosts -= 1
}
if this.User.Update("FavPosts") == nil {
result["success"] = true
}
}
} else {
favoritePost = models.FavoritePost{
User: &this.User,
Post: &post,
IsFav: true,
}
if favoritePost.Insert() == nil {
//update user fav post count
this.User.FavPosts += 1
if this.User.Update("FavPosts") == nil {
result["success"] = true
}
}
}
}
}
}
}
}
this.Data["json"] = result
this.ServeJson()
}
}