MCPcopy Create free account
hub / github.com/53AI/53AIHub / ToggleLike

Method ToggleLike

api/model/like.go:135–156  ·  view source on GitHub ↗

ToggleLike 点赞/取消点赞

()

Source from the content-addressed store, hash-verified

133
134// ToggleLike 点赞/取消点赞
135func (l *Like) ToggleLike() error {
136 exists, err := l.Exists()
137 if err != nil {
138 return err
139 }
140
141 if exists {
142 // 存在则更新状态(取消点赞)
143 currentLike, err := GetLikeByUserObject(l.UserID, l.Type, l.ObjectID)
144 if err != nil {
145 return err
146 }
147 newStatus := LikeStatusCancel
148 if currentLike.Status == LikeStatusCancel {
149 newStatus = LikeStatusActive
150 }
151 return currentLike.UpdateStatus(newStatus)
152 }
153
154 // 不存在则创建新记录
155 return l.Create()
156}
157
158// GetLikeByUserObject 根据用户和对象获取点赞记录
159func GetLikeByUserObject(userID int64, objectType string, objectID int64) (*Like, error) {

Callers

nothing calls this directly

Calls 4

ExistsMethod · 0.95
CreateMethod · 0.95
GetLikeByUserObjectFunction · 0.85
UpdateStatusMethod · 0.45

Tested by

no test coverage detected