Rework api

This commit is contained in:
2024-10-15 22:17:34 +02:00
parent 071619cfb3
commit 6cf141bfd9
7 changed files with 443 additions and 110 deletions

View File

@@ -0,0 +1,25 @@
package api
import (
"net/http"
"novamd/internal/db"
)
func 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)
return
}
user, err := db.GetUserByID(userID)
if err != nil {
http.Error(w, "Failed to get user", http.StatusInternalServerError)
return
}
respondJSON(w, user)
}
}