Getters for display name and avatar URL

This commit is contained in:
Brendan Abolivier 2017-07-07 11:34:34 +01:00
parent 2ca6b914bd
commit a765352d16
No known key found for this signature in database
GPG key ID: 8EF1500759F70623

View file

@ -31,11 +31,11 @@ type profileResponse struct {
DisplayName string `json:"displayname"` DisplayName string `json:"displayname"`
} }
type avatarURLRequest struct { type avatarURL struct {
AvatarURL string `json:"avatar_url"` AvatarURL string `json:"avatar_url"`
} }
type displayNameRequest struct { type displayName struct {
DisplayName string `json:"displayname"` DisplayName string `json:"displayname"`
} }
@ -69,8 +69,24 @@ func GetProfile(
func AvatarURL( func AvatarURL(
req *http.Request, accountDB *accounts.Database, userID string, req *http.Request, accountDB *accounts.Database, userID string,
) util.JSONResponse { ) util.JSONResponse {
if req.Method == "PUT" { if req.Method == "GET" {
var r avatarURLRequest localpart := getLocalPart(userID)
profile, err := accountDB.GetProfileByLocalpart(localpart)
if err == nil {
res := avatarURL{
AvatarURL: profile.AvatarURL,
}
return util.JSONResponse{
Code: 200,
JSON: res,
}
}
return util.JSONResponse{
Code: 500,
JSON: jsonerror.Unknown("Failed to load avatar URL"),
}
} else if req.Method == "PUT" {
var r avatarURL
if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
return *resErr return *resErr
} }
@ -102,8 +118,24 @@ func AvatarURL(
func DisplayName( func DisplayName(
req *http.Request, accountDB *accounts.Database, userID string, req *http.Request, accountDB *accounts.Database, userID string,
) util.JSONResponse { ) util.JSONResponse {
if req.Method == "PUT" { if req.Method == "GET" {
var r displayNameRequest localpart := getLocalPart(userID)
profile, err := accountDB.GetProfileByLocalpart(localpart)
if err == nil {
res := displayName{
DisplayName: profile.DisplayName,
}
return util.JSONResponse{
Code: 200,
JSON: res,
}
}
return util.JSONResponse{
Code: 500,
JSON: jsonerror.Unknown("Failed to load display name"),
}
} else if req.Method == "PUT" {
var r displayName
if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil { if resErr := httputil.UnmarshalJSONRequest(req, &r); resErr != nil {
return *resErr return *resErr
} }