一方关注只记关注。双方互关时写入已有双向好友边;取消关注若不再互关只删好友边,不删消息。 Co-authored-by: Cursor <cursoragent@cursor.com>
62 lines
1.1 KiB
Go
62 lines
1.1 KiB
Go
package friendhandler
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"spark-server/internal/transport/http/respond"
|
|
)
|
|
|
|
func (h *Handler) GetFollow(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
targetID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
out, err := h.friends.GetFollow(c.Request.Context(), uid, targetID)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, out)
|
|
}
|
|
|
|
func (h *Handler) Follow(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
targetID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
out, err := h.friends.Follow(c.Request.Context(), uid, targetID)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, out)
|
|
}
|
|
|
|
func (h *Handler) Unfollow(c *gin.Context) {
|
|
uid, ok := currentUID(c)
|
|
if !ok {
|
|
return
|
|
}
|
|
targetID, err := pathUID(c)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
out, err := h.friends.Unfollow(c.Request.Context(), uid, targetID)
|
|
if err != nil {
|
|
respond.JSONError(c, err)
|
|
return
|
|
}
|
|
respond.JSON(c, out)
|
|
}
|