Update all the shit

This commit is contained in:
Henri Burau
2024-06-07 00:07:29 +02:00
parent ddbfc32fb1
commit 18265f59df
43 changed files with 609 additions and 182 deletions

View File

@ -7,7 +7,6 @@ import (
"gitea.henriburau.de/haw-lan/cod4watcher/models"
"gitea.henriburau.de/haw-lan/cod4watcher/views/capture"
"gitea.henriburau.de/haw-lan/cod4watcher/views/components"
"github.com/go-chi/chi"
)
@ -38,7 +37,7 @@ func (s *Server) HandleCaptureTable(w http.ResponseWriter, r *http.Request) erro
return err
}
return Render(w, r, components.CaptureTable(*foundCapture.MapScores.BuildTable()))
return Render(w, r, capture.TableWithLeaderboard(*foundCapture.MapScores.BuildTable()))
}
func (s *Server) HandleCaptureStart(w http.ResponseWriter, r *http.Request) error {
@ -87,7 +86,7 @@ func (s *Server) HandleCaptureDelete(w http.ResponseWriter, r *http.Request) err
}
func (s *Server) HandleCaptureForm(w http.ResponseWriter, r *http.Request) error {
return Render(w, r, capture.CaptureForm(capture.CaptureFormValues{}, map[string]string{}))
return Render(w, r, capture.CaptureForm(capture.CaptureFormValues{Port: "28960"}, map[string]string{}))
}
func (s *Server) HandleCaptureCreate(w http.ResponseWriter, r *http.Request) error {
@ -145,3 +144,35 @@ func parseCaptureFormAndValidate(r *http.Request) (capture.CaptureFormValues, ma
return formValues, errors
}
func (s *Server) HandleUpdateMapScoreCounted(w http.ResponseWriter, r *http.Request) error {
captureString := chi.URLParam(r, "captureID")
captureID, err := strconv.ParseInt(captureString, 10, 64)
if err != nil {
return err
}
mapscoreIDString := chi.URLParam(r, "mapscoreID")
mapscoreID, err := strconv.ParseInt(mapscoreIDString, 10, 64)
if err != nil {
return err
}
countedString := chi.URLParam(r, "counted")
counted, err := strconv.ParseBool(countedString)
if err != nil {
return err
}
err = s.cs.SetMapScoreConted(r.Context(), mapscoreID, counted)
if err != nil {
return err
}
updatedCapture, err := s.cs.GetCaptureById(r.Context(), captureID)
if err != nil {
return err
}
return Render(w, r, capture.MapSelectTable(updatedCapture))
}

View File

@ -9,9 +9,8 @@ import (
func (s *Server) HandleServerStatus(w http.ResponseWriter, r *http.Request) error {
status, err := s.c4s.GetServerStatus(r.URL.Query().Get("host"), r.URL.Query().Get("port"))
if err != nil {
w.WriteHeader(http.StatusBadRequest)
return err
return Render(w, r, cod4server.ServerStatusError(err))
} else {
return Render(w, r, cod4server.ServerStatus(status))
}
return Render(w, r, cod4server.ServerStatus(status))
}