Second P1 growth engine: compare two profiles, gate full tips behind deep-access mock payment, and list personal archives on /profile. Co-authored-by: Cursor <cursoragent@cursor.com>
56 lines
1.5 KiB
Go
56 lines
1.5 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/google/uuid"
|
|
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/middleware"
|
|
"github.com/yuxingu/digital-psychology/apps/api/internal/service/relation"
|
|
"github.com/yuxingu/digital-psychology/apps/api/pkg/response"
|
|
)
|
|
|
|
// RelationHandler exposes 关系理解 APIs.
|
|
type RelationHandler struct {
|
|
Svc *relation.Service
|
|
}
|
|
|
|
// Register mounts routes.
|
|
func (h *RelationHandler) Register(rg *gin.RouterGroup) {
|
|
rg.POST("/relation/insight", h.Create)
|
|
}
|
|
|
|
// Create handles POST /relation/insight.
|
|
func (h *RelationHandler) Create(c *gin.Context) {
|
|
userID, ok := middleware.UserIDFromContext(c)
|
|
if !ok {
|
|
response.Fail(c, http.StatusUnauthorized, 40100, "unauthorized")
|
|
return
|
|
}
|
|
var req struct {
|
|
ProfileAID string `json:"profile_a_id" binding:"required"`
|
|
ProfileBID string `json:"profile_b_id" binding:"required"`
|
|
}
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 10000, "invalid request")
|
|
return
|
|
}
|
|
aID, err := uuid.Parse(req.ProfileAID)
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 10000, "invalid profile_a_id")
|
|
return
|
|
}
|
|
bID, err := uuid.Parse(req.ProfileBID)
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 10000, "invalid profile_b_id")
|
|
return
|
|
}
|
|
out, err := h.Svc.Create(c.Request.Context(), userID, aID, bID)
|
|
if err != nil {
|
|
response.Fail(c, http.StatusBadRequest, 30005, err.Error())
|
|
return
|
|
}
|
|
response.OK(c, out)
|
|
}
|