Basic functionality
This commit is contained in:
@ -7,6 +7,7 @@ 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"
|
||||
)
|
||||
|
||||
@ -22,7 +23,52 @@ func (s *Server) HandleCapture(w http.ResponseWriter, r *http.Request) error {
|
||||
return err
|
||||
}
|
||||
|
||||
return Render(w, r, capture.Capture(foundCapture))
|
||||
return Render(w, r, capture.Capture(foundCapture, *foundCapture.MapScores.BuildTable()))
|
||||
}
|
||||
|
||||
func (s *Server) HandleCaptureTable(w http.ResponseWriter, r *http.Request) error {
|
||||
captureString := chi.URLParam(r, "captureID")
|
||||
captureID, err := strconv.ParseInt(captureString, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
foundCapture, err := s.cs.GetCaptureById(r.Context(), captureID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return Render(w, r, components.CaptureTable(*foundCapture.MapScores.BuildTable()))
|
||||
}
|
||||
|
||||
func (s *Server) HandleCaptureStart(w http.ResponseWriter, r *http.Request) error {
|
||||
captureString := chi.URLParam(r, "captureID")
|
||||
captureID, err := strconv.ParseInt(captureString, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.cs.StartCapture(r.Context(), captureID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return hxRedirect(w, r, "/")
|
||||
}
|
||||
|
||||
func (s *Server) HandleCaptureStop(w http.ResponseWriter, r *http.Request) error {
|
||||
captureString := chi.URLParam(r, "captureID")
|
||||
captureID, err := strconv.ParseInt(captureString, 10, 64)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
err = s.cs.StopCapture(r.Context(), captureID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return hxRedirect(w, r, "/")
|
||||
}
|
||||
|
||||
func (s *Server) HandleCaptureDelete(w http.ResponseWriter, r *http.Request) error {
|
||||
@ -58,7 +104,7 @@ func (s *Server) HandleCaptureCreate(w http.ResponseWriter, r *http.Request) err
|
||||
Start: time.Now(),
|
||||
}
|
||||
|
||||
_, err := s.cs.GetServerStatus(r.Context(), newCapture)
|
||||
_, err := s.c4s.GetServerStatus(newCapture.Host, newCapture.Port)
|
||||
if err != nil {
|
||||
errors["host"] = err.Error()
|
||||
errors["port"] = err.Error()
|
||||
|
||||
Reference in New Issue
Block a user