From 1c2201317f3a29864cd30169f7ed2dda31474aca Mon Sep 17 00:00:00 2001 From: Howl Date: Mon, 7 Nov 2016 18:34:53 +0100 Subject: [PATCH] Add POST users/self/userpage --- app/start.go | 1 + app/v1/user.go | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/app/start.go b/app/start.go index d34a5cd..b657ab8 100644 --- a/app/start.go +++ b/app/start.go @@ -118,6 +118,7 @@ func Start(conf common.Conf, dbO *sqlx.DB) *gin.Engine { gv1.GET("/friends/add", Method(v1.FriendsAddGET, common.PrivilegeWrite)) gv1.GET("/friends/del", Method(v1.FriendsDelGET, common.PrivilegeWrite)) gv1.POST("/users/self/settings", Method(v1.UsersSelfSettingsPOST, common.PrivilegeWrite)) + gv1.POST("/users/self/userpage", Method(v1.UserSelfUserpagePOST, common.PrivilegeWrite)) //gv1.POST("/beatmaps/rank_requests", Method(v1.BeatmapRankRequestsSubmitPOST, common.PrivilegeWrite)) // Admin: beatmap diff --git a/app/v1/user.go b/app/v1/user.go index 3a570fb..806f3d7 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -333,6 +333,23 @@ func UserUserpageGET(md common.MethodData) common.CodeMessager { return r } +// UserSelfUserpagePOST allows to change the current user's userpage. +func UserSelfUserpagePOST(md common.MethodData) common.CodeMessager { + var d struct { + Data *string `json:"data"` + } + md.RequestData.Unmarshal(&d) + if d.Data == nil { + return ErrMissingField("data") + } + _, err := md.DB.Exec("UPDATE users_stats SET userpage_content = ? WHERE id = ? LIMIT 1", *d.Data, md.ID()) + if err != nil { + md.Err(err) + } + md.C.Request.URL.RawQuery += "&id=" + strconv.Itoa(md.ID()) + return UserUserpageGET(md) +} + func whereClauseUser(md common.MethodData, tableName string) (*common.CodeMessager, string, interface{}) { switch { case md.Query("id") == "self":