Minor fixes

feat/db
Antonio De Lucreziis 2 years ago
parent 227619e5eb
commit 860cc76503

@ -1,6 +1,6 @@
# Server config # Server config
MODE=development MODE=development
HOST=localhost:8000 HOST=:8000
# Separate services # Separate services
GIT_URL=https://git.phc.dm.unipi.it GIT_URL=https://git.phc.dm.unipi.it
@ -9,6 +9,7 @@ CHAT_URL=https://chat.phc.dm.unipi.it
# Other # Other
EMAIL=macchinisti@lists.dm.unipi.it EMAIL=macchinisti@lists.dm.unipi.it
# Lista Utenti
USER_PAGES_BASE_URL=https://poisson.phc.dm.unipi.it/~ USER_PAGES_BASE_URL=https://poisson.phc.dm.unipi.it/~
# AuthService # AuthService

@ -2,9 +2,9 @@
{{define "title"}}Profilo di @{{ .User.Username }} • PHC{{end}} {{define "title"}}Profilo di @{{ .User.Username }} • PHC{{end}}
{{define "body"}} {{define "body"}}
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> <script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="/public/js/profilo.min.js"></script> <script src="/public/profilo.min.js"></script>
<section x-data="profilo"> <section x-data="profilo">
<h1>Profilo di @{{ .User.Username }}</h1> <h1>Profilo di <strong>@{{ .User.Username }}</strong></h1>
<p class="center"> <p class="center">
<a class="button" href="/logout">Logout</a> <a class="button" href="/logout">Logout</a>
</p> </p>

@ -3,7 +3,7 @@
{{define "body"}} {{define "body"}}
<script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script> <script src="https://unpkg.com/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.js"></script> <script src="https://cdn.jsdelivr.net/npm/fuse.js/dist/fuse.js"></script>
<script src="/public/js/utenti.min.js"></script> <script src="/public/utenti.min.js"></script>
<section x-data="utenti"> <section x-data="utenti">
<h1> <h1>
<i class="fas fa-users"></i> <i class="fas fa-users"></i>

@ -16,6 +16,7 @@ import (
type Service interface { type Service interface {
HandleStaticPage(w io.Writer, view string, ctx Context) error HandleStaticPage(w io.Writer, view string, ctx Context) error
HandleUtenti() ([]*model.User, error) HandleUtenti() ([]*model.User, error)
HandleListaUtenti() ([]website.UserInfo, error)
HandleStoriaPage(w io.Writer, ctx Context) error HandleStoriaPage(w io.Writer, ctx Context) error
HandleQueryAppunti(w io.Writer, query string, ctx Context) error HandleQueryAppunti(w io.Writer, query string, ctx Context) error
HandleNewsPage(w io.Writer, ctx Context) error HandleNewsPage(w io.Writer, ctx Context) error
@ -61,6 +62,15 @@ func (h *DefaultHandler) HandleUtenti() ([]*model.User, error) {
return utenti, nil 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 { func (h *DefaultHandler) HandleStoriaPage(w io.Writer, ctx Context) error {
storia, err := h.Storia.GetStoria() storia, err := h.Storia.GetStoria()
if err != nil { if err != nil {

@ -36,6 +36,7 @@ func NewFiberServer(h handler.Service) *fiber.App {
return app return app
} }
// routes defines routes under "/"
func routes(h handler.Service, r fiber.Router) { func routes(h handler.Service, r fiber.Router) {
// //
// Initial setup // Initial setup
@ -152,9 +153,10 @@ func routes(h handler.Service, r fiber.Router) {
routesApi(h, r.Group("/api")) routesApi(h, r.Group("/api"))
} }
// routesApi defines routes under "/api"
func routesApi(h handler.Service, r fiber.Router) { func routesApi(h handler.Service, r fiber.Router) {
r.Get("/api/utenti", func(c *fiber.Ctx) error { r.Get("/utenti", func(c *fiber.Ctx) error {
utenti, err := h.HandleUtenti() utenti, err := h.HandleListaUtenti()
if err != nil { if err != nil {
return err return err
} }
@ -162,7 +164,7 @@ func routesApi(h handler.Service, r fiber.Router) {
return c.JSON(utenti) 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)) user, err := h.HandleRequiredUser(CreateContext(c))
if err != nil { if err != nil {
return err return err

@ -2,6 +2,7 @@ package website
import ( import (
"encoding/json" "encoding/json"
"log"
"os" "os"
) )
@ -34,5 +35,7 @@ func (j *JsonFileListUtenti) GetUtenti() ([]UserInfo, error) {
return nil, err return nil, err
} }
log.Printf("Loaded list utenti with %d users", len(users))
return users, nil return users, nil
} }

Loading…
Cancel
Save