Reorganize handlers

This commit is contained in:
2024-11-03 17:41:17 +01:00
parent 72680abdf4
commit dfd9544fba
10 changed files with 273 additions and 239 deletions

View File

@@ -6,15 +6,14 @@ import (
"novamd/internal/db"
)
func GetUser(db *db.DB) http.HandlerFunc {
func (h *BaseHandler) GetUser(db *db.DB) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
userID, err := getUserID(r)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
ctx, ok := h.getContext(w, r)
if !ok {
return
}
user, err := db.GetUserByID(userID)
user, err := db.GetUserByID(ctx.UserID)
if err != nil {
http.Error(w, "Failed to get user", http.StatusInternalServerError)
return