From 43615ce988b16ee1bbf99a8e6a8f9f1266729bb4 Mon Sep 17 00:00:00 2001 From: toast Date: Wed, 30 Nov 2022 02:34:24 -0700 Subject: [PATCH 1/4] moved stats and export resources from user to users --- handlers.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/handlers.go b/handlers.go index f464ae87..0d85a580 100644 --- a/handlers.go +++ b/handlers.go @@ -145,10 +145,14 @@ func (s *Server) ServeAPI() error { user.GET("/api-keys", withUser(s.handleUserGetApiKeys)) user.POST("/api-keys", withUser(s.handleUserCreateApiKey)) user.DELETE("/api-keys/:key_or_hash", withUser(s.handleUserRevokeApiKey)) - user.GET("/export", withUser(s.handleUserExportData)) user.PUT("/password", withUser(s.handleUserChangePassword)) user.PUT("/address", withUser(s.handleUserChangeAddress)) - user.GET("/stats", withUser(s.handleGetUserStats)) + + //move resources to plural users <-- (notice the s!!) + users := e.Group("/users") + users.Use(s.AuthRequired(util.PermLevelUser)) + users.GET("/stats", withUser(s.handleGetUserStats)) + users.GET("/export", withUser(s.handleUserExportData)) userMiner := user.Group("/miner") userMiner.POST("/claim", withUser(s.handleUserClaimMiner)) @@ -1635,8 +1639,8 @@ func (s *Server) handleMakeDeal(c echo.Context, u *util.User) error { }) } -//from datatransfer.ChannelID and used for swagger docs -//if we don't redefine this here, we'll need to enable parse dependences for swagger and it will take a really long time +// from datatransfer.ChannelID and used for swagger docs +// if we don't redefine this here, we'll need to enable parse dependences for swagger and it will take a really long time type ChannelIDParam struct { Initiator string Responder string From 2a74756e33fc69ae60833f226dda204eeaf8e8f3 Mon Sep 17 00:00:00 2001 From: toast Date: Wed, 30 Nov 2022 02:36:21 -0700 Subject: [PATCH 2/4] updated docstrings for new /users routes --- handlers.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/handlers.go b/handlers.go index 0d85a580..aa43a823 100644 --- a/handlers.go +++ b/handlers.go @@ -3220,7 +3220,7 @@ type userStatsResponse struct { // @Success 200 {object} string // @Failure 400 {object} util.HttpError // @Failure 500 {object} util.HttpError -// @Router /user/stats [get] +// @Router /users/stats [get] func (s *Server) handleGetUserStats(c echo.Context, u *util.User) error { var stats userStatsResponse if err := s.DB.Raw(` SELECT @@ -4173,7 +4173,7 @@ func (s *Server) handleGetStagingZoneForUser(c echo.Context, u *util.User) error // @Success 200 {object} string // @Failure 400 {object} util.HttpError // @Failure 500 {object} util.HttpError -// @Router /user/export [get] +// @Router /users/export [get] func (s *Server) handleUserExportData(c echo.Context, u *util.User) error { export, err := s.exportUserData(u.ID) if err != nil { From f6e4b01ac1ae9bc2544283b0c0da1638d2068629 Mon Sep 17 00:00:00 2001 From: toast Date: Wed, 30 Nov 2022 02:37:41 -0700 Subject: [PATCH 3/4] changed stats handler name to be consistent with other naming semantics --- handlers.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/handlers.go b/handlers.go index aa43a823..801d5387 100644 --- a/handlers.go +++ b/handlers.go @@ -151,7 +151,7 @@ func (s *Server) ServeAPI() error { //move resources to plural users <-- (notice the s!!) users := e.Group("/users") users.Use(s.AuthRequired(util.PermLevelUser)) - users.GET("/stats", withUser(s.handleGetUserStats)) + users.GET("/stats", withUser(s.handleUserGetStats)) users.GET("/export", withUser(s.handleUserExportData)) userMiner := user.Group("/miner") @@ -3212,7 +3212,7 @@ type userStatsResponse struct { NumPins int64 `json:"numPins"` } -// handleGetUserStats godoc +// handleUserGetStats godoc // @Summary Get stats for the current user // @Description This endpoint is used to geet stats for the current user. // @Tags User @@ -3221,7 +3221,7 @@ type userStatsResponse struct { // @Failure 400 {object} util.HttpError // @Failure 500 {object} util.HttpError // @Router /users/stats [get] -func (s *Server) handleGetUserStats(c echo.Context, u *util.User) error { +func (s *Server) handleUserGetStats(c echo.Context, u *util.User) error { var stats userStatsResponse if err := s.DB.Raw(` SELECT (SELECT SUM(size) FROM contents where user_id = ? AND aggregated_in = 0 AND active) as total_size, From 54ed70841c6a7bd33ea6b54829937a3cefd832bd Mon Sep 17 00:00:00 2001 From: toastts Date: Wed, 30 Nov 2022 09:39:08 +0000 Subject: [PATCH 4/4] docs: update swagger docs --- docs/docs.go | 4 ++-- docs/swagger.json | 4 ++-- docs/swagger.yaml | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/docs.go b/docs/docs.go index ca01a25e..a1057774 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -2906,7 +2906,7 @@ const docTemplate = `{ } } }, - "/user/export": { + "/users/export": { "get": { "description": "This endpoint is used to get API keys for a user.", "produces": [ @@ -2938,7 +2938,7 @@ const docTemplate = `{ } } }, - "/user/stats": { + "/users/stats": { "get": { "description": "This endpoint is used to geet stats for the current user.", "produces": [ diff --git a/docs/swagger.json b/docs/swagger.json index 172ace5c..9526b7a4 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -2899,7 +2899,7 @@ } } }, - "/user/export": { + "/users/export": { "get": { "description": "This endpoint is used to get API keys for a user.", "produces": [ @@ -2931,7 +2931,7 @@ } } }, - "/user/stats": { + "/users/stats": { "get": { "description": "This endpoint is used to geet stats for the current user.", "produces": [ diff --git a/docs/swagger.yaml b/docs/swagger.yaml index 674327de..fdf45517 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -2085,7 +2085,7 @@ paths: summary: Revoke a User API Key. tags: - User - /user/export: + /users/export: get: description: This endpoint is used to get API keys for a user. produces: @@ -2106,7 +2106,7 @@ paths: summary: Export user data tags: - User - /user/stats: + /users/stats: get: description: This endpoint is used to geet stats for the current user. produces: