Output slice of values

This commit is contained in:
Melon 2023-07-13 00:16:47 +01:00
parent eb8e4c7ed7
commit b2a53722e6
Signed by: melon
GPG Key ID: 6C9D970C50D26A25

View File

@ -15,16 +15,13 @@ import (
func SetupTargetApis(r *httprouter.Router, verify mjwt.Verifier, manager *router.Manager) {
// Endpoint for routes
r.GET("/route", checkAuthWithPerm(verify, "violet:route", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims) {
routes, active, err := manager.GetAllRoutes()
routes, err := manager.GetAllRoutes()
if err != nil {
apiError(rw, http.StatusInternalServerError, "Failed to get routes from database")
return
}
rw.WriteHeader(http.StatusOK)
_ = json.NewEncoder(rw).Encode(map[string]any{
"routes": routes,
"active": active,
})
_ = json.NewEncoder(rw).Encode(routes)
}))
r.POST("/route", parseJsonAndCheckOwnership[routeSource](verify, "route", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims, t routeSource) {
err := manager.InsertRoute(target.Route(t))
@ -47,16 +44,13 @@ func SetupTargetApis(r *httprouter.Router, verify mjwt.Verifier, manager *router
// Endpoint for redirects
r.GET("/redirect", checkAuthWithPerm(verify, "violet:redirect", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims) {
redirects, active, err := manager.GetAllRedirects()
redirects, err := manager.GetAllRedirects()
if err != nil {
apiError(rw, http.StatusInternalServerError, "Failed to get redirects from database")
return
}
rw.WriteHeader(http.StatusOK)
_ = json.NewEncoder(rw).Encode(map[string]any{
"redirects": redirects,
"active": active,
})
_ = json.NewEncoder(rw).Encode(redirects)
}))
r.POST("/redirect", parseJsonAndCheckOwnership[redirectSource](verify, "redirect", func(rw http.ResponseWriter, req *http.Request, params httprouter.Params, b AuthClaims, t redirectSource) {
err := manager.InsertRedirect(target.Redirect(t))