package routing import ( lishwist "lishwist/core" "lishwist/http/response" "net/http" ) func Users(app *lishwist.Session, h http.Header, r *response.Request) response.Response { admin := app.Admin() if admin == nil { return NotFound(h, r) } users, err := admin.ListUsers() if err != nil { return response.Error(http.StatusInternalServerError, "Failed to get users: %s", err) } return response.Data("", users) } func User(app *lishwist.Session, h http.Header, r *response.Request) response.Response { admin := app.Admin() if admin == nil { return NotFound(h, r) } reference := r.PathValue("userReference") user, err := lishwist.GetUserByReference(reference) if err != nil { return response.Error(http.StatusInternalServerError, "Failed to get user: %s", err) } if user == nil { return response.Error(http.StatusNotFound, "User not found") } return response.Data("", user) } func UserPost(app *lishwist.Session, h http.Header, r *response.Request) response.Response { admin := app.Admin() if admin == nil { return NotFound(h, r) } form := r.ParseForm() reference := r.PathValue("userReference") if reference == app.User.Reference { return response.Error(http.StatusForbidden, "You cannot delete yourself.") } user, err := lishwist.GetUserByReference(reference) if err != nil { return response.Error(http.StatusInternalServerError, "Failed to get user: %s", err) } if user == nil { return response.Error(http.StatusNotFound, "User not found") } intent := form.Get("intent") if intent != "" { err = admin.UserSetLive(reference, intent != "delete") if err != nil { return response.Error(http.StatusInternalServerError, "Failed to delete user: %s", err) } } return response.Data("", user) }