MCPcopy Create free account
hub / github.com/GoSimplicity/LinkMe / Like

Method Like

internal/api/post.go:258–284  ·  view source on GitHub ↗

Like 点赞/取消点赞

(ctx *gin.Context)

Source from the content-addressed store, hash-verified

256
257// Like 点赞/取消点赞
258func (ph *PostHandler) Like(ctx *gin.Context) {
259 var req req.LikeReq
260 if err := ctx.ShouldBindJSON(&req); err != nil {
261 apiresponse.ErrorWithMessage(ctx, "无效的请求参数")
262 return
263 }
264
265 uc, ok := requireUser(ctx)
266 if !ok {
267 return
268 }
269
270 var err error
271
272 if req.Liked {
273 err = ph.intSvc.Like(ctx, req.PostId, uc.Uid)
274 } else {
275 err = ph.intSvc.CancelLike(ctx, req.PostId, uc.Uid)
276 }
277
278 if err != nil {
279 apiresponse.ErrorWithMessage(ctx, err.Error())
280 return
281 }
282
283 apiresponse.SuccessWithData(ctx, req.PostId)
284}
285
286// Collect 收藏/取消收藏
287func (ph *PostHandler) Collect(ctx *gin.Context) {

Callers

nothing calls this directly

Calls 5

ErrorWithMessageFunction · 0.92
SuccessWithDataFunction · 0.92
requireUserFunction · 0.85
LikeMethod · 0.65
CancelLikeMethod · 0.65

Tested by

no test coverage detected