Add API handler for /users/self

This commit is contained in:
Howl 2016-04-05 22:38:33 +02:00
parent d02f3f9951
commit b484fe2761
No known key found for this signature in database
GPG Key ID: 40D328300D245DA5
2 changed files with 11 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func Start(conf common.Conf, db *sql.DB) {
// Read privilege required // Read privilege required
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("/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

@ -8,6 +8,7 @@ import (
"strings" "strings"
"time" "time"
"github.com/gin-gonic/gin"
"github.com/osuripple/api/common" "github.com/osuripple/api/common"
) )
@ -113,3 +114,12 @@ func userPuts(md common.MethodData, row *sql.Row) (r common.Response) {
r.Data = user r.Data = user
return return
} }
// UserSelfGET is a shortcut for /users/id/self. (/users/self)
func UserSelfGET(md common.MethodData) common.Response {
md.C.Params = append(md.C.Params, gin.Param{
Key: "id",
Value: "self",
})
return UserByIDGET(md)
}