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)