package handler import ( "encoding/json" "errors" "net/http" "soul-api/internal/database" "soul-api/internal/model" "github.com/gin-gonic/gin" "gorm.io/gorm" ) // MiniprogramMbtiAvatarsGet GET /api/miniprogram/config/mbti-avatars // 公开只读:返回 16 型 MBTI → 头像 URL,供小程序在无用户头像时按性格展示(推广海报等)。 func MiniprogramMbtiAvatarsGet(c *gin.Context) { db := database.DB() var row model.SystemConfig err := db.Where("config_key = ?", mbtiAvatarsConfigKey).First(&row).Error if err != nil { if errors.Is(err, gorm.ErrRecordNotFound) { c.JSON(http.StatusOK, gin.H{"success": true, "avatars": map[string]string{}}) return } c.JSON(http.StatusOK, gin.H{"success": false, "error": "读取失败"}) return } out := make(map[string]string) if len(row.ConfigValue) > 0 { if uerr := json.Unmarshal(row.ConfigValue, &out); uerr != nil { c.JSON(http.StatusOK, gin.H{"success": false, "error": "配置无效"}) return } } c.JSON(http.StatusOK, gin.H{"success": true, "avatars": out}) }