(c *gin.Context)
| 763 | } |
| 764 | |
| 765 | func UpdateSelf(c *gin.Context) { |
| 766 | var requestData map[string]interface{} |
| 767 | if err := common.DecodeJson(c.Request.Body, &requestData); err != nil { |
| 768 | common.ApiErrorI18n(c, i18n.MsgInvalidParams) |
| 769 | return |
| 770 | } |
| 771 | |
| 772 | // 检查是否是用户设置更新请求 (sidebar_modules 或 language) |
| 773 | if sidebarModules, sidebarExists := requestData["sidebar_modules"]; sidebarExists { |
| 774 | userId := c.GetInt("id") |
| 775 | user, err := model.GetUserById(userId, false) |
| 776 | if err != nil { |
| 777 | common.ApiError(c, err) |
| 778 | return |
| 779 | } |
| 780 | |
| 781 | // 获取当前用户设置 |
| 782 | currentSetting := user.GetSetting() |
| 783 | |
| 784 | // 更新sidebar_modules字段 |
| 785 | if sidebarModulesStr, ok := sidebarModules.(string); ok { |
| 786 | currentSetting.SidebarModules = sidebarModulesStr |
| 787 | } |
| 788 | |
| 789 | if err := model.UpdateUserSetting(user.Id, currentSetting); err != nil { |
| 790 | common.ApiErrorI18n(c, i18n.MsgUpdateFailed) |
| 791 | return |
| 792 | } |
| 793 | |
| 794 | common.ApiSuccessI18n(c, i18n.MsgUpdateSuccess, nil) |
| 795 | return |
| 796 | } |
| 797 | |
| 798 | // 检查是否是语言偏好更新请求 |
| 799 | if language, langExists := requestData["language"]; langExists { |
| 800 | userId := c.GetInt("id") |
| 801 | user, err := model.GetUserById(userId, false) |
| 802 | if err != nil { |
| 803 | common.ApiError(c, err) |
| 804 | return |
| 805 | } |
| 806 | |
| 807 | // 获取当前用户设置 |
| 808 | currentSetting := user.GetSetting() |
| 809 | |
| 810 | // 更新language字段 |
| 811 | if langStr, ok := language.(string); ok { |
| 812 | currentSetting.Language = langStr |
| 813 | } |
| 814 | |
| 815 | if err := model.UpdateUserSetting(user.Id, currentSetting); err != nil { |
| 816 | common.ApiErrorI18n(c, i18n.MsgUpdateFailed) |
| 817 | return |
| 818 | } |
| 819 | |
| 820 | common.ApiSuccessI18n(c, i18n.MsgUpdateSuccess, nil) |
| 821 | return |
| 822 | } |
nothing calls this directly
no test coverage detected