Handle no avatar, add delete avatar support
This commit is contained in:
1 parent
35bff424f1
commit
3864a4c1cc
9 files changed
+110
-11
No files matched your search
@@ -20,7 +20,7 @@ type updatePasswordRequest struct {
|
||||
|
||||
func (h *Handler) getProfile(w http.ResponseWriter, r *http.Request) {
|
||||
u := userFromRequest(r)
|
||||
writeJson(w, http.StatusOK, newUserResponse(u))
|
||||
h.respondUser(w, r, u, http.StatusOK)
|
||||
}
|
||||
|
||||
func (h *Handler) updateProfile(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -58,7 +58,7 @@ func (h *Handler) updateProfile(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
writeJson(w, http.StatusOK, newUserResponse(updated))
|
||||
h.respondUser(w, r, updated, http.StatusOK)
|
||||
}
|
||||
|
||||
func (h *Handler) updatePassword(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -109,6 +109,19 @@ func (h *Handler) uploadAvatar(w http.ResponseWriter, r *http.Request) {
|
||||
writeNoContent(w)
|
||||
}
|
||||
|
||||
// deleteAvatar removes the caller's avatar. It is idempotent: deleting an
|
||||
// avatar that does not exist still succeeds.
|
||||
func (h *Handler) deleteAvatar(w http.ResponseWriter, r *http.Request) {
|
||||
u := userFromRequest(r)
|
||||
|
||||
if err := h.users.DeleteAvatar(r.Context(), u); err != nil {
|
||||
h.fail(w, err)
|
||||
return
|
||||
}
|
||||
|
||||
writeNoContent(w)
|
||||
}
|
||||
|
||||
func (h *Handler) getAvatar(w http.ResponseWriter, r *http.Request) {
|
||||
u := userFromRequest(r)
|
||||
|
||||
|
||||
Reference in new issue
Block a user