spark-server/internal/transport/http/handler/group/member.go
zhr ae9a71034d feat: implement Spark IM V3 modular monolith
Add HTTP /v1 MVC, TCP send path, groups with server-side member-avatar collage, object-storage upload, and friends/favorites around the architecture-v3 layout.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-09-17 19:52:11 +08:00

135 lines
2.5 KiB
Go

package grouphandler
import (
"strconv"
"github.com/gin-gonic/gin"
grouplogic "spark-server/internal/module/group/logic"
"spark-server/internal/pkg/errs"
"spark-server/internal/transport/http/respond"
)
func (h *Handler) ListMembers(c *gin.Context) {
uid, ok := currentUID(c)
if !ok {
return
}
id, err := pathID(c)
if err != nil {
respond.JSONError(c, err)
return
}
limit, _ := strconv.Atoi(c.Query("limit"))
out, err := h.groups.ListMembers(c.Request.Context(), uid, id, limit)
if err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, out)
}
func (h *Handler) Invite(c *gin.Context) {
uid, ok := currentUID(c)
if !ok {
return
}
id, err := pathID(c)
if err != nil {
respond.JSONError(c, err)
return
}
var in grouplogic.InviteInput
if err := respond.BindJSON(c, &in); err != nil {
respond.JSONError(c, err)
return
}
out, err := h.groups.Invite(c.Request.Context(), uid, id, &in)
if err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, out)
}
func (h *Handler) RemoveMember(c *gin.Context) {
uid, ok := currentUID(c)
if !ok {
return
}
id, err := pathID(c)
if err != nil {
respond.JSONError(c, err)
return
}
target, err := pathUID(c)
if err != nil {
respond.JSONError(c, err)
return
}
if err := h.groups.RemoveMember(c.Request.Context(), uid, id, target); err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, gin.H{})
}
func (h *Handler) UpdateMember(c *gin.Context) {
uid, ok := currentUID(c)
if !ok {
return
}
id, err := pathID(c)
if err != nil {
respond.JSONError(c, err)
return
}
target, err := pathUID(c)
if err != nil {
respond.JSONError(c, err)
return
}
var in grouplogic.UpdateMemberInput
if err := respond.BindJSON(c, &in); err != nil {
respond.JSONError(c, err)
return
}
out, err := h.groups.UpdateMember(c.Request.Context(), uid, id, target, &in)
if err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, out)
}
func (h *Handler) Transfer(c *gin.Context) {
uid, ok := currentUID(c)
if !ok {
return
}
id, err := pathID(c)
if err != nil {
respond.JSONError(c, err)
return
}
var in grouplogic.TransferInput
if err := respond.BindJSON(c, &in); err != nil {
respond.JSONError(c, err)
return
}
out, err := h.groups.Transfer(c.Request.Context(), uid, id, &in)
if err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, out)
}
func pathUID(c *gin.Context) (int64, error) {
id, err := strconv.ParseInt(c.Param("uid"), 10, 64)
if err != nil || id <= 0 {
return 0, errs.ErrInvalidArgument
}
return id, nil
}