From 860cc765038b90e3b109af57bb21bfdfdd4c8c1d Mon Sep 17 00:00:00 2001 From: Antonio De Lucreziis Date: Thu, 18 Aug 2022 18:26:38 +0200 Subject: [PATCH] Minor fixes --- .env.dev | 3 ++- _views/profilo.html | 4 ++-- _views/utenti.html | 2 +- handler/handler.go | 10 ++++++++++ server/fiber.go | 8 +++++--- utenti.go | 3 +++ 6 files changed, 23 insertions(+), 7 deletions(-) diff --git a/.env.dev b/.env.dev index ee828f4..a4b54ea 100644 --- a/.env.dev +++ b/.env.dev @@ -1,6 +1,6 @@ # Server config MODE=development -HOST=localhost:8000 +HOST=:8000 # Separate services GIT_URL=https://git.phc.dm.unipi.it @@ -9,6 +9,7 @@ CHAT_URL=https://chat.phc.dm.unipi.it # Other EMAIL=macchinisti@lists.dm.unipi.it +# Lista Utenti USER_PAGES_BASE_URL=https://poisson.phc.dm.unipi.it/~ # AuthService diff --git a/_views/profilo.html b/_views/profilo.html index 5d960e2..647bd75 100644 --- a/_views/profilo.html +++ b/_views/profilo.html @@ -2,9 +2,9 @@ {{define "title"}}Profilo di @{{ .User.Username }} • PHC{{end}} {{define "body"}} - +
-

Profilo di @{{ .User.Username }}

+

Profilo di @{{ .User.Username }}

Logout

diff --git a/_views/utenti.html b/_views/utenti.html index a25aa1e..dbb1ec0 100644 --- a/_views/utenti.html +++ b/_views/utenti.html @@ -3,7 +3,7 @@ {{define "body"}} - +

diff --git a/handler/handler.go b/handler/handler.go index 2ff9253..94eefb4 100644 --- a/handler/handler.go +++ b/handler/handler.go @@ -16,6 +16,7 @@ import ( type Service interface { HandleStaticPage(w io.Writer, view string, ctx Context) error HandleUtenti() ([]*model.User, error) + HandleListaUtenti() ([]website.UserInfo, error) HandleStoriaPage(w io.Writer, ctx Context) error HandleQueryAppunti(w io.Writer, query string, ctx Context) error HandleNewsPage(w io.Writer, ctx Context) error @@ -61,6 +62,15 @@ func (h *DefaultHandler) HandleUtenti() ([]*model.User, error) { return utenti, nil } +func (h *DefaultHandler) HandleListaUtenti() ([]website.UserInfo, error) { + utenti, err := h.ListaUtenti.GetUtenti() + if err != nil { + return nil, err + } + + return utenti, nil +} + func (h *DefaultHandler) HandleStoriaPage(w io.Writer, ctx Context) error { storia, err := h.Storia.GetStoria() if err != nil { diff --git a/server/fiber.go b/server/fiber.go index b959225..bf16f13 100644 --- a/server/fiber.go +++ b/server/fiber.go @@ -36,6 +36,7 @@ func NewFiberServer(h handler.Service) *fiber.App { return app } +// routes defines routes under "/" func routes(h handler.Service, r fiber.Router) { // // Initial setup @@ -152,9 +153,10 @@ func routes(h handler.Service, r fiber.Router) { routesApi(h, r.Group("/api")) } +// routesApi defines routes under "/api" func routesApi(h handler.Service, r fiber.Router) { - r.Get("/api/utenti", func(c *fiber.Ctx) error { - utenti, err := h.HandleUtenti() + r.Get("/utenti", func(c *fiber.Ctx) error { + utenti, err := h.HandleListaUtenti() if err != nil { return err } @@ -162,7 +164,7 @@ func routesApi(h handler.Service, r fiber.Router) { return c.JSON(utenti) }) - r.Get("/api/profilo", func(c *fiber.Ctx) error { + r.Get("/profilo", func(c *fiber.Ctx) error { user, err := h.HandleRequiredUser(CreateContext(c)) if err != nil { return err diff --git a/utenti.go b/utenti.go index e08c684..6cba391 100644 --- a/utenti.go +++ b/utenti.go @@ -2,6 +2,7 @@ package website import ( "encoding/json" + "log" "os" ) @@ -34,5 +35,7 @@ func (j *JsonFileListUtenti) GetUtenti() ([]UserInfo, error) { return nil, err } + log.Printf("Loaded list utenti with %d users", len(users)) + return users, nil }