Ajouter liste de documents à /documentation
This commit is contained in:
parent
51d5dde7b4
commit
3dcb86d65f
4 changed files with 164 additions and 2 deletions
|
@ -6,6 +6,7 @@ package cmd
|
|||
import (
|
||||
"context"
|
||||
"crypto/subtle"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
|
||||
|
@ -20,6 +21,7 @@ import (
|
|||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
|
||||
"git.agecem.com/agecem/agecem-org/api"
|
||||
"git.agecem.com/agecem/agecem-org/public"
|
||||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
|
@ -584,7 +586,53 @@ func handleVieEtudianteOrganisme(c echo.Context) error {
|
|||
}
|
||||
|
||||
func handleDocumentation(c echo.Context) error {
|
||||
return c.Render(http.StatusOK, "documentation-html", nil)
|
||||
client, err := api.New("http", "localhost", viper.GetInt("server.port"), api.APIOptions{
|
||||
KeyAuth: viper.GetBool("server.api.auth"),
|
||||
Key: viper.GetString("server.api.key"),
|
||||
})
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
result, err := client.Call(http.MethodGet, "/v1/bucket")
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
var buckets []string
|
||||
|
||||
err = json.Unmarshal(result, &buckets)
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
type Bucket struct {
|
||||
Name string
|
||||
Documents []string
|
||||
}
|
||||
|
||||
var data []Bucket
|
||||
|
||||
for _, bucket := range buckets {
|
||||
result, err := client.Call(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", bucket))
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
var documents []string
|
||||
|
||||
err = json.Unmarshal(result, &documents)
|
||||
if err != nil {
|
||||
return c.Render(http.StatusInternalServerError, "documentation-html", nil)
|
||||
}
|
||||
|
||||
data = append(data, Bucket{
|
||||
Name: bucket,
|
||||
Documents: documents,
|
||||
})
|
||||
}
|
||||
|
||||
return c.Render(http.StatusOK, "documentation-html", data)
|
||||
}
|
||||
|
||||
func handleFormulaires(c echo.Context) error {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue