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

@ -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/id/:id", Method(v1.UserByIDGET, db, common.PrivilegeRead))
gv1.GET("/users/name/:name", Method(v1.UserByNameGET, 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/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", Method(v1.BadgesGET, db, common.PrivilegeRead))
gv1.GET("/badges/:id", Method(v1.BadgeByIDGET, db, common.PrivilegeRead)) gv1.GET("/badges/:id", Method(v1.BadgeByIDGET, db, common.PrivilegeRead))

View File

@ -123,3 +123,22 @@ func UserSelfGET(md common.MethodData) common.Response {
}) })
return UserByIDGET(md) 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,
}
}