From cf3b30d8512aa2497fa43f271f35fb225e01ba59 Mon Sep 17 00:00:00 2001 From: Howl Date: Thu, 7 Apr 2016 11:59:38 +0200 Subject: [PATCH] Add /users/whatid/:username --- app/start.go | 1 + app/v1/user.go | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/app/start.go b/app/start.go index c3e958d..11b7112 100644 --- a/app/start.go +++ b/app/start.go @@ -29,6 +29,7 @@ func Start(conf common.Conf, db *sql.DB) { gv1.GET("/users/id/:id", Method(v1.UserByIDGET, db, common.PrivilegeRead)) gv1.GET("/users/name/:name", Method(v1.UserByNameGET, db, common.PrivilegeRead)) gv1.GET("/users/self", Method(v1.UserSelfGET, db, common.PrivilegeRead)) + gv1.GET("/users/whatid/:username", Method(v1.UserWhatsTheIDGET, 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 527ac61..ddee2b6 100644 --- a/app/v1/user.go +++ b/app/v1/user.go @@ -123,3 +123,22 @@ func UserSelfGET(md common.MethodData) common.Response { }) return UserByIDGET(md) } + +// UserWhatsTheIDGET is an API request that only returns an user's ID. +func UserWhatsTheIDGET(md common.MethodData) common.Response { + var ( + id int + allowed int + ) + err := md.DB.QueryRow("SELECT id, allowed FROM users WHERE username = ?", md.C.Param("username")).Scan(&id, &allowed) + if err != nil || allowed != 1 { + return common.Response{ + Code: 404, + Message: "That user could not be found!", + } + } + return common.Response{ + Code: 200, + Data: id, + } +}