mirror of
https://github.com/notherealmarco/WASAPhoto.git
synced 2025-03-14 14:16:15 +01:00
32 lines
926 B
Go
32 lines
926 B
Go
package api
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/julienschmidt/httprouter"
|
|
"github.com/notherealmarco/WASAPhoto/service/api/authorization"
|
|
"github.com/notherealmarco/WASAPhoto/service/api/helpers"
|
|
"github.com/notherealmarco/WASAPhoto/service/api/reqcontext"
|
|
"github.com/notherealmarco/WASAPhoto/service/structures"
|
|
)
|
|
|
|
func (rt *_router) UpdateUsername(w http.ResponseWriter, r *http.Request, ps httprouter.Params, ctx reqcontext.RequestContext) {
|
|
|
|
uid := ps.ByName("user_id")
|
|
if !authorization.SendAuthorizationError(ctx.Auth.UserAuthorized, uid, rt.db, w, rt.baseLogger, http.StatusNotFound) {
|
|
return
|
|
}
|
|
var req structures.UserDetails
|
|
if !helpers.DecodeJsonOrBadRequest(r.Body, w, &req, rt.baseLogger) {
|
|
return
|
|
}
|
|
|
|
err := rt.db.UpdateUsername(uid, req.Name)
|
|
|
|
if err != nil {
|
|
helpers.SendInternalError(err, "Database error: UpdateUsername", w, rt.baseLogger)
|
|
return
|
|
}
|
|
|
|
w.WriteHeader(http.StatusNoContent)
|
|
}
|