feat: add RelationInsight API and wire H5 relation/profile pages

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>
This commit is contained in:
jackyu66git
2026-08-02 16:28:10 +08:00
co-authored by Cursor
parent 0f320e040b
commit 14b836f53b
12 changed files with 465 additions and 14 deletions
+55
View File
@@ -0,0 +1,55 @@
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)
}