码农笔录博客源码
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 line
1.4 KiB

6 年之前
package controllers
import (
"beeblog/models"
3 年之前
"beeblog/service"
beego "github.com/beego/beego/v2/server/web"
"strconv"
6 年之前
)
type LikeController struct {
beego.Controller
}
func (this *LikeController) Save() {
5 年之前
likeService := service.LikeService{}
userService := service.UserService{}
6 年之前
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)}
5 年之前
if _, err := likeService.SaveLike(like); err != nil {
6 年之前
this.Data["json"] = models.ReurnError(500, "保存失败")
3 年之前
} else {
6 年之前
this.Data["json"] = models.ReurnSuccess("")
}
this.ServeJSON()
3 年之前
userService.CountLike(uid.(int64), id)
6 年之前
return
}
func (this *LikeController) Delete() {
5 年之前
likeService := service.LikeService{}
userService := service.UserService{}
6 年之前
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)}
5 年之前
if _, err := likeService.DelLike(like); err != nil {
6 年之前
this.Data["json"] = models.ReurnError(500, "保存失败")
3 年之前
} else {
6 年之前
this.Data["json"] = models.ReurnSuccess("")
}
this.ServeJSON()
3 年之前
userService.CountLike(uid.(int64), id)
6 年之前
return
}