Add routes to retrieve module's status
One route for the user's polochon modules statuses One route for the modules statuses of Canape itself
This commit is contained in:
parent
0ac63cdde6
commit
779ef8d211
12
backend/admins/modules.go
Normal file
12
backend/admins/modules.go
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
package admin
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"git.quimbo.fr/odwrtw/canape/backend/web"
|
||||||
|
)
|
||||||
|
|
||||||
|
// GetModulesStatuses return the statuses of all the modules
|
||||||
|
func GetModulesStatuses(env *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
return env.RenderJSON(w, env.Config.PolochonConfig.ModulesStatus())
|
||||||
|
}
|
@ -19,6 +19,7 @@ func setupRoutes(env *web.Env) {
|
|||||||
env.Handle("/users/tokens", users.GetTokensHandler).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/users/tokens", users.GetTokensHandler).WithRole(users.UserRole).Methods("GET")
|
||||||
env.Handle("/users/tokens/{token}", users.EditTokenHandler).WithRole(users.UserRole).Methods("POST")
|
env.Handle("/users/tokens/{token}", users.EditTokenHandler).WithRole(users.UserRole).Methods("POST")
|
||||||
env.Handle("/users/tokens/{token}", users.DeleteTokenHandler).WithRole(users.UserRole).Methods("DELETE")
|
env.Handle("/users/tokens/{token}", users.DeleteTokenHandler).WithRole(users.UserRole).Methods("DELETE")
|
||||||
|
env.Handle("/users/modules/status", users.GetModulesStatus).WithRole(users.UserRole).Methods("GET")
|
||||||
|
|
||||||
// Movies routes
|
// Movies routes
|
||||||
env.Handle("/movies/polochon", movies.PolochonMoviesHandler).WithRole(users.UserRole).Methods("GET")
|
env.Handle("/movies/polochon", movies.PolochonMoviesHandler).WithRole(users.UserRole).Methods("GET")
|
||||||
@ -67,4 +68,5 @@ func setupRoutes(env *web.Env) {
|
|||||||
env.Handle("/admins/users", admin.UpdateUserHandler).WithRole(users.AdminRole).Methods("POST")
|
env.Handle("/admins/users", admin.UpdateUserHandler).WithRole(users.AdminRole).Methods("POST")
|
||||||
env.Handle("/admins/stats", admin.GetStatsHandler).WithRole(users.AdminRole).Methods("GET")
|
env.Handle("/admins/stats", admin.GetStatsHandler).WithRole(users.AdminRole).Methods("GET")
|
||||||
env.Handle("/admins/tokens/{username}", admin.GenerateUserToken).WithRole(users.AdminRole).Methods("POST")
|
env.Handle("/admins/tokens/{username}", admin.GenerateUserToken).WithRole(users.AdminRole).Methods("POST")
|
||||||
|
env.Handle("/admins/modules", admin.GetModulesStatuses).WithRole(users.AdminRole).Methods("GET")
|
||||||
}
|
}
|
||||||
|
@ -5,11 +5,11 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
|
||||||
"git.quimbo.fr/odwrtw/canape/backend/auth"
|
"git.quimbo.fr/odwrtw/canape/backend/auth"
|
||||||
"git.quimbo.fr/odwrtw/canape/backend/config"
|
"git.quimbo.fr/odwrtw/canape/backend/config"
|
||||||
"git.quimbo.fr/odwrtw/canape/backend/tokens"
|
"git.quimbo.fr/odwrtw/canape/backend/tokens"
|
||||||
"git.quimbo.fr/odwrtw/canape/backend/web"
|
"git.quimbo.fr/odwrtw/canape/backend/web"
|
||||||
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
// SignupPOSTHandler handles the user's Signup
|
// SignupPOSTHandler handles the user's Signup
|
||||||
@ -215,3 +215,26 @@ func EditTokenHandler(e *web.Env, w http.ResponseWriter, r *http.Request) error
|
|||||||
|
|
||||||
return e.RenderJSON(w, t)
|
return e.RenderJSON(w, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// GetModulesStatus returns the status of the modules
|
||||||
|
func GetModulesStatus(e *web.Env, w http.ResponseWriter, r *http.Request) error {
|
||||||
|
// Get the user from the request
|
||||||
|
v := auth.GetCurrentUser(r, e.Log)
|
||||||
|
user, ok := v.(*User)
|
||||||
|
if !ok {
|
||||||
|
return e.RenderError(w, fmt.Errorf("invalid user type"))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create a papi client
|
||||||
|
client, err := user.NewPapiClient()
|
||||||
|
if err != nil {
|
||||||
|
return e.RenderError(w, fmt.Errorf("error while getting user"))
|
||||||
|
}
|
||||||
|
|
||||||
|
status, err := client.GetModulesStatus()
|
||||||
|
if err != nil {
|
||||||
|
return e.RenderError(w, fmt.Errorf("error while getting modules status %q", err))
|
||||||
|
}
|
||||||
|
|
||||||
|
return e.RenderJSON(w, status)
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user