Add /users/whatid/:username

This commit is contained in:
Howl
2016-04-07 11:59:38 +02:00
parent d84aafebb7
commit cf3b30d851
2 changed files with 20 additions and 0 deletions

View File

@@ -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,
}
}