49 lines
1.2 KiB
Go
49 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"fmt"
|
|
"log/slog"
|
|
"net/http"
|
|
|
|
"git.duckylabs.xyz/duckbox/ducky-dash/db"
|
|
"git.duckylabs.xyz/duckbox/ducky-dash/view/users"
|
|
"github.com/go-chi/chi/v5"
|
|
"github.com/google/uuid"
|
|
)
|
|
|
|
func HandleUsersIndex(w http.ResponseWriter, r *http.Request) error {
|
|
// TODO: Pull all users from the current users groups
|
|
// Pull all users
|
|
accounts, err := db.GetAllAccounts()
|
|
if err != nil {
|
|
slog.Error("error getting all accounts", err)
|
|
return err
|
|
}
|
|
|
|
return render(r, w, users.UsersViewIndex(accounts))
|
|
}
|
|
|
|
func HandleUserProfile(w http.ResponseWriter, r *http.Request) error {
|
|
fmt.Println("User Profile Handler activated")
|
|
// Get UUID from the URL
|
|
userID := chi.URLParam(r, "uuid")
|
|
if userID == "" {
|
|
return render(r, w, users.UsersViewIndex(nil))
|
|
}
|
|
|
|
accountID, err := uuid.Parse(userID)
|
|
if err != nil {
|
|
slog.Error("error parsing user ID", err)
|
|
return render(r, w, users.UsersViewIndex(nil))
|
|
}
|
|
|
|
|
|
account, err := db.GetAccountByID(accountID)
|
|
if err != nil {
|
|
slog.Error("error getting account by ID", err)
|
|
return render(r, w, users.UsersViewIndex(nil))
|
|
}
|
|
|
|
return render(r, w, users.UserProfileView(account))
|
|
}
|