Files
arbeitszeitmessung/Backend/endpoints/team-presence.go
Tom Tröger ba034f1c33
Some checks failed
Tests / Run Go Tests (push) Failing after 1m35s
Arbeitszeitmessung Deploy / Build Webserver (push) Successful in 2m48s
feat: updated docs and added description to files
2026-01-29 18:28:28 +01:00

43 lines
1.0 KiB
Go

package endpoints
// this endpoint served at "/team/presence" shows the presence page
import (
"arbeitszeitmessung/helper"
"arbeitszeitmessung/models"
"arbeitszeitmessung/templates"
"log"
"net/http"
)
func PresenceHandler(w http.ResponseWriter, r *http.Request) {
helper.RequiresLogin(Session, w, r)
helper.SetCors(w)
switch r.Method {
case http.MethodGet:
teamPresence(w, r)
case http.MethodOptions:
// just support options header for non GET Requests from SWAGGER
w.WriteHeader(http.StatusOK)
default:
http.Error(w, "Method not allowed!", http.StatusMethodNotAllowed)
}
}
func teamPresence(w http.ResponseWriter, r *http.Request) {
user, err := models.GetUserFromSession(Session, r.Context())
if err != nil {
log.Println("Error getting user!", err)
}
team, err := user.GetTeamMembers()
teamPresence := make(map[models.User]bool)
for _, user := range team {
teamPresence[user] = user.CheckAnwesenheit()
}
if err != nil {
log.Println("Error getting team", err)
}
templates.TeamPresencePage(teamPresence).Render(r.Context(), w)
}