spark-server/internal/transport/http/handler/user/handler.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

53 lines
1.2 KiB
Go

package userhandler
import (
"github.com/gin-gonic/gin"
userlogic "spark-server/internal/module/user/logic"
"spark-server/internal/pkg/errs"
"spark-server/internal/pkg/reqctx"
"spark-server/internal/transport/http/respond"
)
// Handler is the users HTTP controller.
type Handler struct {
users *userlogic.Service
}
func New(users *userlogic.Service) *Handler {
return &Handler{users: users}
}
func (h *Handler) Me(c *gin.Context) {
rc := reqctx.From(c.Request.Context())
if rc == nil || rc.UserID <= 0 {
respond.JSONError(c, errs.ErrUnauthorized)
return
}
u, err := h.users.Get(c.Request.Context(), rc.UserID)
if err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, userlogic.PublicProfile(u))
}
func (h *Handler) PatchMe(c *gin.Context) {
rc := reqctx.From(c.Request.Context())
if rc == nil || rc.UserID <= 0 {
respond.JSONError(c, errs.ErrUnauthorized)
return
}
var in userlogic.UpdateProfileInput
if err := respond.BindJSON(c, &in); err != nil {
respond.JSONError(c, err)
return
}
u, err := h.users.UpdateProfile(c.Request.Context(), rc.UserID, in)
if err != nil {
respond.JSONError(c, err)
return
}
respond.JSON(c, userlogic.PublicProfile(u))
}