码农笔录博客源码
Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

57 linhas
1.4 KiB

há 6 anos
package controllers
import (
"beeblog/models"
há 3 anos
"beeblog/service"
beego "github.com/beego/beego/v2/server/web"
"strconv"
há 6 anos
)
type LikeController struct {
beego.Controller
}
func (this *LikeController) Save() {
há 5 anos
likeService := service.LikeService{}
userService := service.UserService{}
há 6 anos
uid := this.GetSession("userid")
if uid == nil {
this.Data["json"] = models.ReurnError(401, "")
this.ServeJSON()
return
}
idStr := this.Ctx.Input.Param(":id")
id, _ := strconv.ParseInt(idStr, 10, 64)
like := &models.Like{BlogId: id, UserId: uid.(int64)}
há 5 anos
if _, err := likeService.SaveLike(like); err != nil {
há 6 anos
this.Data["json"] = models.ReurnError(500, "保存失败")
há 3 anos
} else {
há 6 anos
this.Data["json"] = models.ReurnSuccess("")
}
this.ServeJSON()
há 3 anos
userService.CountLike(uid.(int64), id)
há 6 anos
return
}
func (this *LikeController) Delete() {
há 5 anos
likeService := service.LikeService{}
userService := service.UserService{}
há 6 anos
uid := this.GetSession("userid")
if uid == nil {
this.Data["json"] = models.ReurnError(401, "")
this.ServeJSON()
return
}
idStr := this.Ctx.Input.Param(":id")
id, _ := strconv.ParseInt(idStr, 10, 64)
like := &models.Like{BlogId: id, UserId: uid.(int64)}
há 5 anos
if _, err := likeService.DelLike(like); err != nil {
há 6 anos
this.Data["json"] = models.ReurnError(500, "保存失败")
há 3 anos
} else {
há 6 anos
this.Data["json"] = models.ReurnSuccess("")
}
this.ServeJSON()
há 3 anos
userService.CountLike(uid.(int64), id)
há 6 anos
return
}