From 8d99ff1070f1532cc4b4f41f7a22f1b86e300b43 Mon Sep 17 00:00:00 2001 From: Howl Date: Thu, 7 Apr 2016 14:42:17 +0200 Subject: [PATCH] add a method for retrieving an user's userpage. --- app/start.go | 1 + app/v1/user.go | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/app/start.go b/app/start.go index c41e4e4..496c2ba 100644 --- a/app/start.go +++ b/app/start.go @@ -31,6 +31,7 @@ func Start(conf common.Conf, db *sql.DB) { gv1.GET("/users/self", Method(v1.UserSelfGET, db, common.PrivilegeRead)) gv1.GET("/users/whatid/:username", Method(v1.UserWhatsTheIDGET, db, common.PrivilegeRead)) gv1.GET("/users/full/:id", Method(v1.UserFullGET, db, common.PrivilegeRead)) + gv1.GET("/users/userpage/:id", Method(v1.UserUserpageGET, db, common.PrivilegeRead)) gv1.GET("/badges", Method(v1.BadgesGET, db, common.PrivilegeRead)) gv1.GET("/badges/:id", Method(v1.BadgeByIDGET, db, common.PrivilegeRead)) diff --git a/app/v1/user.go b/app/v1/user.go index 2c8000e..88a3203 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -268,3 +268,21 @@ LIMIT 1 r.Data = fd return } + +// UserUserpageGET gets an user's userpage, as in the customisable thing. +func UserUserpageGET(md common.MethodData) (r common.Response) { + var userpage string + err := md.DB.QueryRow("SELECT userpage_content FROM users_stats WHERE id = ? LIMIT 1", md.C.Param("id")).Scan(&userpage) + switch { + case err == sql.ErrNoRows: + r.Code = 404 + r.Message = "No user with that user ID!" + case err != nil: + md.C.Error(err) + r = Err500 + return + } + r.Code = 200 + r.Data = userpage + return +}