From 66a11e508539788476174b8620c1a3f68088b17d Mon Sep 17 00:00:00 2001 From: Jared Date: Wed, 1 Feb 2023 00:19:10 -0500 Subject: [PATCH] Add a new endpoint and remove an unused one from the router --- endpoints/getusers.go | 32 ++++++++++++++++++++++++++++++++ main.go | 2 +- 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 endpoints/getusers.go diff --git a/endpoints/getusers.go b/endpoints/getusers.go new file mode 100644 index 0000000..f4aa385 --- /dev/null +++ b/endpoints/getusers.go @@ -0,0 +1,32 @@ +package endpoints + +import ( + "encoding/json" + "net/http" + + "github.com/imosed/signet/auth" + . "github.com/imosed/signet/data" +) + +type GetUsersResponse struct { + Users []User `json:"users"` +} + +func GetUsers(w http.ResponseWriter, r *http.Request) { + claims, err := auth.GetUserClaims(r) + + if claims.Privileges > AdminPlus { + return + } + + var users []User + Db.Table("users").Scan(&users) + + var resp GetUsersResponse + resp.Users = users + + err = json.NewEncoder(w).Encode(resp) + if err != nil { + panic("Could not deliver response") + } +} diff --git a/main.go b/main.go index 4a827eb..625bdea 100644 --- a/main.go +++ b/main.go @@ -42,7 +42,7 @@ func main() { router.HandleFunc("/CloseRewardFund", endpoints.CloseRewardFund) router.HandleFunc("/SubmitRewardFund", endpoints.SubmitFund) router.HandleFunc("/DistributeRewardFund", endpoints.DistributeRewards) - // router.HandleFunc("/SubmitFund", endpoints.SubmitFund) + router.HandleFunc("/GetUsers", endpoints.GetUsers) router.HandleFunc("/GetBalance", endpoints.GetBalance) router.HandleFunc("/Contribute", endpoints.Contribute) router.HandleFunc("/ContributorStream", endpoints.ContributorStream)