39 lines
925 B
Go
39 lines
925 B
Go
|
package post
|
|||
|
|
|||
|
import (
|
|||
|
"fmt"
|
|||
|
"mini_server/internal/dao"
|
|||
|
"mini_server/internal/server/help"
|
|||
|
"mini_server/internal/server/httpreply"
|
|||
|
"net/http"
|
|||
|
|
|||
|
"github.com/gin-gonic/gin"
|
|||
|
"github.com/sirupsen/logrus"
|
|||
|
)
|
|||
|
|
|||
|
func UnLike(c *gin.Context) {
|
|||
|
reply := httpreply.NewDefaultReplyData()
|
|||
|
defer httpreply.Reply(c, reply)
|
|||
|
|
|||
|
userId, ok := help.GetUserId(c)
|
|||
|
if !ok {
|
|||
|
reply.Status = http.StatusNotFound
|
|||
|
reply.Message = "无法获取用户信息"
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
var param QueryURI
|
|||
|
if err := c.ShouldBindUri(¶m); err != nil {
|
|||
|
reply.Status = http.StatusBadRequest
|
|||
|
reply.Message = fmt.Sprintf("invalid uri path,err:%v", err)
|
|||
|
return
|
|||
|
}
|
|||
|
|
|||
|
if err := dao.PostLike_UnLike(userId, param.PostId); err != nil {
|
|||
|
logrus.Errorf("贴子取消点赞删除数据库异常,userId:%d,postId:%d,err:%v", userId, param.PostId, err)
|
|||
|
reply.Status = http.StatusInternalServerError
|
|||
|
reply.Message = "贴子取消点赞异常"
|
|||
|
return
|
|||
|
}
|
|||
|
}
|